GoodsController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 actionUpdate()
  44. {
  45. $data = Yii::$app->request->post();
  46. $id = isset($data['id']) ? $data['id'] : 0;
  47. $info = GoodsService::getById($id);
  48. GoodsService::valid($info, $this->mainId);
  49. $data['sjId'] = $this->sjId;
  50. $data['mainId'] = $this->mainId;
  51. GoodsService::updateGoods($id, $data);
  52. util::complete();
  53. }
  54. //商品排序 ssh 2020.3.11
  55. public function actionSort()
  56. {
  57. $id = Yii::$app->request->get('id', 0);
  58. $cId = Yii::$app->request->get('cId', 0);
  59. $inTurn = Yii::$app->request->get('inTurn', 0);
  60. //验证商品
  61. $info = GoodsService::getById($id);
  62. GoodsService::valid($info, $this->mainId);
  63. if ($cId != 0) {
  64. //验证分类
  65. $category = CategoryService::getById($cId);
  66. CategoryService::valid($category, $this->mainId);
  67. GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
  68. } else {
  69. GoodsService::updateById($id, ['inTurn' => $inTurn]);
  70. GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
  71. }
  72. util::complete('操作成功');
  73. }
  74. //删除商品 ssh 2019.12.7
  75. public function actionDelete()
  76. {
  77. $id = Yii::$app->request->get('id', 0);
  78. $goods = GoodsService::getById($id);
  79. GoodsService::valid($goods, $this->mainId);
  80. GoodsService::deleteGoods($goods);
  81. util::complete();
  82. }
  83. //上下架 ssh 2019.12.8
  84. public function actionChangeStatus()
  85. {
  86. $post = Yii::$app->request->post();
  87. $id = isset($post['id']) ? $post['id'] : 0;
  88. $status = isset($post['status']) ? $post['status'] : 1;
  89. $info = GoodsService::getById($id);
  90. GoodsService::valid($info, $this->mainId);
  91. GoodsService::changeStatus($id, $status);
  92. util::complete();
  93. }
  94. //发送短链接到手机上 ssh 2019.12.8
  95. public function actionSendShortUrl()
  96. {
  97. $id = Yii::$app->request->get('id');
  98. util::complete();
  99. }
  100. //查看商品短链接 ssh 2019.12.8
  101. public function actionShortUrl()
  102. {
  103. $id = Yii::$app->request->get('id');
  104. util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
  105. }
  106. //商品说明 ssh 2019.12.8
  107. public function actionIntroduce()
  108. {
  109. $set = GoodsSettingService::getByCondition(['sjId' => $this->sjId]);
  110. $introduce = $set['goodsIntroduce'];
  111. util::success(['introduce' => $introduce]);
  112. }
  113. //修改商品说明 ssh 2019.12.8
  114. public function actionUpdateIntroduce()
  115. {
  116. $introduce = Yii::$app->request->post('introduce', '');
  117. GoodsSettingService::updateByCondition(['sjId' => $this->sjId], ['goodsIntroduce' => $introduce]);
  118. util::complete('提交成功');
  119. }
  120. //设置 ssh 2019.12.8
  121. public function actionSetting()
  122. {
  123. $return = GoodsSettingService::getSetting($this->sjId);
  124. util::success($return);
  125. }
  126. //更新涨价 ssh 2019.12.9
  127. public function actionUpdateRise()
  128. {
  129. $post = Yii::$app->request->post();
  130. $festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
  131. unset($post['festIdList']);
  132. $riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
  133. if ($riseSwitch == 1) {
  134. if (empty($festIdList)) {
  135. util::fail('请选择节日');
  136. }
  137. FestRiseService::deleteByCondition(['sjId' => $this->sjId]);
  138. $add = [];
  139. foreach ($festIdList as $festId) {
  140. $add[] = ['sjId' => $this->sjId, 'festId' => $festId];
  141. }
  142. FestRiseService::batchAdd($add);
  143. }
  144. GoodsSettingService::updateByCondition(['sjId' => $this->sjId], $post);
  145. util::complete('提交成功');
  146. }
  147. }