| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace addons\WechatVideoShop\backend\controllers;
- use addons\WechatVideoShop\common\enums\WechatVideoShopGoodsStatusEnums;
- use addons\WechatVideoShop\common\expand\sdk\weixin\src\model\basic\UploadQualificationModel;
- use addons\WechatVideoShop\common\expand\sdk\weixin\src\request\basic\UploadQualificationRequest;
- use addons\WechatVideoShop\common\helper\WechatRequestHelper;
- use addons\WechatVideoShop\common\service\GoodsService;
- use addons\WechatVideoShop\common\service\SettingService;
- use addons\WechatVideoShop\common\service\ShopService;
- use common\enums\StatusEnum;
- use yii\helpers\Json;
- class GoodsController extends BaseController
- {
- public $enableCsrfValidation = false;
- public function actionIndex()
- {
- if ($this->request->isAjax) {
- if ($this->request->isGet) {
- $param = \Yii::$app->request->get();
- $service = new GoodsService();
- $list = $service->getGoodsList($this->mall_id, $param);
- if ($list === false) {
- return $this->error($service->getError());
- }
- // 获取所有店铺键值对
- $list['shop'] = (new ShopService())->ShopArr($this->mall_id);
- $list['status_map'] = WechatVideoShopGoodsStatusEnums::STATUS_REMARKS;
- $list['edit_status_map'] = WechatVideoShopGoodsStatusEnums::EDIT_STATUS_REMARKS;
- return $this->success('数据请求成功', $list);
- }
- }
- return $this->render($this->action->id);
- }
- public function actionCreate()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $data = \Yii::$app->request->post();
- $valid = \Yii::$app->services->validate->validate($data, [
- [['id', 'seven_day_return', 'shop_id'], 'integer'],
- [['id', 'seven_day_return'], 'default', 'value' => 0],
- [['cat_id', 'goods_id'], 'required'],
- [['sale_attr', 'attr', 'qualifications', 'product_id'], 'safe']
- ], [
- 'cat_id' => '类目',
- 'goods_id' => '商品',
- 'shop_id' => '店铺',
- ]);
- if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- try {
- $ret = (new GoodsService())->create($this->mall_id, $data);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- return is_string($ret) ? $this->error($ret) : $this->success();
- }
- if (\Yii::$app->request->isGet) {
- $data = \Yii::$app->request->get();
- $valid = \Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required'],
- ], [
- 'id' => '商品',
- ]);
- if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- }
- }
- }
- /**
- * 删除商品
- * @return mixed|null
- */
- public function actionDelete()
- {
- $data = \Yii::$app->request->post();
- $valid = \Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required'],
- ], [
- 'id' => '商品',
- ]);
- if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 删除商品
- $ret = (new GoodsService())->delete($this->mall_id, $data['id']);
- return is_string($ret) ? $this->error($ret) : $this->success('删除成功');
- }
- /**
- * 提交上架,微信那边就是审核中了
- * @return mixed|null
- */
- public function actionOnSale()
- {
- $data = \Yii::$app->request->post();
- $valid = \Yii::$app->services->validate->validate($data, [
- [['id', 'type'], 'integer'],
- [['id', 'type'], 'required'],
- ], [
- 'id' => '商品',
- 'type' => '操作类型',
- ]);
- if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 删除商品
- $ret = (new GoodsService())->onSale($this->mall_id, $data['id'], $data['type']);
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
- }
-
- /**
- * 重新提审
- * @return mixed|null
- */
- public function actionUpdate()
- {
- return $this->success('提审成功');
- }
- public function actionSetStock()
- {
- $data = \Yii::$app->request->post();
- $valid = \Yii::$app->services->validate->validate($data, [
- [['skus', 'id'], 'safe'],
- [['skus', 'id'], 'required'],
- ], [
- 'skus' => 'SKU',
- 'id' => '商品',
- ]);
- if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $skus = Json::decode($data['skus']);
- $ret = (new GoodsService())->setStock($this->mall_id, $data['id'], $skus);
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
- }
- /**
- * 取消提审
- * @return mixed|null
- */
- public function actionCancelAudit()
- {
- $data = \Yii::$app->request->post();
- $valid = \Yii::$app->services->validate->validate($data, [
- [['id'], 'integer'],
- [['id'], 'required'],
- ], [
- 'id' => '商品',
- ]);
- if ($valid === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 删除商品
- $ret = (new GoodsService())->cancelAudit($this->mall_id, $data['id']);
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
- }
- }
|