GoodsController.php 4.7 KB

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