| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace addons\UserGift\backend\controllers;
- use addons\Coupon\common\models\AddonsCoupon;
- use addons\UserGift\common\enums\GiftEnum;
- use addons\UserGift\common\models\UserGiftRule;
- use addons\UserGift\common\models\UserGiftRuleSetting;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\logic\common\Gift;
- use common\models\mall\MallAddons;
- use Yii;
- use yii\db\Exception;
- use yii\helpers\Json;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\UserGift\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- public $addonsName = AddonsEnum::ADDONS_NAME_USERGIFT;
- /**
- * 规则管理
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $data = Gift::getGiftList($this->mall_id, $this->addonsName, (new GiftEnum()));
- $this->success('获取成功', $data);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 新增或编辑
- * @Author: lun
- * @DateTime: 2021/12/16 0016 14:51
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionEdit()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['gift_type'], 'required'],
- [['gift_type'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $data = Gift::giftEditByGet($this->mall_id, $this->addonsName, $params['gift_type'], (new GiftEnum()));
- $this->success('获取成功', $data);
- } else {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['gift_type','setting', 'status'], 'required'],
- [['gift_type'], 'string'],
- [['status'], 'integer'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- $res = Gift::giftEditByPost($this->mall_id, $this->addonsName, $params, (new GiftEnum()));
- if ($res == false) throw new Exception('保存失败');
- return $this->success('保存成功');
- } catch (\Exception $e) {
- return $this->error('保存失败:'. $e->getMessage());
- }
- }
- } else {
- // 判断优惠券插件是否安装
- $has_coupon = MallAddons::isInstall($this->mall_id,AddonsEnum::ADDONS_NAME_COUPON);
- return $this->render($this->action->id,['has_coupon' => $has_coupon]);
- }
- }
- /**
- * 获取对应等级的详细内容
- * @Author: lun
- * @DateTime: 2021/12/16 0016 10:38
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionRuleDetail()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['gift_type'], 'required'],
- [['gift_type'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- $list = Gift::getRuleDetail($this->mall_id, $this->addonsName, $params['gift_type'], (new GiftEnum()));
- $this->success('获取成功', $list);
- } catch (\Exception $e) {
- $this->error('获取失败:' . $e->getMessage());
- }
- }
- }
- /**
- * 数据处理-已废除
- * @Author: lun
- * @DateTime: 2021/12/16 0016 14:24
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionHandle()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['id', 'type'], 'required'],
- [['id', 'status'], 'integer'],
- [['type'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- $rule = UserGiftRule::getOne([['id' => $params, 'mall_id' => $this->mall_id]], true,[],'','id,gift_type,status');
- if (empty($rule)) throw new \Exception("查无此规则");
- if ($rule['status'] == $params['status']) throw new \Exception("规则状态已经为关闭状态");
- $rule_params = ['id' => $params['id'], 'gift_type' => $rule['gift_type'], 'status' => $params['status']];
- $res = UserGiftRule::setData($this->mall_id,$rule_params);
- if ($res == false) throw new \Exception(UserGiftRule::getStaticError());
- $this->success('修改成功');
- } catch (\Exception $e) {
- $this->error('修改失败:' . $e->getMessage());
- }
- }
- }
- }
|