GoodsController.php 4.5 KB

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