GoodsController.php 3.7 KB

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