Category.Class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * 官网分类管理模块
  4. * Created by PhpStorm.
  5. * User: phperstar
  6. * Date: 2020/2/11
  7. * Time: 3:00 PM
  8. */
  9. namespace JinDouYun\Controller\Manage;
  10. use Mall\Framework\Core\ErrorCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\Manage\MCategory;
  13. use Mall\Framework\Core\ResultWrapper;
  14. use Mall\Framework\Core\StatusCode;
  15. class Category extends BaseController
  16. {
  17. private $objMCategory;
  18. public function __construct()
  19. {
  20. parent::__construct(false, false, false);
  21. $this->objMCategory = new MCategory();
  22. }
  23. // 公共字段
  24. public function commonFieldFilter()
  25. {
  26. $paramsData = $this->request->getRawJson();
  27. $params = [
  28. 'categoryName' => isset($paramsData['categoryName']) ? $paramsData['categoryName'] : '',
  29. 'sort' => isset($paramsData['sort']) ? $paramsData['sort'] : 1,
  30. 'enableStatus' => isset($paramsData['enableStatus']) ? $paramsData['enableStatus'] : 5,
  31. ];
  32. foreach ($params as $k => $v) {
  33. if (empty($v) && $v !== 0) {
  34. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  35. }
  36. }
  37. $params['type'] = isset($paramsData['type']) ? $paramsData['type'] : StatusCode::$delete;
  38. $params['description'] = isset($paramsData['description']) ? $paramsData['description'] : '';
  39. return $params;
  40. }
  41. // 添加频道
  42. public function addCategory()
  43. {
  44. $categoryData = self::commonFieldFilter();
  45. $result = $this->objMCategory->addCategory($categoryData);
  46. if ($result->isSuccess()) {
  47. parent::sendOutput($result->getData());
  48. }
  49. parent::sendOutput($result->getData(), $result->getErrorCode());
  50. }
  51. // 修改频道启用/停用状态
  52. public function updateEnbaleStatus()
  53. {
  54. $paramsData = $this->request->getRawJson();
  55. $params = [
  56. 'id' => isset($paramsData['id']) ? $paramsData['id'] : '',
  57. 'enableStatus' => isset($paramsData['enableStatus']) ? $paramsData['enableStatus'] : '',
  58. ];
  59. foreach ($params as $k => $v) {
  60. if (empty($v) && $v !== 0) {
  61. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  62. }
  63. }
  64. $params['type'] = isset($params['type']) ? $params['type'] : StatusCode::$delete;
  65. $result = $this->objMCategory->updateEnbaleStatus($params);
  66. if ($result->isSuccess()) {
  67. parent::sendOutput($result->getData());
  68. }
  69. parent::sendOutput($result->getData(), $result->getErrorCode());
  70. }
  71. // 删除频道
  72. public function delCategory()
  73. {
  74. $id = $this->request->param('request_id');
  75. if (empty($id)) {
  76. parent::sendOutput('参数为空', ErrorCode::$paramError);
  77. }
  78. $result = $this->objMCategory->delCategory($id);
  79. if ($result->isSuccess()) {
  80. parent::sendOutput($result->getData());
  81. }
  82. parent::sendOutput($result->getData(), $result->getErrorCode());
  83. }
  84. // 获取指定频道信息
  85. public function getCategoryInfo()
  86. {
  87. $params['id'] = $this->request->param('request_id');
  88. if ( !$params['id'] ) {
  89. $this->sendOutput('参数错误', ErrorCode::$paramError );
  90. }
  91. $result = $this->objMCategory->getCategoryInfo($params);
  92. if($result->isSuccess()){
  93. $this->sendOutput($result->getData());
  94. }else{
  95. $this->sendOutput($result->getData(), $result->getErrorCode());
  96. }
  97. }
  98. // 编辑频道
  99. public function editCategory()
  100. {
  101. $categoryId = $this->request->param('request_id');
  102. if(empty($categoryId)){
  103. $this->sendOutput('参数错误', ErrorCode::$paramError);
  104. }
  105. $categoryData = self::commonFieldFilter();
  106. $categoryData['id'] = $categoryId;
  107. $result = $this->objMCategory->editCategory($categoryData);
  108. if($result->isSuccess()){
  109. parent::sendOutput($result->getData());
  110. }else{
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. }
  114. // 获取所有频道信息
  115. public function getAllCategory()
  116. {
  117. $params = $this->request->getRawJson();
  118. $type = isset($params['type']) ? $params['type'] : StatusCode::$delete;
  119. $result = $this->objMCategory->getAllCategory($type);
  120. if($result->isSuccess()){
  121. parent::sendOutput($result->getData());
  122. }else{
  123. parent::sendOutput($result->getData(), $result->getErrorCode());
  124. }
  125. }
  126. //获取频道和文章信息
  127. public function getCategoryAndArticle()
  128. {
  129. $params = $this->request->getRawJson();
  130. $data = [
  131. 'categoryPage' => isset($params['categoryPage']) ? $params['categoryPage'] : 1,
  132. 'categoryPageSize' => isset($params['categoryPageSize']) ? $params['categoryPageSize'] : 4,
  133. 'articlePage' => isset($params['articlePage']) ? $params['articlePage'] : 1,
  134. 'articlePageSize' => isset($params['articlePageSize']) ? $params['articlePageSize'] : 4,
  135. ];
  136. $selectParams = [
  137. 'categoryOffset' => ($data['categoryPage'] - 1) * $data['categoryPageSize'],
  138. 'categoryLimit' => $data['categoryPageSize'],
  139. 'articleOffset' => ($data['articlePage'] - 1) * $data['articlePageSize'],
  140. 'articleLimit' => $data['articlePageSize'],
  141. ];
  142. $modelResult = $this->objMCategory->getCategoryAndArticle($selectParams);
  143. if(!$modelResult->isSuccess()){
  144. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  145. }
  146. parent::sendOutput($modelResult->getData());
  147. }
  148. }