GoodsController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace addons\WechatVideoShop\backend\controllers;
  3. use addons\WechatVideoShop\common\enums\WechatVideoShopGoodsStatusEnums;
  4. use addons\WechatVideoShop\common\expand\sdk\weixin\src\model\basic\UploadQualificationModel;
  5. use addons\WechatVideoShop\common\expand\sdk\weixin\src\request\basic\UploadQualificationRequest;
  6. use addons\WechatVideoShop\common\helper\WechatRequestHelper;
  7. use addons\WechatVideoShop\common\service\GoodsService;
  8. use addons\WechatVideoShop\common\service\SettingService;
  9. use addons\WechatVideoShop\common\service\ShopService;
  10. use common\enums\StatusEnum;
  11. use yii\helpers\Json;
  12. class GoodsController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. public function actionIndex()
  16. {
  17. if ($this->request->isAjax) {
  18. if ($this->request->isGet) {
  19. $param = \Yii::$app->request->get();
  20. $service = new GoodsService();
  21. $list = $service->getGoodsList($this->mall_id, $param);
  22. if ($list === false) {
  23. return $this->error($service->getError());
  24. }
  25. // 获取所有店铺键值对
  26. $list['shop'] = (new ShopService())->ShopArr($this->mall_id);
  27. $list['status_map'] = WechatVideoShopGoodsStatusEnums::STATUS_REMARKS;
  28. $list['edit_status_map'] = WechatVideoShopGoodsStatusEnums::EDIT_STATUS_REMARKS;
  29. return $this->success('数据请求成功', $list);
  30. }
  31. }
  32. return $this->render($this->action->id);
  33. }
  34. public function actionCreate()
  35. {
  36. if (\Yii::$app->request->isAjax) {
  37. if (\Yii::$app->request->isPost) {
  38. $data = \Yii::$app->request->post();
  39. $valid = \Yii::$app->services->validate->validate($data, [
  40. [['id', 'seven_day_return', 'shop_id'], 'integer'],
  41. [['id', 'seven_day_return'], 'default', 'value' => 0],
  42. [['cat_id', 'goods_id'], 'required'],
  43. [['sale_attr', 'attr', 'qualifications', 'product_id'], 'safe']
  44. ], [
  45. 'cat_id' => '类目',
  46. 'goods_id' => '商品',
  47. 'shop_id' => '店铺',
  48. ]);
  49. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  50. try {
  51. $ret = (new GoodsService())->create($this->mall_id, $data);
  52. } catch (\Exception $e) {
  53. return $this->error($e->getMessage());
  54. }
  55. return is_string($ret) ? $this->error($ret) : $this->success();
  56. }
  57. if (\Yii::$app->request->isGet) {
  58. $data = \Yii::$app->request->get();
  59. $valid = \Yii::$app->services->validate->validate($data, [
  60. [['id'], 'integer'],
  61. [['id'], 'required'],
  62. ], [
  63. 'id' => '商品',
  64. ]);
  65. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  66. }
  67. }
  68. }
  69. /**
  70. * 删除商品
  71. * @return mixed|null
  72. */
  73. public function actionDelete()
  74. {
  75. $data = \Yii::$app->request->post();
  76. $valid = \Yii::$app->services->validate->validate($data, [
  77. [['id'], 'integer'],
  78. [['id'], 'required'],
  79. ], [
  80. 'id' => '商品',
  81. ]);
  82. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  83. // 删除商品
  84. $ret = (new GoodsService())->delete($this->mall_id, $data['id']);
  85. return is_string($ret) ? $this->error($ret) : $this->success('删除成功');
  86. }
  87. /**
  88. * 提交上架,微信那边就是审核中了
  89. * @return mixed|null
  90. */
  91. public function actionOnSale()
  92. {
  93. $data = \Yii::$app->request->post();
  94. $valid = \Yii::$app->services->validate->validate($data, [
  95. [['id', 'type'], 'integer'],
  96. [['id', 'type'], 'required'],
  97. ], [
  98. 'id' => '商品',
  99. 'type' => '操作类型',
  100. ]);
  101. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  102. // 删除商品
  103. $ret = (new GoodsService())->onSale($this->mall_id, $data['id'], $data['type']);
  104. return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
  105. }
  106. /**
  107. * 重新提审
  108. * @return mixed|null
  109. */
  110. public function actionUpdate()
  111. {
  112. return $this->success('提审成功');
  113. }
  114. public function actionSetStock()
  115. {
  116. $data = \Yii::$app->request->post();
  117. $valid = \Yii::$app->services->validate->validate($data, [
  118. [['skus', 'id'], 'safe'],
  119. [['skus', 'id'], 'required'],
  120. ], [
  121. 'skus' => 'SKU',
  122. 'id' => '商品',
  123. ]);
  124. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  125. $skus = Json::decode($data['skus']);
  126. $ret = (new GoodsService())->setStock($this->mall_id, $data['id'], $skus);
  127. return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
  128. }
  129. /**
  130. * 取消提审
  131. * @return mixed|null
  132. */
  133. public function actionCancelAudit()
  134. {
  135. $data = \Yii::$app->request->post();
  136. $valid = \Yii::$app->services->validate->validate($data, [
  137. [['id'], 'integer'],
  138. [['id'], 'required'],
  139. ], [
  140. 'id' => '商品',
  141. ]);
  142. if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  143. // 删除商品
  144. $ret = (new GoodsService())->cancelAudit($this->mall_id, $data['id']);
  145. return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
  146. }
  147. }