GoodsBrand.Class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * 商品品牌
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/5
  7. * Time: 11:25
  8. */
  9. namespace JinDouYun\Controller\GoodsManage;
  10. use JinDouYun\Controller\BaseController;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Model\GoodsManage\MGoodsBrand;
  15. class GoodsBrand extends BaseController
  16. {
  17. private $objMGoodsBrand;
  18. /**
  19. * GoodsBrand constructor.
  20. * @param bool $isCheckAcl
  21. * @param bool $isMustLogin
  22. * @throws \Exception
  23. */
  24. public function __construct($isCheckAcl = true, $isMustLogin = true)
  25. {
  26. parent::__construct($isCheckAcl, $isMustLogin);
  27. $this->objMGoodsBrand = new MGoodsBrand($this->onlineUserId, $this->onlineEnterpriseId);
  28. }
  29. /**
  30. * 添加和编辑商品品牌
  31. *
  32. * @return array
  33. */
  34. public function commonFieldFilter()
  35. {
  36. $params = $this->request->getRawJson();
  37. if (empty($params)) {
  38. $this->sendOutput('参数为空', ErrorCode::$paramError);
  39. }
  40. $goodsBrandData = [
  41. 'title' => isset($params['title']) ? $params['title'] : '',
  42. ];
  43. foreach ($goodsBrandData as $key => $value) {
  44. if (empty($value)) {
  45. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  46. }
  47. }
  48. $goodsBrandData['supplier'] = isset($params['supplier']) ? $params['supplier'] : '';
  49. $goodsBrandData['images'] = isset($params['images']) ? $params['images'] : null;
  50. $goodsBrandData['sort'] = isset($params['sort']) ? $params['sort'] : 0;
  51. $goodsBrandData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;
  52. $goodsBrandData['createTime'] = time();
  53. $goodsBrandData['updateTime'] = time();
  54. return $goodsBrandData;
  55. }
  56. /**
  57. * 添加商品品牌
  58. * @throws \Exception
  59. */
  60. public function addBrand()
  61. {
  62. $brandData = $this->commonFieldFilter();
  63. $result = $this->objMGoodsBrand->addBrand($brandData);
  64. if ($result->isSuccess()) {
  65. parent::sendOutput($result->getData());
  66. }
  67. parent::sendOutput($result->getData(), $result->getErrorCode());
  68. }
  69. /**
  70. * 编辑品牌信息
  71. * @throws \Exception
  72. */
  73. public function editBrand()
  74. {
  75. $id = $this->request->param('request_id');
  76. if (empty($id)) {
  77. $this->sendOutput('参数错误', ErrorCode::$paramError);
  78. }
  79. $brandData = $this->commonFieldFilter();
  80. $brandData['id'] = $id;
  81. unset($brandData['createTime']);
  82. $result = $this->objMGoodsBrand->editBrand($brandData);
  83. if ($result->isSuccess()) {
  84. parent::sendOutput($result->getData());
  85. }
  86. parent::sendOutput($result->getData(), $result->getErrorCode());
  87. }
  88. /**
  89. * 获取指定id的品牌详情
  90. * @throws \Exception
  91. */
  92. public function getBrandInfoById()
  93. {
  94. $id = $this->request->param('request_id');
  95. if (!$id) {
  96. $this->sendOutput('参数错误', ErrorCode::$paramError);
  97. }
  98. $result = $this->objMGoodsBrand->getBrandInfoById($id);
  99. if ($result->isSuccess()) {
  100. $this->sendOutput($result->getData());
  101. }
  102. $this->sendOutput($result->getData(), $result->getErrorCode());
  103. }
  104. /**
  105. * 品牌的显示和隐藏
  106. * @throws \Exception
  107. */
  108. public function updateBrandStatus()
  109. {
  110. $params['id'] = $this->request->param('request_id');
  111. $params['enableStatus'] = $this->request->param('enableStatus');//4禁用 5启用
  112. foreach ($params as $key => $value) {
  113. if (empty($value)) {
  114. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  115. }
  116. }
  117. $result = $this->objMGoodsBrand->updateBrandStatus($params);
  118. if ($result->isSuccess()) {
  119. parent::sendOutput($result->getData());
  120. }
  121. parent::sendOutput($result->getData(), $result->getErrorCode());
  122. }
  123. /**
  124. * 获取所有品牌
  125. * @throws \Exception
  126. */
  127. public function getAllBrand()
  128. {
  129. $page = $this->request->param('page') ? $this->request->param('page') : 1;
  130. $pageSize = $this->request->param('pageSize') ? $this->request->param('pageSize') : 10;
  131. $keyword = $this->request->param('keyword') ? $this->request->param('keyword') : '';
  132. $offset = ($page - 1) * $pageSize;
  133. $selectParams = [
  134. 'limit' => $pageSize,
  135. 'offset' => $offset,
  136. ];
  137. if (!empty($keyword)) {
  138. $selectParams['keyword'] = $keyword;
  139. }
  140. $reportData = $this->objMGoodsBrand->getAllBrand($selectParams);
  141. if ($reportData->isSuccess()) {
  142. $returnData = $reportData->getData();
  143. $pageData = [
  144. 'pageIndex' => $page,
  145. 'pageSize' => $pageSize,
  146. 'pageTotal' => $returnData['total'],
  147. ];
  148. parent::sendOutput($returnData['data'], 0, $pageData);
  149. }
  150. parent::sendOutput($reportData->getData(), ErrorCode::$dberror);
  151. }
  152. /**
  153. * 删除分类
  154. * @throws \Exception
  155. */
  156. public function delBrand()
  157. {
  158. $brandId = $this->request->param('request_id');
  159. if (!$brandId) {
  160. $this->sendOutput('参数错误', ErrorCode::$paramError);
  161. }
  162. if (!is_array($brandId)) {
  163. $brandId = [$brandId];
  164. }
  165. $result = $this->objMGoodsBrand->delBrand($brandId);
  166. if ($result->isSuccess()) {
  167. parent::sendOutput($result->getData());
  168. }
  169. parent::sendOutput($result->getData(), $result->getErrorCode());
  170. }
  171. }