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()); } } } }