/** * 22得到热门地区的车辆信息 * /index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ&json_params={"remoteIp":"106.2.184.106"} * 强制更热门地区数据的方式 /index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ&json_params={"remoteIp":"106.2.184.106"}&updateRedis=yes * * http://brs.test.baicheng.com/index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ\&update=crontabRedis //用于强制更新数据 * http://brs.test.baicheng.com/index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ\&update=crontabShow //用于确认数据是否更新完,否则再次更新 */ public function actionGetHotAreaMatchListRQ() { /* ini_set("display_errors", "On"); error_reporting(E_ALL | E_STRICT);*/ ini_set('max_execution_time', 1000); $Redis = YiiRedis::getInstance(); $request_time = time(); $json_params = Yii::app()->request->getParam('json_params'); //客户端请求的json参数 $update = Yii::app()->request->getParam('update'); //是否强制更新redis中的查询数据 $is_updateRedis = !empty($update) && $update == "crontabRedis" ? true : false; //用于强制更新数据 如:crontab $is_show = !empty($update) && $update == "crontabShow" ? true : false; //用于确认数据是否更新完,否则再次更新 用于 crontab // 验证JSON串的正确性 if (!empty($json_params) && IconvEncode::IsJson($json_params) || $is_updateRedis || $is_show) { //remoteIp 得到客户端ip[S] $arr_params = json_decode($json_params, true); $arr_params['remoteIp'] = !empty($arr_params['remoteIp']) ? $arr_params['remoteIp'] : CARRENTALAPI_REMOTEIP; $remoteIp = $arr_params['remoteIp']; $json_params = json_encode($arr_params); if (!filter_var($remoteIp, FILTER_VALIDATE_IP)) { $return_json = json_encode(array('status' => false, 'error_msg' => '0x220002_remoteIp不是正确ip地址')); return $return_json; } //remoteIp 得到客户端ip[E] //得到搜索数据[S] //生成redis key $search_reasult_key = 'search_hor_area_' . md5($json_params); if ($Redis->get($search_reasult_key) && !$is_updateRedis && !$is_show) { $Rs = $Redis->get($search_reasult_key); exit($Rs); } //得到搜索数据[E] //得到热门地区 $sql = "SELECT a.*,b.Name as ContinentName,b.Sort AS ContinentSort FROM rentalcars_hot_city AS a INNER JOIN rentalcars_hot_continent AS b ON a.ContinentId=b.ID WHERE a.Status='1' AND b.Status='1' ORDER BY b.Sort ASC ,a.Sort ASC"; $HotArea_array = RentalcarsHotCity::model()->dbConnection->createCommand($sql)->queryAll(); $request_params = array(); $area_list_arr = array(); $key = 0; foreach ($HotArea_array as $area) { $continentSort = $area['ContinentSort']; //大洲权重 $request_date_unix = time() + 60 * 60 * 24 * 21; //21天后的车辆查询时间 //得到城市下的所有门店[S] $pickUp_params_arr = array('country' => $area['RcCountry'], 'city' => $area['RcCity']); $pickUp_params_json = json_encode($pickUp_params_arr); $pickUp_location_json = RcManager::PickUpLocationListFilter($pickUp_params_json); $pickUp_location_arr = json_decode($pickUp_location_json, true); //得到城市下的所有门店[S] $pickUp_location_id_same = false; //判断某个门店下是否找到符合条件的车型 if ($pickUp_location_arr['status'] && is_array($pickUp_location_arr['data'])) { foreach ($pickUp_location_arr['data'] as $pickUp_location_val) { //设置热门城市的条件[S] $request_params['PickUp']['Location']['country'] = $area['RcCountry']; $request_params['PickUp']['Location']['city'] = $area['RcCity']; $request_params['PickUp']['Location']['id'] = $pickUp_location_val['id']; $request_params['PickUp']['Date']['year'] = date('Y', $request_date_unix); $request_params['PickUp']['Date']['month'] = date('m', $request_date_unix); $request_params['PickUp']['Date']['day'] = date('d', $request_date_unix); $request_params['PickUp']['Date']['hour'] = "10"; $request_params['PickUp']['Date']['minute'] = "30"; $request_params['DropOff']['Location'] = $request_params['PickUp']['Location']; // $request_params['DropOff']['Date']=$request_params['PickUp']['Date']; $request_params['DropOff']['Date']['year'] = date('Y', $request_date_unix + 60 * 60 * 24 * 7); $request_params['DropOff']['Date']['month'] = date('m', $request_date_unix + 60 * 60 * 24 * 7); $request_params['DropOff']['Date']['day'] = date('d', $request_date_unix + 60 * 60 * 24 * 7); $request_params['DropOff']['Date']['hour'] = "10"; $request_params['DropOff']['Date']['minute'] = "30"; $request_params['DriverAge'] = 26; $request_params['remoteIp'] = $remoteIp; $request_json = json_encode($request_params); //设置热门城市的条件[E] //得到搜索数据[S] //生成redis key $search_reasult_key = 'search_hor_area_' . md5($request_json); if ($Redis->get($search_reasult_key) && !$is_updateRedis) { $Rs = $Redis->get($search_reasult_key); $Rs_array = json_decode($Rs, true); } else { $Rs = RcManager::SearchRQ($request_json); $Rs_array = json_decode($Rs, true); if ($Rs_array['status']) { $Redis->set($search_reasult_key, $Rs, 60 * 60 * 24); } } //得到搜索数据[E] //处理返回数据[S] $RS_boss_carRentalTapeCompany_json = RcManager::CarRentalTapeCompany(''); //要过滤的租车公司名称 if (!empty($Rs_array['status']) && (bool) $Rs_array['status']) { if (!empty($Rs_array['data']) && is_array($Rs_array['data'])) { $Rs_data_array = $Rs_array['data']; foreach ($Rs_data_array as $match) { if (!empty($match['Match']['Vehicle']['@attributes']['group'])) { $match_group = $match['Match']['Vehicle']['@attributes']['group']; //得到车辆类型编号 //过滤租车公司[S] if ($RS_boss_carRentalTapeCompany_json) { $RS_boss__carRentalTapeCompany_arr = json_decode($RS_boss_carRentalTapeCompany_json, true); if (!empty($match['Match']['Supplier']['@text'])) { $supplier_name = $match['Match']['Supplier']['@text']; if (in_array($supplier_name, $RS_boss__carRentalTapeCompany_arr)) { continue; //过滤下线的租车公司 } } } //过滤租车公司[E] if (RcManager::isVehicleType('C', $match_group)) { //过滤车辆 $area_list_arr[$continentSort][$key]['Match'] = $match['Match']; $area_list_arr[$continentSort][$key]['CityNameCn'] = $area['CityNameCn']; $area_list_arr[$continentSort][$key]['CityNameEn'] = $area['CityNameEn']; $area_list_arr[$continentSort][$key]['Search'] = $request_params; $area_list_arr[$continentSort]['ContinentName'] = $area['ContinentName']; $pickUp_location_id_same = true; $key++; break; } } } } } //处理返回数据[S] if (!$pickUp_location_id_same) { continue; } else { break; } } } } unset($Rs, $Rs_array, $Rs_data_array, $match_group, $match, $HotArea_array); $return_array = array('status' => true, 'data' => $area_list_arr); $return_json = json_encode($return_array); ApiLogManage::addRentalcars('GetHotAreaMatchListRQ', '', '', $return_json, $request_time, time(), 1); //记录日志 //设置搜索数据到redis[S] //生成redis key $search_reasult_key = 'search_hor_area_' . md5($json_params); $Redis->set($search_reasult_key, $return_json, 60 * 60 * 24); //得到搜索数据[E] exit($return_json); } else { $return_json = json_encode(array('status' => false, 'error_msg' => '0x220001_json数据格式不正确')); exit($return_json); } }