GoodsController.php 4.5 KB

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