GoodsController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: admin
  5. * Date: 2019/12/1
  6. * Time: 13:55
  7. */
  8. namespace shop\controllers;
  9. use biz\goods\services\CategoryService;
  10. use biz\goods\services\GoodsCategoryService;
  11. use biz\goods\services\GoodsSettingService;
  12. use biz\merchant\services\MerchantAssetService;
  13. use biz\saas\services\FestRiseService;
  14. use Yii;
  15. use common\components\util;
  16. use biz\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->merchantId;
  36. $where['delStatus'] = 0;
  37. $data = GoodsService::getGoodsList($where);
  38. $asset = MerchantAssetService::getByMerchantId($this->merchantId);
  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->merchantId;
  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->merchantId);
  66. $data['merchantId'] = $this->merchantId;
  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', -1);
  75. $inTurn = Yii::$app->request->get('inTurn', 0);
  76. //验证商品
  77. $info = GoodsService::getById($id);
  78. GoodsService::valid($info, $this->merchantId);
  79. if ($cId != -1) {
  80. //验证分类
  81. $category = CategoryService::getById($cId);
  82. CategoryService::valid($category, $this->merchantId);
  83. GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
  84. } else {
  85. GoodsService::updateById($id, ['inTurn' => $inTurn]);
  86. }
  87. util::complete('操作成功');
  88. }
  89. //删除商品 shish 2019.12.7
  90. public function actionDelete()
  91. {
  92. $id = Yii::$app->request->get('id', 0);
  93. GoodsService::deleteGoods($id, $this->admin);
  94. util::complete();
  95. }
  96. //上下架 shish 2019.12.8
  97. public function actionChangeStatus()
  98. {
  99. $post = Yii::$app->request->post();
  100. $id = isset($post['id']) ? $post['id'] : 0;
  101. $status = isset($post['status']) ? $post['status'] : 1;
  102. $info = GoodsService::getById($id);
  103. GoodsService::valid($info, $this->merchantId);
  104. GoodsService::changeStatus($id, $status);
  105. util::complete();
  106. }
  107. //发送短链接到手机上 shish 2019.12.8
  108. public function actionSendShortUrl()
  109. {
  110. $id = Yii::$app->request->get('id');
  111. util::complete();
  112. }
  113. //查看商品短链接 shish 2019.12.8
  114. public function actionShortUrl()
  115. {
  116. $id = Yii::$app->request->get('id');
  117. util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
  118. }
  119. //商品说明 shish 2019.12.8
  120. public function actionIntroduce()
  121. {
  122. $set = GoodsSettingService::getByCondition(['merchantId' => $this->merchantId]);
  123. $introduce = $set['goodsIntroduce'];
  124. util::success(['introduce' => $introduce]);
  125. }
  126. //修改商品说明 shish 2019.12.8
  127. public function actionUpdateIntroduce()
  128. {
  129. $introduce = Yii::$app->request->post('introduce', '');
  130. GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], ['goodsIntroduce' => $introduce]);
  131. util::complete('提交成功');
  132. }
  133. //设置 shish 2019.12.8
  134. public function actionSetting()
  135. {
  136. $return = GoodsSettingService::getSetting($this->merchantId);
  137. util::success($return);
  138. }
  139. //更新涨价 shish 2019.12.9
  140. public function actionUpdateRise()
  141. {
  142. $post = Yii::$app->request->post();
  143. $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
  144. unset($post['festIdList']);
  145. $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
  146. if ($riseSwitch == 1) {
  147. if (empty($festIdList)) {
  148. util::fail('请选择节日');
  149. }
  150. FestRiseService::deleteByCondition(['merchantId' => $this->merchantId]);
  151. $add = [];
  152. foreach ($festIdList as $festId) {
  153. $add[] = ['merchantId' => $this->merchantId, 'festId' => $festId];
  154. }
  155. FestRiseService::batchAdd($add);
  156. }
  157. GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], $post);
  158. util::complete('提交成功');
  159. }
  160. }