GoodsController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\GoodsSettingService;
  10. use biz\merchant\services\MerchantAssetService;
  11. use biz\saas\services\FestRiseService;
  12. use Yii;
  13. use common\components\util;
  14. use biz\goods\services\GoodsService;
  15. class GoodsController extends BaseController
  16. {
  17. //商品列表 shish 2019.12.7
  18. public function actionList()
  19. {
  20. $get = Yii::$app->request->get();
  21. $status = isset($get['status']) ? $get['status'] : -1;
  22. $goodsName = isset($get['goodsName']) && !empty($get['goodsName']) ? $get['goodsName'] : '';
  23. $where = [];
  24. if ($status != -1) {
  25. $where['status'] = $status;
  26. }
  27. if (!empty($goodsName)) {
  28. $where['goodsName'] = ['like', $goodsName];
  29. }
  30. $where['merchantId'] = $this->merchantId;
  31. $where['delStatus'] = 0;
  32. $data = GoodsService::getGoodsList($where);
  33. $asset = MerchantAssetService::getByMerchantId($this->merchantId);
  34. $data['MerchantAsset'] = $asset;
  35. util::success($data);
  36. }
  37. //添加商品 shish 2019.12.7
  38. public function actionAdd()
  39. {
  40. $data = Yii::$app->request->post();
  41. $data['merchantId'] = $this->merchantId;
  42. $return = GoodsService::addGoods($data);
  43. $id = $return['id'];
  44. $info = GoodsService::getById($id);
  45. util::success($info);
  46. }
  47. //获取商品详情 shish 2019.12.7
  48. public function actionDetail()
  49. {
  50. $id = Yii::$app->request->get('id');
  51. $goods = GoodsService::getGoodsInfo($id);
  52. util::success($goods);
  53. }
  54. //更新商品 shish 2019.12.7
  55. public function actionUpdate()
  56. {
  57. $data = Yii::$app->request->post();
  58. $id = isset($data['id']) ? $data['id'] : 0;
  59. unset($data['id']);
  60. $info = GoodsService::getById($id);
  61. GoodsService::valid($info, $this->merchantId);
  62. $data['merchantId'] = $this->merchantId;
  63. GoodsService::updateGoods($id, $data);
  64. util::ok();
  65. }
  66. //商品排序
  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. util::ok('操作成功');
  75. }
  76. //删除商品 shish 2019.12.7
  77. public function actionDelete()
  78. {
  79. $id = Yii::$app->request->get('id', 0);
  80. GoodsService::deleteGoods($id, $this->admin);
  81. util::ok();
  82. }
  83. //上下架 shish 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->merchantId);
  91. GoodsService::changeStatus($id, $status);
  92. util::ok();
  93. }
  94. //发送短链接到手机上 shish 2019.12.8
  95. public function actionSendShortUrl()
  96. {
  97. $id = Yii::$app->request->get('id');
  98. util::ok();
  99. }
  100. //查看商品短链接 shish 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. //商品说明 shish 2019.12.8
  107. public function actionIntroduce()
  108. {
  109. $set = GoodsSettingService::getByCondition(['merchantId' => $this->merchantId]);
  110. $introduce = $set['goodsIntroduce'];
  111. util::success(['introduce' => $introduce]);
  112. }
  113. //修改商品说明 shish 2019.12.8
  114. public function actionUpdateIntroduce()
  115. {
  116. $introduce = Yii::$app->request->post('introduce', '');
  117. GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], ['goodsIntroduce' => $introduce]);
  118. util::ok('提交成功');
  119. }
  120. //设置 shish 2019.12.8
  121. public function actionSetting()
  122. {
  123. $return = GoodsSettingService::getSetting($this->merchantId);
  124. util::success($return);
  125. }
  126. //更新涨价 shish 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(['merchantId' => $this->merchantId]);
  138. $add = [];
  139. foreach ($festIdList as $festId) {
  140. $add[] = ['merchantId' => $this->merchantId, 'festId' => $festId];
  141. }
  142. FestRiseService::batchAdd($add);
  143. }
  144. GoodsSettingService::updateByCondition(['merchantId' => $this->merchantId], $post);
  145. util::ok('提交成功');
  146. }
  147. }