GoodsController.php 4.8 KB

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