GoodsController.php 4.0 KB

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