[ 'class' => 'kucha\ueditor\UEditorAction', ], // 'config' => [ // "imagePathFormat" => "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}" //上传保存路径 // ], ]; } protected function findModel($id) { if (($model = OperaTouristAgent::findOne(['tourist_id' => $id])) !== null) { $model_arr['ota'] = $model; $model_arr['otc'] = OperaTouristCommon::findOne(['tourist_id' => $id]); //寻找start_area_id 上级 $parent_id = BaseArea::findOne(['ID' => $model_arr['otc']->start_area_id]); $model_arr['otc']->tp_start_area_id1 = $parent_id->PARENT_ID; //end $model_arr['ote'] = OperaTouristExtra::findOne(['tourist_id' => $id]); $model_arr['ott'] = OperaTouristCtrip::findOne(['sp_tourist_id'=>$id,'cancel_flag'=>0]); $model_arr['img'] = OperaTouristImg::findAll(['tourist_id' => $id,'cancel_flag' => 0]); return $model_arr; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * @return string * * 添加产品的信息展示 */ public function actionIndex() { $model_ota = new OperaTouristAgent(); $model_otc = new OperaTouristCommon(); $model_ote = new OperaTouristExtra(); $model_ott = new OperaTouristCtrip(); $model_img[0] = new OperaTouristImg(); $data['view'] = 'index'; $data['op'] = 'add'; $data['area'] = BaseTourist::getArea(Yii::$app->request->get('area_id')); return $this->render('_base', ['data' => $data, 'model_ota' => $model_ota, 'model_otc' => $model_otc, 'model_ote' => $model_ote,'model_ott' => $model_ott, 'model_img' => $model_img]); } // public function actionValidateForm() // { // Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; // $model = new OperaTouristCommon();//这里要替换成自己的模型类 // $model->load(Yii::$app->request->post()); // return \yii\widgets\ActiveForm::validate($model); // } /* * 添加或修改产品操作 */ public function actionAddTouristBase() { $cookies = Yii::$app->request->cookies; $user_id = $cookies->getValue('user_id', 1); $otc = Yii::$app->request->post('OperaTouristCommon'); $ott = Yii::$app->request->post('OperaTouristCtrip'); $tourist_id = isset($otc['tourist_id']) ? $otc['tourist_id'] : ''; if ($tourist_id != '') { $model_arr = $this->findModel($tourist_id); $model_ota = $model_arr['ota']; $model_otc = $model_arr['otc']; $model_ote = $model_arr['ote']; $model_img = $model_arr['img']; $op = 'modify'; } else { $model_ota = new OperaTouristAgent(); $model_otc = new OperaTouristCommon(); $model_ote = new OperaTouristExtra(); $op = 'add'; } $result = false; //照片路径; // $path = Yii::getAlias("@webroot") . Yii::$app->params['tourist_img_url']; $path = Yii::$app->basePath . '/web' . Yii::$app->params['tourist_img_url']; if (!is_dir($path)) { mkdir($path, 0777); } // $path = Yii::$app->basePath . '/web' . Yii::$app->params['tourist_img_url']; if ( $model_otc->load(Yii::$app->request->post()) && $model_ote->load(Yii::$app->request->post()) // && Model::validateMultiple([$model_otc, $model_ote]) ) { $transaction = Yii::$app->db->beginTransaction(); try { //赋予默认值 $model_ote->create_time = $model_ota->create_time = $model_otc->create_time = date('Y-m-d H:i:s'); $model_ote->update_time = $model_ota->update_time = $model_otc->update_time = date('Y-m-d H:i:s'); $model_ote->create_user_id = $model_ota->create_user_id = $model_otc->create_user_id = $user_id; $model_ote->update_user_id = $model_ota->update_user_id = $model_otc->update_user_id = $user_id; //处理common表照片 $common_pic_file = UploadedFile::getInstance($model_otc, 'top_image_url'); if ($common_pic_file && $common_pic_file != null) { $name_before = $common_pic_name = time(); $common_pic_name = $common_pic_name . "." . $common_pic_file->getExtension(); $model_otc->top_image_url = Yii::$app->params['tourist_img_url'] . $common_pic_name; if ($common_pic_file->saveAs($path . $common_pic_name) !== true) { throw new \Exception(); }; //处理缩略图 //获取照片长宽 $imgstream = file_get_contents($path . $common_pic_name); $im = imagecreatefromstring($imgstream); $x = imagesx($im);//获取图片的宽 $y = imagesy($im);//获取图片的高 if ($x > $y) { //图片宽大于高 $sx = abs(($y - $x) / 2); $sy = 0; } else { //图片高大于等于宽 $sy = abs(($x - $y) / 2.5); $sx = 0; } //裁剪 $img_big_url = "@backend/web/" . Yii::$app->params['tourist_img_url'] . "$common_pic_name"; $image=new Image(); $image1=clone $image; $image1::crop($img_big_url, $x>=300?300:$x, $y>=300?300:$y, [$sx, $sy]) ->resize(new Box(300,300)) ->save(Yii::getAlias("@backend/web/" . Yii::$app->params['tourist_img_url'] . "$name_before.{$common_pic_file->getExtension()}.min.{$common_pic_file->getExtension()}"), ['quality' => 100]); // $res = BaseTourist::cutPic("@backend/web" . Yii::$app->params['tourist_img_url'] . "$common_pic_name", "@backend/web" . Yii::$app->params['tourist_img_url']); $image2=clone $image; $image2::crop($img_big_url, $x>=370?370:$x, $y>=326?326:$y, [$sx, $sy]) ->resize(new Box(370,326)) ->save(Yii::getAlias("@backend/web/" . Yii::$app->params['tourist_img_url'] . "$name_before.{$common_pic_file->getExtension()}.370x326.{$common_pic_file->getExtension()}"), ['quality' => 100]); $model_otc->list_image_url = Yii::$app->params['tourist_img_url'] . "$name_before.{$common_pic_file->getExtension()}.min.{$common_pic_file->getExtension()}"; } //common表保存 if (!$model_otc->save(false)) { throw new \Exception('保存失败.' . $model_otc::getModelError($model_otc)); } //如果是修改 那么修改行程天数会需要修改detail表 // if ($op == 'update') { // //天数影响车票和门票 //晚数影响酒店 // $update_info = ['cancel_flag' => 1]; // $update_day_where = ['and', ['>=', 'day_from_start', $model_otc->day_num], ['in', 'res_type', [1, 3]]]; // $update_night_where = ['and', ['>=', 'day_from_start', $model_otc->night_num], ['in', 'res_type', [2]]]; // OperaTouristDetail::updateAll($update_info, $update_day_where); // OperaTouristDetail::updateAll($update_info, $update_night_where); // } //处理img表照片 for ($i = 0; $i < count($_FILES['OperaTouristImg']['name']); $i++) { // $img_file = UploadedFile::getInstance($model_img[$i], 'image_url'); $img_url = $_FILES['OperaTouristImg']['name'][$i]['image_url']; $img_oned = isset($_POST['OperaTouristImg'][$i]['image_url']) ? $_POST['OperaTouristImg'][$i]['image_url'] : ''; if ($img_url != null && $img_oned == '') { if (isset($_POST['OperaTouristImg'][$i]['image_name']) & !empty($_POST['OperaTouristImg'][$i]['image_name'])) { $model_img[$i] = OperaTouristImg::findOne(['image_name' => $_POST['OperaTouristImg'][$i]['image_name']]); } else { $model_img[$i] = new OperaTouristImg(); } $img_file = UploadedFile::getInstance($model_img[$i], "[$i]image_url"); $name = date("Y") . date("m") . date("d") . date("H") . date("i") . date("s") . rand(100, 999) . " . " . $img_file->getExtension(); if ($img_file->saveAs($path . $name) === true) { $model_img[$i]->image_url = Yii::$app->params['tourist_img_url']; $model_img[$i]->image_name = $name; $model_img[$i]->tourist_id = $model_otc->tourist_id; $model_img[$i]->create_time = date('Y-m-d H:i:s'); $model_img[$i]->update_time = date('Y-m-d H:i:s'); $model_img[$i]->create_user_id = $user_id; $model_img[$i]->update_user_id = $user_id; } //img表保存 if (!$model_img[$i]->save(false)) { throw new \Exception('保存失败.' . $model_img[$i]::getModelError($model_img[$i])); } } } //已验证 故直接保存 $model_ota->tourist_id = $model_ote->tourist_id = $model_otc->tourist_id; //extra表保存 if (!$model_ote->save(false)) { throw new \Exception(); } //agent表保存 if (!$model_ota->save(false)) { throw new \Exception(); } //ctrip表单独处理 if($tourist_id=='add'){ //如果添加,不填携程订单号,ctrip不插数据 if(!empty($ott['ctrip_prod_id'])){ $model_ott = new OperaTouristCtrip(); $model_ott->create_time = date('Y-m-d H:i:s'); $model_ott->update_time = date('Y-m-d H:i:s'); $model_ott->create_user = $user_id; $model_ott->update_user = $user_id; $model_ott->sp_tourist_id = $model_otc->tourist_id; $model_ott->ctrip_prod_id = $ott['ctrip_prod_id']; if(!$model_ott->save(false)){ throw new \Exception(); } } }else{ //如果修改,原来没有关联数据的ctrip添加数据 if(empty($model_arr['ott'])){ if(!empty($ott['ctrip_prod_id'])){ $model_ott = new OperaTouristCtrip(); $model_ott->create_time = date('Y-m-d H:i:s'); $model_ott->update_time = date('Y-m-d H:i:s'); $model_ott->create_user = $user_id; $model_ott->update_user = $user_id; $model_ott->sp_tourist_id = $model_otc->tourist_id; $model_ott->ctrip_prod_id = $ott['ctrip_prod_id']; if(!$model_ott->save(false)){ throw new \Exception(); } } }else{ $model_ott = $model_arr['ott']; $model_ott->update_time = date('Y-m-d H:i:s'); $model_ott->update_user = $user_id; if(empty($ott['ctrip_prod_id'])){ $model_ott->cancel_flag = 1; $model_ott->ctrip_prod_id = 0; }else{ $model_ott->ctrip_prod_id = $ott['ctrip_prod_id']; } if(!$model_ott->save(false)){ throw new \Exception(); } } } $result = true; //提交 $transaction->commit(); } catch (Exception $e) { $result = false; $transaction->rollBack(); } } if ($result) { if ($op == 'add') $url = '/zzcs/tourist/add-combination-res'; elseif ($op == 'modify') $url = '/zzcs/tourist/upt-combination-res'; $this->redirect(Yii::$app->getUrlManager()->createUrl([$url, 'tourist_id' => $model_otc->tourist_id])); //$this->redirect(Yii::$app->getUrlManager()->createUrl('/zzcs/tourist/list')); Yii::$app->session->setFlash('success', '保存成功!'); } else { $this->redirect(Yii::$app->getUrlManager()->createUrl('/zzcs/tourist/index')); Yii::$app->session->setFlash('error', '保存失败!请联系管理员'); } } /** * @param int $tourist_id * * @return string * * 修改产品页面和数据加载 */ public function actionUpdate($tourist_id=0) { if($tourist_id==0){ $tourist_id = Yii::$app->request->get('tourist_id','0'); } $model_arr = $this->findModel($tourist_id); $data['view'] = 'index'; $data['op'] = 'modify'; $data['tourist_id'] = $tourist_id; $model_ota = $model_arr['ota']; $model_otc = $model_arr['otc']; $model_ote = $model_arr['ote']; if(!empty($model_arr['ott'])){ $model_ott = $model_arr['ott']; }else{ $model_ott = new OperaTouristCtrip(); } if (count($model_arr['img']) > 0) $model_img = $model_arr['img']; else $model_img[0] = new OperaTouristImg(); $data['area'] = BaseTourist::getArea(Yii::$app->request->get('area_id')); return $this->render('_base', ['data' => $data, 'model_ota' => $model_ota, 'model_otc' => $model_otc, 'model_ote' => $model_ote,'model_ott'=>$model_ott,'model_img' => $model_img]); } /** * Function Description:数据拷贝 * Function Name: actionClone * * @return int * @throws Exception * @throws \Exception * * @author 冒炎 */ public function actionClone(){ $tourist_id = Yii::$app->request->post('tourist_id'); $common = new OperaTouristCommon(); $agent = new OperaTouristAgent(); $extra = new OperaTouristExtra(); $img = new OperaTouristImg(); $detail = new OperaTouristDetail(); $ctrip = new OperaTouristCtrip(); $cookies = Yii::$app->request->cookies; $user_id = $cookies->getValue('user_id', 1); $time = date('Y-m-d H:i:s'); $transaction = Yii::$app->db->beginTransaction(); try{ //common表数据复制 $last_tourist_id = $common->commonClone($tourist_id,$user_id,$time); if(!$last_tourist_id){ throw new \Exception(); } //agent表数据复制 $agent_clone_res = $agent->agentClone($tourist_id,$user_id,$time,$last_tourist_id); if(!$agent_clone_res){ throw new \Exception(); } //extra表数据复制 $extra_clone_res = $extra->extraClone($tourist_id,$user_id,$time,$last_tourist_id); if(!$extra_clone_res){ throw new \Exception(); } //img 表数据复制 $img_clone_res = $img->imgClone($tourist_id,$user_id,$time,$last_tourist_id); if(!$img_clone_res){ throw new \Exception(); } //detail 表数据复制 $detal_clone_res = $detail->detailClone($tourist_id,$user_id,$time,$last_tourist_id); if(!$detal_clone_res){ throw new \Exception(); } //ctrip表数据复制 // $ctrip_clone_res = $ctrip->ctripClone($tourist_id,$user_id,$time,$last_tourist_id); // if(!$ctrip_clone_res){ // throw new \Exception(); // } $transaction->commit(); return 0; }catch (Exception $e){ $transaction->rollBack(); return 1; } } /** * @return string * 组合产品列表 */ public function actionList() { $model = new OperaTouristAgent(); $filter = ['product_name' => '', 'tourist_code' => '', 'start_area_name' => '', 'is_onsale' => '']; if (Yii::$app->request->isAjax) { $filter = Yii::$app->request->get(); } $dataProvider = $model->getListInfo($filter); $data['view'] = 'list'; return $this->render('_base', ['data' => $data, 'dataProvider' => $dataProvider]); } /** * 行程说明入口 */ public function actionUeditor($tourist_id) { $model = OperaTouristCommon::findOne(['tourist_id' => $tourist_id]); $data['view'] = 'ueditor'; $data['tourist_id'] = $tourist_id; return $this->render('_base', ['data' => $data, 'model' => $model]); } public function actionSaveUeditor() { $data = Yii::$app->request->post('OperaTouristCommon'); $update_info = ['tourist_description' => $data['tourist_description']]; $update_where = ['tourist_id' => $data['tourist_id']]; $res = OperaTouristCommon::updateAll($update_info, $update_where); if (!$res) { $this->redirect(Yii::$app->getUrlManager()->createUrl('/zzcs/tourist/list')); Yii::$app->session->setFlash('error', '保存失败!请联系管理员'); } else { $this->redirect(Yii::$app->getUrlManager()->createUrl('/zzcs/tourist/list')); Yii::$app->session->setFlash('success', '保存成功!'); } } /** * 修改产品状态 */ public function actionModify() { $post = Yii::$app->request->post(); if (isset($post['id']) && isset($post['op'])) { $model = new OperaTouristAgent(); $data = $model->isOnSaleControl($post['id'], $post['op']); } else { $data['code'] = 2; } echo json_encode($data); } /** * Function Description:批量增加修改特定票种价格日历 * Function Name: actionModifyRunInfo * * @return array * * @author 温依莅 */ public function actionModifyRunInfo() { $request = Yii::$app->request; $prod_id = $request->post('prod_id', -1); $date = $request->post('prod_date', 0); $attribute = $request->post('prod_attribute', 0); $tourist_obj = new TouristCalendar(); $res = $tourist_obj->modifyRunInfo($prod_id, $date, $attribute); return json_encode($res); } /** * Function Description:资源组合信息页 * Function Name: actionAddCombinationRes * * @return array|string * * @author 娄梦宁 */ public function actionAddCombinationRes() { $tourist_id = Yii::$app->request->get('tourist_id', ''); if ($tourist_id == '') { return [ 'code' => 1, 'info' => '参数错误' ]; } $logic = new TouristCombination(); $data['data'] = $logic->AddCombination($tourist_id); $data['view'] = 'add-combination'; $data['op'] = 'add'; $data['tourist_id'] = $tourist_id; return $this->render('_base', ['data' => $data]); } /** * Function Description:资源组合修改页数据获取 * Function Name: actionUptCombinationRes * * @return array|string * * @author 娄梦宁 */ public function actionUptCombinationRes() { $tourist_id = Yii::$app->request->get('tourist_id', ''); if ($tourist_id == '') { return [ 'code' => 1, 'info' => '参数错误' ]; } $logic = new TouristCombination(); $data['data'] = $logic->UptCombination($tourist_id); $data['view'] = 'upt-combination'; $data['op'] = 'modify'; $data['tourist_id'] = $tourist_id; return $this->render('_base', ['data' => $data]); } /** * Function Description:通过线路id取上下车站点 * Function Name: ActionGetLineDetail * * @return mixed * * @author 娄梦宁 */ public function actionGetLineDetail() { $line_id = Yii::$app->request->post('line_id', ''); $logic = new TouristCombination(); $result = $logic->GetLineDetail($line_id); return json_encode($result); } /** * Function Description:获取酒店房型信息 * Function Name: actionGetRoomType * * @return string * * @author 娄梦宁 */ public function actionGetRoomType() { $hotel_id = Yii::$app->request->post('hotel_id', ''); $logic = new TouristCombination(); $result = $logic->GetRoomType($hotel_id); return json_encode($result); } /** * Function Description:获取子门票信息 * Function Name: actionGetSonTickets * * @return string * * @author 娄梦宁 */ public function actionGetSonTickets() { $ticket_id = Yii::$app->request->post('ticket_id', ''); $logic = new TouristCombination(); $result = $logic->GetSonTickets($ticket_id); return json_encode($result); } /** * Function Description:添加资源组合信息提交 * Function Name: actionSubmitAddRes * * @return string * * @author 娄梦宁 */ public function actionSubmitAddRes() { $bus_info = Yii::$app->request->post('bus_info', ''); $hotel_info = Yii::$app->request->post('hotel_info', ''); $ticket_info = Yii::$app->request->post('ticket_info', ''); $tourist_id = Yii::$app->request->post('tourist_id', ''); $tourist_day = Yii::$app->request->post('tourist_day', ''); $tourist_night = Yii::$app->request->post('tourist_night', -1); $logic = new TouristCombination(); $result = $logic->SubmitAddRes($bus_info, $hotel_info, $ticket_info, $tourist_id, $tourist_day, $tourist_night); return json_encode($result); } /** * Function Description:资源组合修改信息提交 * Function Name: actionSubmitAddRes * * @return string * * @author 娄梦宁 */ public function actionSubmitUptRes() { $bus_info = Yii::$app->request->post('bus_info', ''); $hotel_info = Yii::$app->request->post('hotel_info', ''); $ticket_info = Yii::$app->request->post('ticket_info', ''); $tourist_id = Yii::$app->request->post('tourist_id', ''); $tourist_day = Yii::$app->request->post('tourist_day', ''); $tourist_night = Yii::$app->request->post('tourist_night', -1); $logic = new TouristCombination(); $result = $logic->SubmitUptRes($bus_info, $hotel_info, $ticket_info, $tourist_id, $tourist_day, $tourist_night); return json_encode($result); } /** * 获取价格日历 */ public function actionCalendarInfo() { $request = Yii::$app->request; $tourist_id = $request->get('tourist_id', -1); $org_id = $request->get('org_id', 0); $year = $request->get('year', 0); $month = $request->get('month', 0); $model = new TouristCalendar(); $data = $model->getCalInfo($year, $month, $org_id, $tourist_id); //取所有的符有售票权限的渠道商 $logic = new ProductManage(); $to_org_list = $logic->getAllToOrg(); $data['to_org_list'] = $to_org_list; $data['view_type'] = 2; return $this->render('set-tourist-price', $data); } /** * @return string * 操作上下架 */ public function actionRunUpDown() { $tourist_id = Yii::$app->request->post('tourist_id'); $to_org_id = Yii::$app->request->post('to_org_id'); $run_dates = Yii::$app->request->post('run_dates'); $op = Yii::$app->request->post('op'); $model = new OperaTouristRun(); $data = $model->doUpDown($tourist_id, $to_org_id, $run_dates, $op); return json_encode($data); } /** * Function Description:单个或批量修改价格日历价格 * Function Name: actionRunInfo * * @return string * @throws \Exception * * @author luocj */ public function actionRunInfo() { $tourist_id = Yii::$app->request->post('tourist_id'); $to_org_id = Yii::$app->request->post('to_org_id'); $run_dates = Yii::$app->request->post('run_dates'); $diff_para_adult = Yii::$app->request->post('diff_para_adult');//成人单人加价 $sale_type_adult = Yii::$app->request->post('sale_type_adult');//成人单人加价方式 $diff_para_child = Yii::$app->request->post('diff_para_child');//儿童单人加价 $sale_type_child = Yii::$app->request->post('sale_type_child');//儿童单人加价方式 $model = new OperaTouristRun(); $data = $model->updateInfo($tourist_id, $to_org_id, $run_dates, $diff_para_adult, $sale_type_adult,$diff_para_child,$sale_type_child); return json_encode($data); } /** * 删除自由行产品的图片 * @return string * 田玲菲 */ public function actionDeleteImg(){ $id = Yii::$app->request->post('id',0); $imageManage = new ImageManage(); $result = $imageManage->deleteTouristImg($id); return json_encode($result); } }