GoodsGroups.Class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gss
  5. * Date: 2021/4/15 0015
  6. * Time: 14:48
  7. */
  8. namespace JinDouYun\Controller\Goods;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\StatusCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\Goods\MGoodsGroups;
  13. class GoodsGroups extends BaseController
  14. {
  15. private $objMGoodsGroups;
  16. public function __construct($isCheckAcl = true, $isMustLogin = true)
  17. {
  18. parent::__construct($isCheckAcl, $isMustLogin);
  19. $this->objMGoodsGroups = new MGoodsGroups($this->onlineEnterpriseId, $this->onlineUserId);
  20. }
  21. /**
  22. * 获取参数
  23. * @return array
  24. */
  25. public function commonFieldFilter()
  26. {
  27. $params = $this->request->getRawJson();
  28. if (empty($params)) {
  29. $this->sendOutput('参数为空', ErrorCode::$paramError);
  30. }
  31. $data = [
  32. "name" => isset($params['name']) ? $params['name'] : '',
  33. ];
  34. foreach ($data as $key => $value) {
  35. if (empty($value) && $value !== 0) {
  36. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  37. }
  38. }
  39. $data['explain'] = getArrayItem($params,'explain','');
  40. $data['sort'] = getArrayItem($params,'sort','');
  41. return $data;
  42. }
  43. /**
  44. * 商品分组添加
  45. */
  46. public function addGoodsGroups()
  47. {
  48. $data = $this->commonFieldFilter();
  49. $data['createTime'] = time();
  50. $result = $this->objMGoodsGroups->addGoodsGroups($data);
  51. if (!$result->isSuccess()) {
  52. parent::sendOutput($result->getData(), $result->getErrorCode());
  53. }
  54. parent::sendOutput($result->getData());
  55. }
  56. /**
  57. * 商品分组删除
  58. */
  59. public function deleteGoodsGroups()
  60. {
  61. $id = $this->request->param('request_id');
  62. if (empty($id)) {
  63. $this->sendOutput('参数为空', ErrorCode::$paramError);
  64. }
  65. $update = [
  66. 'deleteStatus' => StatusCode::$delete
  67. ];
  68. $result = $this->objMGoodsGroups->updateGoodsGroups($update, ['id' => $id]);
  69. if (!$result->isSuccess()) {
  70. parent::sendOutput($result->getData(), $result->getErrorCode());
  71. }
  72. parent::sendOutput($result->getData());
  73. }
  74. /**
  75. * 商品分组修改
  76. */
  77. public function updateGoodsGroups()
  78. {
  79. $id = $this->request->param('request_id');
  80. if (empty($id)) {
  81. $this->sendOutput('参数为空', ErrorCode::$paramError);
  82. }
  83. $update = $this->commonFieldFilter();
  84. $update['updateTime'] = time();
  85. $result = $this->objMGoodsGroups->updateGoodsGroups($update, ['id' => $id]);
  86. if (!$result->isSuccess()) {
  87. parent::sendOutput($result->getData(), $result->getErrorCode());
  88. }
  89. parent::sendOutput($result->getData());
  90. }
  91. /**
  92. * 商品分组启用/禁用
  93. */
  94. public function enableGoodsGroups()
  95. {
  96. $id = $this->request->param('request_id');
  97. if (empty($id)) {
  98. $this->sendOutput('参数为空', ErrorCode::$paramError);
  99. }
  100. $params = $this->request->getRawJson();
  101. $data = [
  102. 'status' => isset($params['status']) ? $params['status'] : '',
  103. ];
  104. foreach ($data as $key => $value) {
  105. if (empty($value) && $value !== 0) {
  106. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  107. }
  108. }
  109. $result = $this->objMGoodsGroups->updateGoodsGroups($data, ['id' => $id]);
  110. if (!$result->isSuccess()) {
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. parent::sendOutput($result->getData());
  114. }
  115. /**
  116. * 商品分组列表
  117. */
  118. public function getAllGoodsGroups()
  119. {
  120. $params = $this->request->getRawJson();
  121. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  122. $selectParams['limit'] = $pageParams['limit'];
  123. $selectParams['offset'] = $pageParams['offset'];
  124. $selectParams['name'] = getArrayItem($params,'name',"");
  125. $result = $this->objMGoodsGroups->getAllGoodsGroups($selectParams);
  126. if (!$result->isSuccess()) {
  127. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  128. }
  129. $returnData = $result->getData();
  130. $pageData = [
  131. 'pageIndex' => $params['page'],
  132. 'pageSize' => $params['pageSize'],
  133. 'pageTotal' => $returnData['total'],
  134. ];
  135. parent::sendOutput($returnData['data'], 0, $pageData);
  136. }
  137. /**
  138. * 商品分组详情
  139. */
  140. public function getReservoirInfo()
  141. {
  142. $params['id'] = $this->request->param('request_id');
  143. if (empty($params['id'])) {
  144. $this->sendOutput('参数为空', ErrorCode::$paramError);
  145. }
  146. $result = $this->objMGoodsGroups->getReservoirInfo($params);
  147. if (!$result->isSuccess()) {
  148. parent::sendOutput($result->getData(), $result->getErrorCode());
  149. }
  150. parent::sendOutput($result->getData());
  151. }
  152. }