GoodsController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. //商品列表 shish 2019.12.7
  20. public function actionList()
  21. {
  22. $get = Yii::$app->request->get();
  23. $status = isset($get['status']) ? $get['status'] : -1;
  24. $goodsName = isset($get['goodsName']) && !empty($get['goodsName']) ? $get['goodsName'] : '';
  25. $where = [];
  26. if ($status != -1) {
  27. $where['status'] = $status;
  28. }
  29. if (!empty($goodsName)) {
  30. $where['goodsName'] = ['like', $goodsName];
  31. }
  32. if (isset($get['cId']) && $get['cId'] != -1) {
  33. $where['cId'] = $get['cId'];
  34. }
  35. $where['merchantId'] = $this->sjId;
  36. $where['delStatus'] = 0;
  37. $data = GoodsService::getGoodsList($where);
  38. $asset = MerchantAssetService::getByMerchantId($this->sjId);
  39. $data['MerchantAsset'] = $asset;
  40. util::success($data);
  41. }
  42. //添加商品 shish 2019.12.7
  43. public function actionAdd()
  44. {
  45. $data = Yii::$app->request->post();
  46. $data['merchantId'] = $this->sjId;
  47. $return = GoodsService::addGoods($data);
  48. $id = $return['id'];
  49. $info = GoodsService::getById($id);
  50. util::success($info);
  51. }
  52. //获取商品详情 shish 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. //更新商品 shish 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['merchantId'] = $this->sjId;
  67. GoodsService::updateGoods($id, $data);
  68. util::complete();
  69. }
  70. //商品排序 shish 2020.3.11
  71. public function actionSort()
  72. {
  73. $id = Yii::$app->request->get('id', 0);
  74. $cId = Yii::$app->request->get('cId', 0);
  75. $inTurn = Yii::$app->request->get('inTurn', 0);
  76. //验证商品
  77. $info = GoodsService::getById($id);
  78. GoodsService::valid($info, $this->sjId);
  79. if ($cId != 0) {
  80. //验证分类
  81. $category = CategoryService::getById($cId);
  82. CategoryService::valid($category, $this->sjId);
  83. GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
  84. } else {
  85. GoodsService::updateById($id, ['inTurn' => $inTurn]);
  86. GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
  87. }
  88. util::complete('操作成功');
  89. }
  90. //删除商品 shish 2019.12.7
  91. public function actionDelete()
  92. {
  93. $id = Yii::$app->request->get('id', 0);
  94. $goods = GoodsService::getById($id);
  95. GoodsService::valid($goods, $this->sjId);
  96. GoodsService::deleteGoods($goods);
  97. util::complete();
  98. }
  99. //上下架 shish 2019.12.8
  100. public function actionChangeStatus()
  101. {
  102. $post = Yii::$app->request->post();
  103. $id = isset($post['id']) ? $post['id'] : 0;
  104. $status = isset($post['status']) ? $post['status'] : 1;
  105. $info = GoodsService::getById($id);
  106. GoodsService::valid($info, $this->sjId);
  107. GoodsService::changeStatus($id, $status);
  108. util::complete();
  109. }
  110. //发送短链接到手机上 shish 2019.12.8
  111. public function actionSendShortUrl()
  112. {
  113. $id = Yii::$app->request->get('id');
  114. util::complete();
  115. }
  116. //查看商品短链接 shish 2019.12.8
  117. public function actionShortUrl()
  118. {
  119. $id = Yii::$app->request->get('id');
  120. util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
  121. }
  122. //商品说明 shish 2019.12.8
  123. public function actionIntroduce()
  124. {
  125. $set = GoodsSettingService::getByCondition(['merchantId' => $this->sjId]);
  126. $introduce = $set['goodsIntroduce'];
  127. util::success(['introduce' => $introduce]);
  128. }
  129. //修改商品说明 shish 2019.12.8
  130. public function actionUpdateIntroduce()
  131. {
  132. $introduce = Yii::$app->request->post('introduce', '');
  133. GoodsSettingService::updateByCondition(['merchantId' => $this->sjId], ['goodsIntroduce' => $introduce]);
  134. util::complete('提交成功');
  135. }
  136. //设置 shish 2019.12.8
  137. public function actionSetting()
  138. {
  139. $return = GoodsSettingService::getSetting($this->sjId);
  140. util::success($return);
  141. }
  142. //更新涨价 shish 2019.12.9
  143. public function actionUpdateRise()
  144. {
  145. $post = Yii::$app->request->post();
  146. $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
  147. unset($post['festIdList']);
  148. $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
  149. if ($riseSwitch == 1) {
  150. if (empty($festIdList)) {
  151. util::fail('请选择节日');
  152. }
  153. FestRiseService::deleteByCondition(['merchantId' => $this->sjId]);
  154. $add = [];
  155. foreach ($festIdList as $festId) {
  156. $add[] = ['merchantId' => $this->sjId, 'festId' => $festId];
  157. }
  158. FestRiseService::batchAdd($add);
  159. }
  160. GoodsSettingService::updateByCondition(['merchantId' => $this->sjId], $post);
  161. util::complete('提交成功');
  162. }
  163. }