request; if ($retuest->isAjax) { if ($retuest->isPost) { $post = Yii::$app->request->post(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($post,[ [['list'], 'safe'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $t = \Yii::$app->db->beginTransaction(); try { $prize_ids = []; $params['where'][] = ['mall_id'=>$this->mall_id]; $findData = AddonsSudoku::lists($params,true); if($findData) foreach ($findData as $v) $prize_ids[$v['prize_id']] = $v['id']; $post_type_list = array_column($post['list'],'type'); if(!in_array(5,$post_type_list)){ throw new \Exception('8个奖品至少选中一个谢谢参与'); } foreach ($post['list'] as $k => $v){ $v['mall_id'] = $this->mall_id; $v['created_at'] = time(); if($prize_ids) $v['id'] = $prize_ids[$v['prize_id']]; $res = AddonsSudoku::setData($v); if(!$res){ throw new \Exception(AddonsSudoku::getStaticError()); } } $t->commit(); return $this->success('操作成功'); }catch (\Exception $e) { $t->rollBack(); return $this->success('操作失败,error:'.$e->getMessage()); return false; } } if ($retuest->isGet) { $params['where'][] = ['mall_id'=>$this->mall_id]; $params['order'] = 'id asc'; $params['with'] = ['goods']; $list = AddonsSudoku::lists($params,true); $coupon_params['where'][] = ['mall_id' => $this->mall_id]; $coupon_params['where'][] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $coupon_params['order'] = 'sort asc,id desc'; $coupon = AddonsCoupon::lists($coupon_params,true); $get_system_setting = PlatformSetting::getConfByGroup('system', true); $api_url = $get_system_setting['api_url']['value']; return $this->success('操作成功', compact('list','coupon','api_url')); } } else { return $this->render($this->action->id); } } public function actionLottery(){ } }