public function init() { //编码转换 foreach ($_GET as $key => $val) { if (!IconvEncode::isUtf8($val)) { $_GET[$key] = IconvEncode::gbk2Utf8($val); } } }
/** * 增加图片类型页 */ public function ActionAddPictureCategory() { $picture_category_model = new PictureCategory(); $valid = array('无效', '有效'); //有提交表单,则保存 if (isset($_POST['PictureCategory'])) { $cat_pinyin_arr = IconvEncode::gbk2Pinyin($_POST['PictureCategory']['PictureCategoryName']); $cat_pinyin = implode("", $cat_pinyin_arr); $_POST['PictureCategory']['PictureCategoryPinyin'] = $cat_pinyin; $picture_category_model->attributes = $_POST['PictureCategory']; $picture_category_model->ParentId = empty($_POST['PictureCategory']['ParentId']) ? '0' : $_POST['PictureCategory']['ParentId']; if ($picture_category_model->save()) { Yii::app()->user->setFlash('save_pic', '添加成功'); $this->redirect(Yii::app()->createUrl('PictureCategory/ListPictureCategory')); } else { Yii::app()->user->setFlash('save_pic', '添加失败'); } } // 查询所有一级菜单 $picture_category = PictureCategory::model()->findAllByAttributes(array('ParentId' => 0)); // 跳转至添加页 $this->renderPartial('add_picture_category', array('picture_category_model' => $picture_category_model, 'picture_category' => $picture_category, 'valid' => $valid)); }
/** *18查询门店车辆列表 * @param $json_params * @return string */ public static function SearchRQ($json_params) { $request_time = time(); // 验证JSON串的正确性 if (!empty($json_params) && IconvEncode::IsJson($json_params)) { // 解析Json $request_param = json_decode($json_params, true); // 验证Json串中每一组参数的正确性 [S] if (empty($request_param['DriverAge'])) { $request_param['DriverAge'] = 26; } // 验证PickUp、DropOff、DriverAge是否存在 if (empty($request_param['PickUp']) || empty($request_param['DropOff'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180002_PickUp、DropOff、DriverAge不可为空')); return $return_json; } // DriverAge只能是大于0小于100的数字 if (!is_numeric($request_param['DriverAge']) || $request_param['DriverAge'] <= 18 || $request_param['DriverAge'] >= 75) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180003_DriverAge只能是大于18小于75的数字')); return $return_json; } // 声明简短变量 $PickUp_Location = empty($request_param['PickUp']['Location']) ? '' : $request_param['PickUp']['Location']; // PickUp.Location $DropOff_Location = empty($request_param['DropOff']['Location']) ? '' : $request_param['DropOff']['Location']; // DropOff.Location $PickUp_Date = empty($request_param['PickUp']['Date']) ? '' : $request_param['PickUp']['Date']; // PickUp.Date $DropOff_Date = empty($request_param['DropOff']['Date']) ? '' : $request_param['DropOff']['Date']; // DropOff.Date // 验证PickUp与DropOff下的 Location与Date是否存在 if (empty($PickUp_Location) || empty($PickUp_Date) || empty($DropOff_Location) || empty($DropOff_Date)) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180004_PickUp与DropOff下的 Location与Date是否存在')); return $return_json; } // Location下正确的参数名 $Location_Key = array('id', 'country', 'city'); // 验证PickUp.Location 中的参数名是否正确 foreach ($PickUp_Location as $key => $val) { if (!in_array($key, $Location_Key)) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180005_PickUp. Location 下的参数名错误')); return $return_json; } } // 验证DropOff.Location 中的参数名是否正确 foreach ($DropOff_Location as $key => $val) { if (!in_array($key, $Location_Key)) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180006_DropOff. Location 下的参数名错误')); return $return_json; } } // 验证PickUp.Location 中是否为填写任何条件 [id / country / city] if (count($PickUp_Location) == 0) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180007_PickUp. Location 下缺少必填参数')); return $return_json; } else { // 如按国家+城市的方式查询 if (empty($PickUp_Location['id'])) { // country与city不能单独使用 如填写了country或city的其中一个 另一个也必须填写 if (empty($PickUp_Location['country']) && !empty($PickUp_Location['city']) || !empty($PickUp_Location['country']) && empty($PickUp_Location['city'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180008_单独使用了PickUp.Location 下的country或city')); return $return_json; } } } // 验证DropOff.Location 中是否为填写任何条件 [id / country / city] if (count($DropOff_Location) == 0) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180009_DropOff. Location 下缺少必填参数')); return $return_json; } else { // 如按国家+城市的方式查询 if (empty($DropOff_Location['id'])) { // country与city不能单独使用 如填写了country或city的其中一个 另一个也必须填写 if (empty($DropOff_Location['country']) && !empty($DropOff_Location['city']) || !empty($DropOff_Location['country']) && empty($DropOff_Location['city'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180010_单独使用了DropOff.Location 下的country或city')); return $return_json; } } } // PickUp.Date 中的参数均为必填项 if (empty($PickUp_Date['year']) || empty($PickUp_Date['month']) || empty($PickUp_Date['day']) || empty($PickUp_Date['hour']) || empty($PickUp_Date['minute'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180011_PickUp.Date下缺少必填参数')); return $return_json; } // DropOff.Date 中的参数均为必填项 if (empty($DropOff_Date['year']) || empty($DropOff_Date['month']) || empty($DropOff_Date['day']) || empty($DropOff_Date['hour']) || empty($DropOff_Date['minute'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180012_DropOff.Date 下缺少必填参数')); return $return_json; } $start_time = strtotime($PickUp_Date['year'] . '-' . $PickUp_Date['month'] . '-' . $PickUp_Date['day'] . ' ' . $PickUp_Date['hour'] . ':' . $DropOff_Date['minute']); $end_time = strtotime($DropOff_Date['year'] . '-' . $DropOff_Date['month'] . '-' . $DropOff_Date['day'] . ' ' . $DropOff_Date['hour'] . ':' . $DropOff_Date['minute']); // 验证时间范围是否正确 [例:2014-13-38 错误时间strtotime会返回false] if ($start_time && $end_time) { // 结束时间不能小于开始时间 if ($end_time < $start_time) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180014_DropOff.Date 小于了PickUp.Date')); return $return_json; } } else { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180013_PickUp.Date或DropOff.Date不是正确的时间')); return $return_json; } // 验证Json串中每一组参数的正确性 [E] // 判断根据ID查询还是根据国家地区查询 $PickUp_Location = empty($request_param['PickUp']['Location']['id']) ? 'country="' . $request_param['PickUp']['Location']['country'] . '" city="' . $request_param['PickUp']['Location']['city'] . '"' : 'id="' . $request_param['PickUp']['Location']['id'] . '"'; $DropOff_Location = empty($request_param['DropOff']['Location']['id']) ? 'country="' . $request_param['DropOff']['Location']['country'] . '" city="' . $request_param['DropOff']['Location']['city'] . '"' : 'id="' . $request_param['DropOff']['Location']['id'] . '"'; //remoteIp 得到客户端ip $remoteIp = !empty($request_param['remoteIp']) ? $request_param['remoteIp'] : CARRENTALAPI_REMOTEIP; if (!filter_var($remoteIp, FILTER_VALIDATE_IP)) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180015_remoteIp不是正确ip地址')); return $return_json; } // 拼接XML <SearchRQ supplierInfo="true" showReviews="true" > $request_xml = ' <SearchRQ supplierInfo="true" prefcurr="USD"> <Credentials username="******" password="******" remoteIp="' . $remoteIp . '" /> <PickUp> <Location ' . $PickUp_Location . '/> <Date year="' . $request_param['PickUp']['Date']['year'] . '" month="' . $request_param['PickUp']['Date']['month'] . '" day="' . $request_param['PickUp']['Date']['day'] . '" hour="' . $request_param['PickUp']['Date']['hour'] . '" minute="' . $request_param['PickUp']['Date']['minute'] . '"/> </PickUp> <DropOff> <Location ' . $DropOff_Location . '/> <Date year="' . $request_param['DropOff']['Date']['year'] . '" month="' . $request_param['DropOff']['Date']['month'] . '" day="' . $request_param['DropOff']['Date']['day'] . '" hour="' . $request_param['DropOff']['Date']['hour'] . '" minute="' . $request_param['DropOff']['Date']['minute'] . '"/> </DropOff> <DriverAge>' . $request_param['DriverAge'] . '</DriverAge> <Tracking adcamp="example" adplat="example"/> </SearchRQ>'; // 调用接口获取数据 $request_data = array('xml' => $request_xml); $searchRQ = GetUrlContent::fileGetContent($request_data, CARRENTALAPI_URL, 100, 'POST'); // $searchRQ='<SearchRS> <MatchList> </MatchList></SearchRS>'; // ApiLogManage::addRentalcars('SearchRQ_once',$request_xml,$searchRQ,'',$request_time,time(),1);//记录日志 $simple_xml_obj = simplexml_load_string($searchRQ); if (!$simple_xml_obj) { //判断数据是否为空 $return_json = json_encode(array('status' => false, 'error_msg' => '0x180099_返回数据为空或生成xml对象数据为false')); return $return_json; } $data_arr = SimpleXML::simplexml4array($simple_xml_obj); if (!empty($data_arr['SearchRS'][0]['MatchList']) && isset($data_arr['SearchRS'][0]['MatchList'])) { $result_arr = $data_arr['SearchRS'][0]['MatchList']; if (!is_array($result_arr[0]['Match'])) { //判断是否有车辆 $return_json = json_encode(array('status' => false, 'error_msg' => '0x180099_返回数据为空或生成xml对象数据为false')); return $return_json; } } //对数据进行处理[S] $result_arr = self::filterArray($result_arr); //过滤中间层 //下载rentalcars图片到本地 /* ini_set('display_errors', 'On');// 显示所有错误 error_reporting(E_ALL);*/ foreach ($result_arr as &$match) { if (isset($match['Match'])) { //处理车辆图片[S] $oldImageURL = $match['Match']['Vehicle']['ImageURL']['@text']; $parse_oldImageURL = parse_url($oldImageURL); $newImageFile = CARRENTAL_IMAGES_PATH . $parse_oldImageURL['path']; if (!file_exists($newImageFile)) { $match['Match']['Vehicle']['ImageURL']['@text'] = HTTP_URL . GetUrlContent::GrabImage($oldImageURL, $newImageFile); } else { $match['Match']['Vehicle']['ImageURL']['@text'] = HTTP_URL . $newImageFile; } $oldLargeImageURL = $match['Match']['Vehicle']['LargeImageURL']['@text']; $parse_oldLargeImageURL = parse_url($oldLargeImageURL); $newLargeImageFile = CARRENTAL_IMAGES_PATH . $parse_oldLargeImageURL['path']; if (!file_exists($newLargeImageFile)) { $match['Match']['Vehicle']['LargeImageURL']['@text'] = HTTP_URL . GetUrlContent::GrabImage($oldLargeImageURL, $newLargeImageFile); } else { $match['Match']['Vehicle']['LargeImageURL']['@text'] = HTTP_URL . $newLargeImageFile; } //处理车辆图片[E] //处理车辆公司logo[S] $oldSmall_logo = $match['Match']['Supplier']['@attributes']['small_logo']; $parse_oldSmall_logo = parse_url($oldSmall_logo); $newSmall_logo = CARRENTAL_IMAGES_PATH . $parse_oldSmall_logo['path']; if (!file_exists($newSmall_logo)) { $match['Match']['Supplier']['@attributes']['small_logo'] = HTTP_URL . GetUrlContent::GrabImage($oldSmall_logo, $newSmall_logo); } else { $match['Match']['Supplier']['@attributes']['small_logo'] = HTTP_URL . $newSmall_logo; } //处理车辆公司logo[E] } } //对数据进行处理[E] $result = json_encode($result_arr); if (!empty($result)) { $return_json = json_encode(array('status' => true, 'data' => $result_arr)); ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 1); //记录日志 return $return_json; } else { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180099_请求超时')); ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 10); //记录日志 return $return_json; //请求超时 } } else { $return_json = json_encode(array('status' => false, 'error_msg' => '0x180001_JSON参数格式错误')); return $return_json; } }
/** * 切换日游媒体状态 * @return bool */ public function ActionAjaxChangeTripMediaValid() { $trip_id = $_POST['trip_media_id']; // 获取要修改的日游媒体ID $valid = $_POST['valid']; // 获取该日游媒体当前的状态 [0:禁用 / 1:启用] $valid = $valid == 0 ? 1 : 0; $trip_media_model = TripMedia::model(); $trip_media_info = $trip_media_model->findByPk($trip_id); // 查询更改的日游媒体信息 // 执行更新 if ($trip_media_info->updateByPk($trip_id, array('Valid' => $valid)) > 0) { // 获取所有日游 $trip = IconvEncode::ObjArrChangeArray(Trip::model()->findAll(), 'TripName'); // 添加操作日志 [S] $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' ' . ($valid == 0 ? '禁用了' : '启用了') . ' 【' . $trip[$trip_media_info['TripId']] . '】 的媒体文件'; OperationLogManage::AddOperationLog($log); // 添加日志 // 添加操作日志 [E] echo true; } else { echo false; } }
public function actionXml() { $a = '{}'; if (IconvEncode::IsJson($a)) { echo 'yes'; } else { echo 'no'; } }
/** * 27改变订单状态接口 [bos] 给前端用 * url:/index.php?r=CarrentalApi/rc/ChangeTradeStatus */ public function actionChangeTradeStatus() { $json_params = Yii::app()->request->getParam('json_params'); //客户端请求的json参数 //测试用例[S] $json_params_go = Yii::app()->request->getParam('go'); if ($json_params_go == 'go') { $array_params['UserId'] = 10078560; $array_params['OrderId'] = 543877; $array_params['Status'] = 0; $array_params['Remark'] = '在修改订单状态了'; $json_params = json_encode($array_params); } //测试用例[E] if (!empty($json_params) && IconvEncode::IsJson($json_params)) { $return_json = RcManager::ChangeTradeStatusToBoss($json_params); } else { $return_json = json_encode(array('status' => false, 'error_msg' => '0x270003_传入的json格式用误!')); } exit($return_json); }
/** * 添加文件 * 参数格式:{"FileName":"文件名.后缀名","FileClassify":"文件分类ID","FileStream":"MIME base64格式编码"} 键名区分大小写 * FileName:必填 * FileStream:必填 * FileClassify:必填 [文件分类ID必须包含在文件分类ID的枚举中] * @return string 保存成功返回[原始文件名+相对路径+接口返回状态] 失败返回[原始文件名+相对路径+状态+错误代码] * 错误代码说明:[1.JSON参数错误 / 2.文件分类ID未包含在文件分类ID的枚举中 / 3.上传了不支持的文件类型 / 4.JSON参数的键名错误或缺少必填参数 / 5.文件上传失败 / 6.文件信息保存失败 / 7.接口异常] */ public function ActionSaveFile() { $json_data = array(); // 返回的JSON数据 $json_params = Yii::app()->request->getParam('json_params'); // 获取JSON参数 $json_key = array('filename', 'filestream', 'fileclassify'); // 正确的JSON键名 try { if (!empty($json_params) && IconvEncode::IsJson($json_params)) { // 解析JSON并将键名全部转为小写 $file_data = array_change_key_case(json_decode($json_params, true)); // 验证数据正确性与完整性 foreach ($file_data as $key => $val) { $file_data[$key] = trim($val); // fileclassify必须为数字且必须包含在文件分类ID的枚举中 if ($key == 'fileclassify' && (!is_numeric($val) || !array_key_exists($file_data['fileclassify'], $this->file_classify))) { exit(json_encode(self::CreateErrorMsg(2))); // 文件分类ID未包含在文件分类ID的枚举中 } // 验证文件类型 if ($key == 'filename') { $suffix = strtolower(trim(strrchr($file_data['filename'], '.'), '.')); // 获取文件后缀名 if (!in_array($suffix, $this->file_type)) { exit(json_encode(self::CreateErrorMsg(3))); // 上传了不支持的文件类型 } } } $file_data = array_filter($file_data); // 去空格与去空值后的JSON数据数组 $num = count(array_diff(array_keys($file_data), $json_key)); // 判断JSON的键是否正确 // 验证通过 if ($num === 0) { // 生成并创建上传路径 $upload_path = in_array($file_data['fileclassify'], $this->secret_classify) ? SECRET_FILE_PATH : FILE_PATH; $folder_name = implode('', IconvEncode::gbk2Pinyin($this->file_classify[$file_data['fileclassify']])); // 生成文件分类的文件夹名称 $file_path = $upload_path . $folder_name . '/' . date('Y-m-d', time()) . '/'; DirectoryFile::dirCreate($file_path); // 检测目录是否存在 if (!file_exists($file_path)) { exit(json_encode(self::CreateErrorMsg(5))); // 文件上传失败 } // 生成文件名 格式:【文件分类_时间戳_随机数 / qianzheng_1407315015_4189.doc】 $file_new_name = $folder_name . '_' . time() . '_' . rand(100, 10000) . strrchr($file_data['filename'], '.'); // 上传文件 file_put_contents($file_path . $file_new_name, base64_decode(str_replace(' ', '+', $file_data['filestream']))); // 填充模型 $file_model = new File(); $file_model->FileNewName = $file_new_name; $file_model->FileName = $file_data['filename']; $file_model->FilePath = $file_path . $file_new_name; $file_model->FileClassify = $file_data['fileclassify']; $file_model->CreateTime = date('Y-m-d', time()); // 将文件信息保存至数据库并返回Json数据 [原始文件名.后缀名 + 相对路径] if ($file_model->save()) { $json_data['FileName'] = $file_data['filename']; $json_data['FilePath'] = str_replace('uploads/', '', $file_path) . $file_new_name; $json_data['IsError'] = 'false'; echo json_encode($json_data); } else { exit(json_encode(self::CreateErrorMsg(6))); // 文件信息保存失败 } } else { exit(json_encode(self::CreateErrorMsg(4))); // JSON参数的键名错误或缺少必填参数 } } else { exit(json_encode(self::CreateErrorMsg(1))); // JSON参数错误 } } catch (Exception $e) { exit(json_encode(self::CreateErrorMsg(7))); // 接口异常 } }
/** *保存图片页 */ public function ActionSavePicture() { //获取参数 $city_id = isset($_GET['city_id']) ? $_GET['city_id'] : ""; $create_thumbnails_pic = isset($_GET['create_thumbnails_pic']) ? $_GET['create_thumbnails_pic'] : ""; $picture_category_id = isset($_GET['picture_category_id']) ? $_GET['picture_category_id'] : ""; $picture_name = isset($_GET['picture_name']) ? $_GET['picture_name'] : ""; $picture_title = isset($_GET['picture_title']) ? $_GET['picture_title'] : ""; $picture_description = isset($_GET['picture_description']) ? $_GET['picture_description'] : ""; //解析图片名称和扩展名 $name_noext = substr($picture_name, 0, strrpos($picture_name, '.')); //名称(无扩展名) $name_ext = strrchr($picture_name, "."); //扩展名 //将图片中文名称转换为拼音 $name_noext_arr = IconvEncode::gbk2Pinyin($name_noext); $name_noext_pinyin = implode("", $name_noext_arr); //中、小图名称 $picture_middle_name = $name_noext_pinyin . "_middle" . $name_ext; //中规格图名称 $picture_samll_name = $name_noext_pinyin . "_samll" . $name_ext; //小规格图名称 //获取图片类型 $picture_category = PictureCategory::model()->findByPk($picture_category_id); if (isset($picture_category) && !empty($picture_category)) { if (isset($picture_category['PictureCategoryPinyin']) && !empty($picture_category['PictureCategoryPinyin'])) { //创建图片路径 $pic_dir_path = IMAGES_PATH . $picture_category['PictureCategoryPinyin'] . '/' . date("Y-m") . '/'; DirectoryFile::dirCreate($pic_dir_path); //大图上传 $pic_big_src = $pic_dir_path . $name_noext_pinyin . $name_ext; //上传原始图片并生产规定格式的中图和小图 file_put_contents($pic_big_src, file_get_contents('php://input')); //存放大图 //图片信息存入数据库 if (empty($picture_title)) { $picture_title = $name_noext; } $picture_model = new Picture(); $picture_model->CityId = $city_id; $picture_model->CategoryId = $picture_category_id; $picture_model->Name = $picture_name; $picture_model->Title = $picture_title; $picture_model->Description = $picture_description; $picture_model->save(); //图片中、小图片路径保存到数据库 $pic_id = $picture_model->attributes['ID']; if (isset($pic_id) && !empty($pic_id)) { $picture_source['big'] = new PictureSource(); $picture_source['big']->PicId = $pic_id; $picture_source['big']->PicSrc = $pic_big_src; $picture_source['big']->SizeType = 0; //原图 // 判断是否生成中、小图 if ($create_thumbnails_pic) { $pic_middle_src = $pic_dir_path . $picture_middle_name; $pic_small_src = $pic_dir_path . $picture_samll_name; ImageChange::imgResize($pic_big_src, $pic_middle_src, 380, 210); //生成中图 ImageChange::imgResize($pic_big_src, $pic_small_src, 180, 120); //生成小图 $picture_source['middle'] = new PictureSource(); $picture_source['middle']->PicId = $pic_id; $picture_source['middle']->PicSrc = $pic_middle_src; $picture_source['middle']->SizeType = 1; //中图 $picture_source['small'] = new PictureSource(); $picture_source['small']->PicId = $pic_id; $picture_source['small']->PicSrc = $pic_small_src; $picture_source['small']->SizeType = 2; //小图 } //事务[S] $transaction = Yii::app()->db->beginTransaction(); //开启事务 try { foreach ($picture_source as $pic_src) { if (!$pic_src->save()) { throw new Exception(); } } $transaction->commit(); //提交事务 } catch (Exception $e) { $transaction->rollBack(); //回滚事务 } //事务[S] } echo $pic_dir_path; } } }
/** * 航班查询 * @return string 成功返回航班数据 失败返回错误代码 * 错误代码说明:[1.JSON参数格式错误 / 2.JSON缺少必填参数或参数名不正确 / 3.舱位等级参数未包含在参数等级枚举中 / 4.航程查询条件列表参数缺少必填项或参数不正确 * 5.旅客查询参数缺少必填项或参数不正确 / 6.舱位等级参数未包含在舱位等级枚举中 / 7.不是正确的两字码 / 8.是否直达的参数类型错误 / 9.接口请求失败 / 10.接口异常] */ public function ActionAirFlightShopIRQ() { // $json_params = Yii::app()->request->getParam('json_params'); // 获取JSON参数 // $json_params = '{"journeyType":"RT","queryAvailableConditionList":[{"depCityName":"PEK","arrCityName":"NRT","depDate":"2014-07-28"}],"passengerType":[{"passgerIdentity":"员工","passgerNumber":"7","passgerType":"成人"}]}'; $json_params = '{"journeyType":"RT","queryAvailableConditionList":[{"depCityName":"PEK","arrCityName":"NRT","depDate":"2014-07-14"}]}'; // Json参数名枚举 $json_key = array('journeyType', 'queryAvailableConditionList', 'passengerType', 'physicalCabin', 'carrier', 'isDirectOnly', 'availableJourney'); try { if (!empty($json_params) && IconvEncode::IsJson($json_params)) { // 解析Json参数 $json_params = json_decode($json_params, true); // 验证Json参数名的正确性并过滤空格 foreach ($json_params as $key => $val) { // 验证Json参数名是否存在于枚举中 if (!in_array($key, $json_key)) { $error['ErrorType'] = 2; exit(json_encode($error)); } else { // 过滤参数中的空格 if ($key != 'queryAvailableConditionList' && $key != 'passengerType') { $json_params[$key] = trim($val); } } } //去除Json参数中的空值 $json_params = array_filter($json_params); // 验证航程类型参数 if (!empty($json_params['journeyType'])) { // 航程类型枚举 $journeyType = array('OW', 'RT', 'MS'); // 验证航程类型是否包含在航程类型枚举中 if (!in_array($json_params['journeyType'], $journeyType)) { $error['ErrorType'] = 3; exit(json_encode($error)); } } else { $error['ErrorType'] = 2; exit(json_encode($error)); } // 验证航程查询条件列表参数 if (!empty($json_params['queryAvailableConditionList']) && is_array($json_params['queryAvailableConditionList'])) { $queryAvailableConditionList = $json_params['queryAvailableConditionList'][0]; // 验证必填参数是否为空或传入了两组查询条件 if (count($json_params['queryAvailableConditionList']) > 1 || empty($queryAvailableConditionList['depCityName']) || empty($queryAvailableConditionList['arrCityName']) || empty($queryAvailableConditionList['depDate'])) { $error['ErrorType'] = 4; exit(json_encode($error)); } else { // 验证三字码格式是否正确 if (!self::CheckFormat($queryAvailableConditionList['depCityName'], 2) || !self::CheckFormat($queryAvailableConditionList['arrCityName'], 2)) { $error['ErrorType'] = 4; exit(json_encode($error)); } } } else { $error['ErrorType'] = 2; exit(json_encode($error)); } // 验证旅客查询条件列表参数 if (!empty($json_params['passengerType'])) { $passenger_type = $json_params['passengerType'][0]; // 验证必填参数是否为空或传入了两组查询条件 if (count($json_params['passengerType']) > 1 || empty($passenger_type['passgerIdentity']) || empty($passenger_type['passgerNumber']) || empty($passenger_type['passgerType'])) { $error['ErrorType'] = 5; exit(json_encode($error)); } else { if ($passenger_type['passgerNumber'] < 1 || $passenger_type['passgerNumber'] > 9) { // passgerNumber只能是1~9的正整数 $error['ErrorType'] = 5; // 旅客查询条件列表的出行人数参数错误 exit(json_encode($error)); } } } // 验证舱位等级参数 if (!empty($json_params['physicalCabin'])) { // 舱位等级枚举 $physicalCabin = array('FIRST', 'BUSINESS', 'PREMIUM_ECONOMY', 'ECONOMY', 'PREMIUM_FIRST', 'PREMIUM_BUSINESS'); // 验证舱位等级是否包含在舱位等级枚举中 if (!in_array($json_params['physicalCabin'], $physicalCabin)) { $error['ErrorType'] = 6; exit(json_encode($error)); } } // 验证航空公司参数 if (!empty($json_params['carrier'])) { // 验证两字码格式是否正确 if (!self::CheckFormat($json_params['carrier'], 1)) { $error['ErrorType'] = 7; exit(json_encode($error)); } } // 验证是否直达参数 if (!empty($json_params['isDirectOnly'])) { // 是否直达只能为bool类型 if (!is_bool($json_params['isDirectOnly'])) { $error['ErrorType'] = 8; exit(json_encode($error)); } } // 调用接口获取航班信息 $flight_data = self::GetIairData('AirFlightShopIRQ', json_encode($json_params)); // 返回信息 if ($flight_data) { echo $flight_data; } else { $error['ErrorType'] = 9; exit(json_encode($error)); } } else { $json_data['ErrorType'] = 1; exit(json_encode($json_data)); } } catch (Exception $e) { $json_data['ErrorType'] = 10; exit(json_encode($json_data)); } }
/** * 18查询租车信息 * @return String * 错误代码:[1.JSON参数格式错误 / 2.PickUp或DropOff或DriverAge 的参数名错误 / 3.DriverAge的参数错误 / 4.PickUp或DropOff下 缺少Location或Date参数 / 5.PickUp. Location 下的参数名错误 * 6.DropOff. Location 下的参数名错误 / 7.PickUp. Location 下缺少必填参数 / 8.单独使用了PickUp.Location 下的country或city / 9.DropOff. Location 下缺少必填参数 / * 10.单独使用了DropOff.Location 下的country或city / 11.PickUp.Date下缺少必填参数 / 12.DropOff.Date 下缺少必填参数 / 13.PickUp.Date或DropOff.Date不是正确的时间 / 14.DropOff.Date 小于了 PickUp.Date] */ public function actionSearchRQ() { $request_time = time(); $json_params = Yii::app()->request->getParam('json_params'); //客户端请求的json参数 // $json_params = '{"PickUp":{"Location":{"id":"1124991"},"Date":{"year":"2014","month":"12","day":"12","hour":"12","minute":"30"}},"DropOff":{"Location":{"id":"1124991"},"Date":{"year":"2014","month":"12","day":"30","hour":"12","minute":"30"}},"DriverAge":"32"}'; // 验证JSON串的正确性 if (!empty($json_params) && IconvEncode::IsJson($json_params)) { // 解析Json $request_param = json_decode($json_params, true); // 验证Json串中每一组参数的正确性 [S] // 验证PickUp、DropOff、DriverAge是否存在 if (empty($request_param['PickUp']) || empty($request_param['DropOff']) || empty($request_param['DriverAge'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '2_PickUp、DropOff、DriverAge不可为空')); exit($return_json); } // DriverAge只能是大于0小于100的数字 if (!is_numeric($request_param['DriverAge']) || $request_param['DriverAge'] <= 18 || $request_param['DriverAge'] >= 75) { $return_json = json_encode(array('status' => false, 'error_msg' => '3_DriverAge只能是大于18小于75的数字')); exit($return_json); } // 声明简短变量 $PickUp_Location = empty($request_param['PickUp']['Location']) ? '' : $request_param['PickUp']['Location']; // PickUp.Location $DropOff_Location = empty($request_param['DropOff']['Location']) ? '' : $request_param['DropOff']['Location']; // DropOff.Location $PickUp_Date = empty($request_param['PickUp']['Date']) ? '' : $request_param['PickUp']['Date']; // PickUp.Date $DropOff_Date = empty($request_param['DropOff']['Date']) ? '' : $request_param['DropOff']['Date']; // DropOff.Date // 验证PickUp与DropOff下的 Location与Date是否存在 if (empty($PickUp_Location) || empty($PickUp_Date) || empty($DropOff_Location) || empty($DropOff_Date)) { $return_json = json_encode(array('status' => false, 'error_msg' => '4_PickUp与DropOff下的 Location与Date是否存在')); exit($return_json); } // Location下正确的参数名 $Location_Key = array('id', 'country', 'city'); // 验证PickUp.Location 中的参数名是否正确 foreach ($PickUp_Location as $key => $val) { if (!in_array($key, $Location_Key)) { $return_json = json_encode(array('status' => false, 'error_msg' => '5_PickUp. Location 下的参数名错误')); exit($return_json); } } // 验证DropOff.Location 中的参数名是否正确 foreach ($DropOff_Location as $key => $val) { if (!in_array($key, $Location_Key)) { $return_json = json_encode(array('status' => false, 'error_msg' => '6_DropOff. Location 下的参数名错误')); exit($return_json); } } // 验证PickUp.Location 中是否为填写任何条件 [id / country / city] if (count($PickUp_Location) == 0) { $return_json = json_encode(array('status' => false, 'error_msg' => '7_PickUp. Location 下缺少必填参数')); exit($return_json); } else { // 如按国家+城市的方式查询 if (empty($PickUp_Location['id'])) { // country与city不能单独使用 如填写了country或city的其中一个 另一个也必须填写 if (empty($PickUp_Location['country']) && !empty($PickUp_Location['city']) || !empty($PickUp_Location['country']) && empty($PickUp_Location['city'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '8_单独使用了PickUp.Location 下的country或city')); exit($return_json); } } } // 验证DropOff.Location 中是否为填写任何条件 [id / country / city] if (count($DropOff_Location) == 0) { $return_json = json_encode(array('status' => false, 'error_msg' => '9_DropOff. Location 下缺少必填参数')); exit($return_json); } else { // 如按国家+城市的方式查询 if (empty($DropOff_Location['id'])) { // country与city不能单独使用 如填写了country或city的其中一个 另一个也必须填写 if (empty($DropOff_Location['country']) && !empty($DropOff_Location['city']) || !empty($DropOff_Location['country']) && empty($DropOff_Location['city'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '10_单独使用了DropOff.Location 下的country或city')); exit($return_json); } } } // PickUp.Date 中的参数均为必填项 if (empty($PickUp_Date['year']) || empty($PickUp_Date['month']) || empty($PickUp_Date['day']) || empty($PickUp_Date['hour']) || empty($PickUp_Date['minute'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '11_PickUp.Date下缺少必填参数')); exit($return_json); } // DropOff.Date 中的参数均为必填项 if (empty($DropOff_Date['year']) || empty($DropOff_Date['month']) || empty($DropOff_Date['day']) || empty($DropOff_Date['hour']) || empty($DropOff_Date['minute'])) { $return_json = json_encode(array('status' => false, 'error_msg' => '12_DropOff.Date 下缺少必填参数')); exit($return_json); } $start_time = strtotime($PickUp_Date['year'] . '-' . $PickUp_Date['month'] . '-' . $PickUp_Date['day'] . ' ' . $PickUp_Date['hour'] . ':' . $DropOff_Date['minute']); $end_time = strtotime($DropOff_Date['year'] . '-' . $DropOff_Date['month'] . '-' . $DropOff_Date['day'] . ' ' . $DropOff_Date['hour'] . ':' . $DropOff_Date['minute']); // 验证时间范围是否正确 [例:2014-13-38 错误时间strtotime会返回false] if ($start_time && $end_time) { // 结束时间不能小于开始时间 if ($end_time < $start_time) { $return_json = json_encode(array('status' => false, 'error_msg' => '14_DropOff.Date 小于了PickUp.Date')); exit($return_json); } } else { $return_json = json_encode(array('status' => false, 'error_msg' => '13_PickUp.Date或DropOff.Date不是正确的时间')); exit($return_json); } // 验证Json串中每一组参数的正确性 [E] // 判断根据ID查询还是根据国家地区查询 $PickUp_Location = empty($request_param['PickUp']['Location']['id']) ? 'country="' . $request_param['PickUp']['Location']['country'] . '" city="' . $request_param['PickUp']['Location']['city'] . '"' : 'id="' . $request_param['PickUp']['Location']['id'] . '"'; $DropOff_Location = empty($request_param['DropOff']['Location']['id']) ? 'country="' . $request_param['DropOff']['Location']['country'] . '" city="' . $request_param['DropOff']['Location']['city'] . '"' : 'id="' . $request_param['DropOff']['Location']['id'] . '"'; // 拼接XML $request_xml = ' <SearchRQ> <Credentials username="******" password="******" remoteIp="' . CARRENTALAPI_REMOTEIP . '" /> <PickUp> <Location ' . $PickUp_Location . '/> <Date year="' . $request_param['PickUp']['Date']['year'] . '" month="' . $request_param['PickUp']['Date']['month'] . '" day="' . $request_param['PickUp']['Date']['day'] . '" hour="' . $request_param['PickUp']['Date']['hour'] . '" minute="' . $request_param['PickUp']['Date']['minute'] . '"/> </PickUp> <DropOff> <Location ' . $DropOff_Location . '/> <Date year="' . $request_param['DropOff']['Date']['year'] . '" month="' . $request_param['DropOff']['Date']['month'] . '" day="' . $request_param['DropOff']['Date']['day'] . '" hour="' . $request_param['DropOff']['Date']['hour'] . '" minute="' . $request_param['DropOff']['Date']['minute'] . '"/> </DropOff> <DriverAge>' . $request_param['DriverAge'] . '</DriverAge> <Tracking adcamp="example" adplat="example"/> </SearchRQ>'; // 调用接口获取数据 $request_data = array('xml' => $request_xml); $searchRQ = GetUrlContent::fileGetContent($request_data, CARRENTALAPI_URL, 30, 'POST'); $simple_xml_obj = simplexml_load_string($searchRQ); $data_arr = SimpleXML::simplexml4array($simple_xml_obj); if (!empty($data_arr['SearchRS'][0]['MatchList']) && isset($data_arr['SearchRS'][0]['MatchList'])) { $result_arr = $data_arr['SearchRS'][0]['MatchList']; } $result = json_encode($result_arr); if (!empty($result)) { $return_json = json_encode(array('status' => true, 'data' => $result_arr)); ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 1); //记录日志 echo $return_json; exit; } else { $return_json = json_encode(array('status' => false, 'error_msg' => '5_请求超时')); ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 10); //记录日志 exit($return_json); //请求超时 } } else { $return_json = json_encode(array('status' => false, 'error_msg' => '1_JSON参数格式错误')); exit($return_json); } }
/** * 添加酒店图片 */ public function ActionAddHotelPic() { $isPost = Yii::app()->request->isPostRequest; if (empty($isPost)) { // 获取酒店ID $hotel_id = intval(trim(Yii::app()->request->getParam('hotel_id'))); // 根据酒店ID 获取酒店数据 if (!empty($hotel_id)) { $hotel_model = Hotel::model()->findByPk($hotel_id); $this->render('add_hotel_picture', array('hotel_model' => $hotel_model)); } else { Yii::app()->user->setFlash('参数错误,请刷新后重试'); } } else { // 生成图的名称(大,中,小图)[S] $picture_name = isset($_GET['picture_name']) ? $_GET['picture_name'] : ""; $picture_title = isset($_GET['picture_title']) ? $_GET['picture_title'] : ""; $picture_desc = isset($_GET['picture_description']) ? $_GET['picture_description'] : ""; // 解析图片名称和扩展名 $name_noext = substr($picture_name, 0, strrpos($picture_name, '.')); //名称(无扩展名) $name_ext = strrchr($picture_name, "."); //扩展名 $name_rand = md5(time() . mt_rand(1, 1000000)); // 将图片中文名称转换为拼音 $name_noext_arr = IconvEncode::gbk2Pinyin($name_noext); $name_noext_pinyin = implode("", $name_noext_arr) . $name_rand; // 中、小图名称 $picture_middle_name = $name_noext_pinyin . "_middle" . $name_ext; //中规格图名称 $picture_samll_name = $name_noext_pinyin . "_samll" . $name_ext; //小规格图名称 // 生成图的名称(大,中,小图)[E] $hotel_id = Yii::app()->request->getParam('hotel_id'); // 酒店ID $hotel_count = Hotel::model()->count('ID=:id', array(':id' => $hotel_id)); if ($hotel_count > 0) { // 判断该酒店是否存在 // 创建图片路径 $pic_dir_path = IMAGES_PATH . 'hotel' . '/' . date("Y-m") . '/'; DirectoryFile::dirCreate($pic_dir_path); // 大、中、小图上传 $pic_big_src = $pic_dir_path . $name_noext_pinyin . $name_ext; $pic_middle_src = $pic_dir_path . $picture_middle_name; $pic_small_src = $pic_dir_path . $picture_samll_name; // 上传原始图片并生产规定格式的中图和小图 file_put_contents($pic_big_src, file_get_contents('php://input')); // 存放大图 ImageChange::imgResize($pic_big_src, $pic_middle_src, 380, 210); // 生成中图 ImageChange::imgResize($pic_big_src, $pic_small_src, 180, 120); // 生成小图 // 图片信息存入数据库 if (empty($picture_title)) { $picture_title = $name_noext; } // 图片路径保存到数据库 $HotelPicture['big'] = new HotelPicture(); $HotelPicture['big']->PicSrc = $pic_big_src; $HotelPicture['big']->PicTitle = $picture_title; $HotelPicture['big']->PicDes = $picture_desc; $HotelPicture['big']->Hotel_Id = $hotel_id; $HotelPicture['big']->SizeType = 0; $HotelPicture['middle'] = new HotelPicture(); $HotelPicture['middle']->PicSrc = $pic_middle_src; $HotelPicture['middle']->PicTitle = $picture_title; $HotelPicture['middle']->PicDes = $picture_desc; $HotelPicture['middle']->Hotel_Id = $hotel_id; $HotelPicture['middle']->SizeType = 1; $HotelPicture['small'] = new HotelPicture(); $HotelPicture['small']->PicSrc = $pic_small_src; $HotelPicture['small']->PicTitle = $picture_title; $HotelPicture['small']->PicDes = $picture_desc; $HotelPicture['small']->Hotel_Id = $hotel_id; $HotelPicture['small']->SizeType = 2; //事务[S] $transaction = Yii::app()->db->beginTransaction(); //开启事务 try { foreach ($HotelPicture as $pic_src) { if (!$pic_src->save()) { throw new Exception(); } } $transaction->commit(); //提交事务 } catch (Exception $e) { $transaction->rollBack(); //回滚事务 } //事务[E] echo $pic_dir_path; } } }
/** * 查看购物中心 * @param $shopping_mall_id 购物中心ID */ public function ActionViewShoppingMall($shopping_mall_id) { $shopping_mall_model = ShoppingMall::model(); $shopping_mall_info = $shopping_mall_model->findByPk($shopping_mall_id); // 获取全部品牌 $brand_criteria = new CDbCriteria(); $brand_criteria->select = array('Id', 'BrandName'); $brand = IconvEncode::ObjArrChangeArray(Brand::model()->findAll($brand_criteria), 'BrandName'); // 获取全部餐厅 $restaurant_criteria = new CDbCriteria(); $restaurant_criteria->select = array('Id', 'RestaurantName'); $restaurant = IconvEncode::ObjArrChangeArray(Restaurant::model()->findAll($restaurant_criteria), 'RestaurantName'); // 获取全部优惠卡/券 $discount_criteria = new CDbCriteria(); $discount_criteria->select = array('Id', 'DiscountCardName'); $discount_card = IconvEncode::ObjArrChangeArray(DiscountCard::model()->findAll($discount_criteria), 'DiscountCardName'); // 获取购物中心所在的的 大洲/国家/城市 $area = AreaManage::getAreaByCityid($shopping_mall_info['CityId']); $this->renderPartial('view_shopping_mall', array('shopping_mall_info' => $shopping_mall_info, 'brand' => $brand, 'restaurant' => $restaurant, 'discount_card' => $discount_card, 'area' => $area)); }
/** * 切换购物中心媒体状态 * @return bool */ public function ActionAjaxChangeShoppingMallMediaValid() { $shopping_mall_id = $_POST['shopping_mall_media_id']; // 获取要修改的购物中心媒体ID $valid = $_POST['valid']; // 获取该购物中心媒体当前的状态 [0:禁用 / 1:启用] $valid = $valid == 0 ? 1 : 0; $shopping_mall_media_model = ShoppingMallMedia::model(); $shopping_mall_media_info = $shopping_mall_media_model->findByPk($shopping_mall_id); // 查询更改的购物中心媒体信息 // 执行更新 if ($shopping_mall_media_info->updateByPk($shopping_mall_id, array('Valid' => $valid)) > 0) { // 获取所有购物中心 $shopping_mall = IconvEncode::ObjArrChangeArray(ShoppingMall::model()->findAll(), 'Name_Cn'); // 添加操作日志 [S] $log = Yii::app()->user->name . '于 ' . date('Y-m-d H:i:s', time()) . ' ' . ($valid == 0 ? '禁用了' : '启用了') . ' 【' . $shopping_mall[$shopping_mall_media_info['ShoppingMallId']] . '】 的媒体文件'; OperationLogManage::AddOperationLog($log); // 添加日志 // 添加操作日志 [E] echo true; } else { echo false; } }