request->isAjax) { if (\Yii::$app->request->isGet) { $extra = StoreExtra::findOne(['store_id'=>$this->store_id]); $data = ['give_setting'=>'','deduct_setting'=>'','coupon_list1'=>[],'coupon_list2'=>[]]; if($extra){ $give_setting = json_decode($extra['give_setting'],true); $deduct_setting = json_decode($extra['deduct_setting'],true); $data['give_setting'] =''; //为了兼容之前前端由 el-radio换成el-checkbox if(!empty($give_setting)){ if(!empty($give_setting['coupon_give']['give_type1'])&&in_array($give_setting['coupon_give']['give_type1'],['true',1])){ $give_setting['coupon_give']['give_type1'] = true; }else{ $give_setting['coupon_give']['give_type1'] = false; } if(!empty($give_setting['coupon_give']['give_type2'])&&in_array($give_setting['coupon_give']['give_type2'],['true',1])){ $give_setting['coupon_give']['give_type2'] = true; }else{ $give_setting['coupon_give']['give_type2'] = false; } } $data['give_setting'] = $give_setting; $data['deduct_setting'] = !empty($deduct_setting)?$deduct_setting:''; } $store_id = $this->store_id; $coupon_list = StoreCoupon::lists([ 'where'=>[ new Expression("FIND_IN_SET({$store_id},store_id)"), ['mall_id'=>$this->mall_id], ['status'=>StatusEnum::ENABLED], ['coupon_status'=>AddonsCouponEnum::STATUS_RECEIVING], ], 'select'=>'id,name,type' ]); foreach ($coupon_list as $item){ $item['name'] = '门店:'.$item['name']; $item['from_type'] = 2; switch ($item['type']){ case 1: $data['coupon_list1'][]=$item; break; case 2: $data['coupon_list2'][]=$item; break; } } $is_install = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_COUPON); if($is_install){ $coupon_list = AddonsCoupon::lists([ 'where'=>[ new Expression("FIND_IN_SET({$store_id},store_id)"), ['mall_id'=>$this->mall_id], ['status'=>StatusEnum::ENABLED], ['coupon_status'=>AddonsCouponEnum::STATUS_RECEIVING], ], 'select'=>'id,name,type,store_id' ]); foreach ($coupon_list as $item){ $item['name'] = '平台:'.$item['name']; $item['from_type'] = 1; switch ($item['type']){ case 1: $data['coupon_list1'][]=$item; break; case 2: $data['coupon_list2'][]=$item; break; } } } return $this->success('ok', $data); } else { $params = \Yii::$app->request->post('form'); $params['mall_id'] = $this->mall_id; $params['store_id'] = $this->store_id; //为了兼容之前前端由 el-radio换成el-checkbox if(!empty($params['give_setting']['coupon_give']['give_type1'])&&$params['give_setting']['coupon_give']['give_type1']=='true'){ $params['give_setting']['coupon_give']['give_type1'] = true; }else{ $params['give_setting']['coupon_give']['give_type1'] = false; } if(!empty($params['give_setting']['coupon_give']['give_type2']&&$params['give_setting']['coupon_give']['give_type2']=='true')){ $params['give_setting']['coupon_give']['give_type2'] = true; }else{ $params['give_setting']['coupon_give']['give_type2'] = false; } $res = StoreExtra::setData($params); if ($res == false) return $this->error(StoreExtra::getStaticError()); return $this->success('操作成功'); } } return $this->render($this->action->id); } }