GoodsCategory.Class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /**
  3. * 商品基础资料分类
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/10/30
  7. * Time: 17:10
  8. */
  9. namespace JinDouYun\Controller\GoodsCategory;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\GoodsCategory\MGoodsCategory;
  14. class GoodsCategory extends BaseController
  15. {
  16. private $objMGoodsCategory;
  17. /**
  18. * GoodsCategory constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMGoodsCategory = new MGoodsCategory($this->onlineUserId,$this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 添加和编辑分类信息的公共字段
  30. *
  31. * @return array
  32. */
  33. public function commonFieldFilter()
  34. {
  35. $params = $this->request->getRawJson();
  36. if (empty($params)) {
  37. $this->sendOutput('参数为空', ErrorCode::$paramError);
  38. }
  39. $goodsCategoryData = [
  40. 'title' => isset($params['title']) ? $params['title'] : '',
  41. ];
  42. foreach ($goodsCategoryData as $key => $value) {
  43. if (empty($value) && $value !== 0) {
  44. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  45. }
  46. }
  47. $goodsCategoryData['sort'] = isset($params['sort']) ? $params['sort'] : 0;
  48. $goodsCategoryData['adImage'] = isset($params['adImage']) ? $params['adImage'] : '';
  49. $goodsCategoryData['images'] = isset($params['images']) ? $params['images'] : '';
  50. $goodsCategoryData['link'] = isset($params['link']) ? $params['link'] : '';
  51. $goodsCategoryData['pid'] = isset($params['pid']) ? $params['pid'] : 0;
  52. $goodsCategoryData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;
  53. isset($params['notCustomerType']) && $goodsCategoryData['notCustomerType'] = $params['notCustomerType'];
  54. return $goodsCategoryData;
  55. }
  56. /**
  57. * 添加分类
  58. * @throws \Exception
  59. */
  60. public function addCategory()
  61. {
  62. $categoryData = $this->commonFieldFilter();
  63. $result = $this->objMGoodsCategory->addCategory($categoryData);
  64. if ($result->isSuccess()) {
  65. parent::sendOutput($result->getData());
  66. } else {
  67. parent::sendOutput($result->getData(), $result->getErrorCode());
  68. }
  69. }
  70. /**
  71. * 获取指定id的分类详细信息
  72. * @throws \Exception
  73. */
  74. public function getCategoryInfoById()
  75. {
  76. $id = $this->request->param('request_id');
  77. if (!$id) {
  78. $this->sendOutput('参数错误', ErrorCode::$paramError);
  79. }
  80. $result = $this->objMGoodsCategory->getCategoryInfoById($id);
  81. if ($result->isSuccess()) {
  82. $this->sendOutput($result->getData());
  83. } else {
  84. $this->sendOutput($result->getData(), $result->getErrorCode());
  85. }
  86. }
  87. /**
  88. * 编辑分类信息
  89. * @throws \Exception
  90. */
  91. public function editCategory()
  92. {
  93. $id = $this->request->param('request_id');
  94. if (empty($id)) {
  95. $this->sendOutput('参数错误', ErrorCode::$paramError);
  96. }
  97. $categoryData = $this->commonFieldFilter();
  98. $categoryData['id'] = $id;
  99. $result = $this->objMGoodsCategory->editCategory($categoryData);
  100. if ($result->isSuccess()) {
  101. parent::sendOutput($result->getData());
  102. } else {
  103. parent::sendOutput($result->getData(), $result->getErrorCode());
  104. }
  105. }
  106. /**
  107. * 分类的显示和隐藏
  108. * @throws \Exception
  109. */
  110. public function updateCategoryStatus()
  111. {
  112. $params['id'] = $this->request->param('request_id');
  113. $params['enableStatus'] = $this->request->param('enableStatus');
  114. foreach ($params as $key => $value) {
  115. if (empty($value)) {
  116. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  117. }
  118. }
  119. $result = $this->objMGoodsCategory->updateCategoryStatus($params);
  120. if ($result->isSuccess()) {
  121. parent::sendOutput($result->getData());
  122. } else {
  123. parent::sendOutput($result->getData(), $result->getErrorCode());
  124. }
  125. }
  126. /**
  127. * 获取所有基础商品分类的列表
  128. * @throws \Exception
  129. */
  130. public function getAllCategory()
  131. {
  132. $params = $this->request->getRawJson();
  133. $selectParams = [];
  134. if(isset($params['enableStatus']) && !empty($params['enableStatus'])) {
  135. $selectParams['enableStatus'] = $params['enableStatus'];
  136. }
  137. $result = $this->objMGoodsCategory->getAllCategory($selectParams);
  138. if ($result->isSuccess()) {
  139. $returnData = $result->getData();
  140. parent::sendOutput($returnData['data'], 0);
  141. } else {
  142. parent::sendOutput($result->getData(), $result->getErrorCode());
  143. }
  144. }
  145. /**
  146. * 删除分类
  147. * @throws \Exception
  148. */
  149. public function delCategory()
  150. {
  151. $categoryId = $this->request->param('request_id');
  152. if (!$categoryId) {
  153. $this->sendOutput('参数错误', ErrorCode::$paramError);
  154. }
  155. if (!is_array($categoryId)) {
  156. $categoryId = [$categoryId];
  157. }
  158. $result = $this->objMGoodsCategory->delCategory($categoryId);
  159. if ($result->isSuccess()) {
  160. parent::sendOutput($result->getData());
  161. } else {
  162. parent::sendOutput($result->getData(), $result->getErrorCode());
  163. }
  164. }
  165. }