| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace addons\ScoreExpansion\backend\controllers;
- use addons\ScoreExpansion\backend\services\ScoreExpansionRecommendRewardGoodsService;
- use addons\ScoreExpansion\common\models\ScoreExpansionRecommendRewardGoods;
- use Yii;
- use yii\db\Exception;
- class GoodsController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 商品页面
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render($this->action->id);
- }
- /**
- * 商品列表
- *
- * @return void
- */
- public function actionList()
- {
- $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
- $this->success('success', $scoreExpansionRecommendRewardGoodsService->list($this->request->get()));
- }
- /**
- * 设置独立奖励
- *
- * @return void
- */
- public function actionEdit()
- {
- $post = $this->request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['id', 'is_alone', 'setting'], 'required'],
- [['id', 'is_alone'], 'integer'],
- ]);
- if ($res === false) {
- $this->error(Yii::$app->services->validate->getErrorMessage());
- return;
- }
- $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
- if (!$scoreExpansionRecommendRewardGoodsService->edit($post)) {
- $this->error($scoreExpansionRecommendRewardGoodsService->getError());
- return;
- }
- $this->success();
- }
- /**
- * 删除商品
- *
- * @return void
- */
- public function actionDel()
- {
- $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
- if (!$scoreExpansionRecommendRewardGoodsService->del($this->request->post('id'))) {
- $this->error($scoreExpansionRecommendRewardGoodsService->getError());
- return;
- }
- $this->success();
- }
- /**
- * 添加商品
- *
- * @return void
- * @throws Exception
- */
- public function actionSave()
- {
- $post = $this->request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['goods_ids'], 'required'],
- ]);
- if ($res === false) {
- $this->error(Yii::$app->services->validate->getErrorMessage());
- return;
- }
- $scoreExpansionRecommendRewardGoodsService = new ScoreExpansionRecommendRewardGoodsService(['mall_id' => $this->mall_id]);
- if (!$scoreExpansionRecommendRewardGoodsService->save($post['goods_ids'])) {
- $this->error($scoreExpansionRecommendRewardGoodsService->getError() ?: '添加失败');
- return;
- }
- $this->success();
- }
- }
|