GoodsController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: admin
  5. * Date: 2019/12/1
  6. * Time: 13:55
  7. */
  8. namespace ghs\controllers;
  9. use bizHd\goods\services\CategoryService;
  10. use bizHd\goods\services\GoodsCategoryService;
  11. use bizHd\goods\services\GoodsSettingService;
  12. use biz\sj\services\MerchantAssetService;
  13. use bizHd\saas\services\FestRiseService;
  14. use Yii;
  15. use common\components\util;
  16. use bizHd\goods\services\GoodsService;
  17. class GoodsController extends BaseController
  18. {
  19. //商品列表 ssh 2019.12.7
  20. public function actionList()
  21. {
  22. $get = Yii::$app->request->get();
  23. $status = isset($get['status']) ? $get['status'] : -1;
  24. $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
  25. $where = [];
  26. if ($status != -1) {
  27. $where['status'] = $status;
  28. }
  29. if (!empty($name)) {
  30. $where['name'] = ['like', $name];
  31. }
  32. if (isset($get['cId']) && $get['cId'] != -1) {
  33. $where['cId'] = $get['cId'];
  34. }
  35. $where['sjId'] = $this->sjId;
  36. $where['delStatus'] = 0;
  37. $data = GoodsService::getGoodsList($where);
  38. $asset = MerchantAssetService::getBySjId($this->sjId);
  39. $data['MerchantAsset'] = $asset;
  40. util::success($data);
  41. }
  42. //添加商品 ssh 2019.12.7
  43. public function actionAdd()
  44. {
  45. $data = Yii::$app->request->post();
  46. $data['sjId'] = $this->sjId;
  47. $return = GoodsService::addGoods($data);
  48. $id = $return['id'];
  49. $info = GoodsService::getById($id);
  50. util::success($info);
  51. }
  52. //获取商品详情 ssh 2019.12.7
  53. public function actionDetail()
  54. {
  55. $id = Yii::$app->request->get('id');
  56. $goods = GoodsService::getGoodsInfo($id);
  57. util::success($goods);
  58. }
  59. //更新商品 ssh 2019.12.7
  60. public function actionUpdate()
  61. {
  62. $data = Yii::$app->request->post();
  63. $id = isset($data['id']) ? $data['id'] : 0;
  64. $info = GoodsService::getById($id);
  65. GoodsService::valid($info, $this->sjId);
  66. $data['sjId'] = $this->sjId;
  67. $data['mainId'] = $this->mainId;
  68. GoodsService::updateGoods($id, $data);
  69. util::complete();
  70. }
  71. //商品排序 ssh 2020.3.11
  72. public function actionSort()
  73. {
  74. $id = Yii::$app->request->get('id', 0);
  75. $cId = Yii::$app->request->get('cId', 0);
  76. $inTurn = Yii::$app->request->get('inTurn', 0);
  77. //验证商品
  78. $info = GoodsService::getById($id);
  79. GoodsService::valid($info, $this->sjId);
  80. if ($cId != 0) {
  81. //验证分类
  82. $category = CategoryService::getById($cId);
  83. CategoryService::valid($category, $this->sjId);
  84. GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
  85. } else {
  86. GoodsService::updateById($id, ['inTurn' => $inTurn]);
  87. GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
  88. }
  89. util::complete('操作成功');
  90. }
  91. //删除商品 ssh 2019.12.7
  92. public function actionDelete()
  93. {
  94. $id = Yii::$app->request->get('id', 0);
  95. $goods = GoodsService::getById($id);
  96. GoodsService::valid($goods, $this->sjId);
  97. GoodsService::deleteGoods($goods);
  98. util::complete();
  99. }
  100. //上下架 ssh 2019.12.8
  101. public function actionChangeStatus()
  102. {
  103. $post = Yii::$app->request->post();
  104. $id = isset($post['id']) ? $post['id'] : 0;
  105. $status = isset($post['status']) ? $post['status'] : 1;
  106. $info = GoodsService::getById($id);
  107. GoodsService::valid($info, $this->sjId);
  108. GoodsService::changeStatus($id, $status);
  109. util::complete();
  110. }
  111. //发送短链接到手机上 ssh 2019.12.8
  112. public function actionSendShortUrl()
  113. {
  114. $id = Yii::$app->request->get('id');
  115. util::complete();
  116. }
  117. //查看商品短链接 ssh 2019.12.8
  118. public function actionShortUrl()
  119. {
  120. $id = Yii::$app->request->get('id');
  121. util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
  122. }
  123. //商品说明 ssh 2019.12.8
  124. public function actionIntroduce()
  125. {
  126. $set = GoodsSettingService::getByCondition(['sjId' => $this->sjId]);
  127. $introduce = $set['goodsIntroduce'];
  128. util::success(['introduce' => $introduce]);
  129. }
  130. //修改商品说明 ssh 2019.12.8
  131. public function actionUpdateIntroduce()
  132. {
  133. $introduce = Yii::$app->request->post('introduce', '');
  134. GoodsSettingService::updateByCondition(['sjId' => $this->sjId], ['goodsIntroduce' => $introduce]);
  135. util::complete('提交成功');
  136. }
  137. //设置 ssh 2019.12.8
  138. public function actionSetting()
  139. {
  140. $return = GoodsSettingService::getSetting($this->sjId);
  141. util::success($return);
  142. }
  143. //更新涨价 ssh 2019.12.9
  144. public function actionUpdateRise()
  145. {
  146. $post = Yii::$app->request->post();
  147. $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
  148. unset($post['festIdList']);
  149. $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
  150. if ($riseSwitch == 1) {
  151. if (empty($festIdList)) {
  152. util::fail('请选择节日');
  153. }
  154. FestRiseService::deleteByCondition(['sjId' => $this->sjId]);
  155. $add = [];
  156. foreach ($festIdList as $festId) {
  157. $add[] = ['sjId' => $this->sjId, 'festId' => $festId];
  158. }
  159. FestRiseService::batchAdd($add);
  160. }
  161. GoodsSettingService::updateByCondition(['sjId' => $this->sjId], $post);
  162. util::complete('提交成功');
  163. }
  164. }