GoodsController.php 6.5 KB

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