public function actionHotCity() { $sql = "SELECT a.*,b.Name as ContinentName FROM rentalcars_hot_city AS a INNER JOIN rentalcars_hot_continent AS b ON a.ContinentId=b.ID order by b.Sort ASC ,a.Sort ASC"; $ListHotArea = RentalcarsHotCity::model()->dbConnection->createCommand($sql)->queryAll(); $countryList = array(); $Redis = YiiRedis::getInstance(); if ($Redis->hGet('currental_area', 'countryList')) { $Rs = $Redis->hGet('currental_area', 'countryList'); } else { $Rs = RcManager::PickUpCountryListRQ(); $Rs_array = json_encode($Rs, true); if ($Rs_array['status']) { $Redis->hSet('currental_area', 'countryList', $Rs); } } if (!empty($Rs)) { $countryList = json_decode($Rs, true); } $this->render('hotCity', array('ListHotArea' => $ListHotArea, 'countryList' => $countryList['data'])); }
public static function getInstance() { if (self::$instance == null) { self::$instance = new YiiRedis(); } return self::$instance; }
/** * 根据根据条件数组 * @param $searchArea (取车,还车)条件 * @return array 返回rentalcars 数据 【数组格式】 */ public static function getSearchResultArrayForSearchArea($searchArea) { $Redis = YiiRedis::getInstance(); $search_result_array = array(); if (!empty($searchArea)) { $search = $searchArea; $array_params['PickUp']['Location']['id'] = $search['pickUp_location']; $array_params['PickUp']['Location']['country'] = $search['pickUp_country']; $array_params['PickUp']['Location']['city'] = $search['pickUp_city']; $array_params['DropOff']['Location']['id'] = $search['dropOff_location']; $array_params['DropOff']['Location']['country'] = $search['dropOff_country']; $array_params['DropOff']['Location']['city'] = $search['dropOff_city']; $pickUp_date_strtotime = strtotime($search['pickUp_date']); $pickUp_date_year = date('Y', $pickUp_date_strtotime); $pickUp_date_month = date('m', $pickUp_date_strtotime); $pickUp_date_day = date('d', $pickUp_date_strtotime); $array_params['PickUp']['Date']['year'] = $pickUp_date_year; $array_params['PickUp']['Date']['month'] = $pickUp_date_month; $array_params['PickUp']['Date']['day'] = $pickUp_date_day; $array_params['PickUp']['Date']['hour'] = $search['pickUp_hour']; $array_params['PickUp']['Date']['minute'] = $search['pickUp_minute']; $dropOff_date_strtotime = strtotime($search['dropOff_date']); $dropOff_date_year = date('Y', $dropOff_date_strtotime); $dropOff_date_month = date('m', $dropOff_date_strtotime); $dropOff_date_day = date('d', $dropOff_date_strtotime); $array_params['DropOff']['Date']['year'] = $dropOff_date_year; $array_params['DropOff']['Date']['month'] = $dropOff_date_month; $array_params['DropOff']['Date']['day'] = $dropOff_date_day; $array_params['DropOff']['Date']['hour'] = $search['dropOff_hour']; $array_params['DropOff']['Date']['minute'] = $search['dropOff_minute']; $array_params['DriverAge'] = 26; //搜素的时候年龄默认到25周岁以上 // $search_redis_key = 'carrental_search_' . md5(serialize(array_merge($array_params['PickUp'], $array_params['DropOff']))); $search_redis_key = 'carrental_search_' . md5(serialize($search)); if ($Redis->get($search_redis_key)) { $request_result_json = $Redis->get($search_redis_key, $array_params['DropOff']); } else { $json_params = array('json_params' => json_encode($array_params)); $request_url = HTTP_URL . 'index.php?r=CarrentalApi/Rc/SearchRQ'; //接口请求地址 $request_result_json = GetUrlContent::fileGetContent($json_params, $request_url, 300, 'POST'); //请求数据 if (!empty($request_result_json)) { $Redis->set($search_redis_key, $request_result_json, 60 * 60); } } $request_result_array = !empty($request_result_json) ? json_decode($request_result_json, true) : array(); $search_result_array = is_array($request_result_array) ? $request_result_array : array(); } return $search_result_array; }
/** * 搜索页面的ajax调用 */ public function actionSearchResultFilter() { $Redit = YiiRedis::getInstance(); $search_filter = Yii::app()->request->getParam('search_filter'); $search_filter_area_be64_serialize = Yii::app()->request->getParam('search_filter_area'); $search_filter_area = unserialize(base64_decode($search_filter_area_be64_serialize)); $search_reqult_html = ''; //返回过滤后的数据,并处理为页面展示方式 if (!empty($search_filter)) { //判断是否有查询条件 $search_reasult_key = 'carrental_search_' . md5(serialize($search_filter_area)); //得到存存储查询结果的redis key //得到搜索数据[S] if ($Redit->get($search_reasult_key)) { //判断redis中的数据是否已经过期 $search_result_json = $Redit->get($search_reasult_key); $search_result_array = !empty($search_result_json) ? json_decode($search_result_json, true) : array(); $search_result_array = is_array($search_result_array) ? $search_result_array : array(); } else { //如果redis数据过期,则根据search_area,重新进行搜索 if (!empty($search_filter_area)) { $search_result_array = CarrentalManage::getSearchResultArrayForSearchArea($search_filter_area); //调用数据并输出 } } //得到搜索数据[E] //将搜索结果数组转换为html展示的数据格式[S] $search_days = !empty($search_filter['search_days']) ? $search_filter['search_days'] : 0; //展示租车的天数 foreach ($search_result_array['data'] as $k => $v) { //对结果进行按条件进行过滤 if (!empty($v['Match'])) { //得到单价[S] $html_basePrice = trim($v['Match'][1]['Price']['@attributes']['basePrice']); $html_discount = trim($v['Match'][1]['Price']['@attributes']['discount']); $html_unitPrice = number_format(($html_basePrice + $html_discount) / $search_days, 2); //得到单价[E] $html_automatic = !empty($v['Match'][0]['Vehicle']['@attributes']['automatic']) ? $v['Match'][0]['Vehicle']['@attributes']['automatic'] : ''; if (!empty($search_filter['price_range']) && !CarrentalManage::isPriceRange($search_filter['price_range'], $html_unitPrice)) { continue; } //判断每天单价是否在搜索区间内 if (!empty($search_filter['automatic']) && !CarrentalManage::isAutomatic($search_filter['automatic'], $html_automatic)) { continue; } //判断车辆排档类型 $html_imgPath = !empty($v["Match"][0]["Vehicle"][2]["ImageURL"]["@text"]) ? $v["Match"][0]["Vehicle"][2]["ImageURL"]["@text"] : ""; $html_group = ''; //车型文本内容 if (!empty($v['Match'][0]['Vehicle']['@attributes']['group'])) { //得到车型 $result_group = trim($v['Match'][0]['Vehicle']['@attributes']['group']); $models = strtoupper(substr($result_group, 0, 1)); $html_group = Params::$carrental_Models[$models]; if (!empty($search_filter['vehicle_Type']) && !CarrentalManage::isVehicleType($search_filter['vehicle_Type'], $result_group)) { continue; } //判断车辆类型 } $html_seats = !empty($v['Match'][0]['Vehicle']['@attributes']['seats']) ? $v['Match'][0]['Vehicle']['@attributes']['seats'] : ''; $html_pickUp_location_locName = !empty($v['Match'][2]['Route'][0]['PickUp'][0]['Location']['@attributes']['locName']) ? $v['Match'][2]['Route'][0]['PickUp'][0]['Location']['@attributes']['locName'] : ''; $html_dropOff_location_locName = !empty($v['Match'][2]['Route'][1]['DropOff'][0]['Location']['@attributes']['locName']) ? $v['Match'][2]['Route'][1]['DropOff'][0]['Location']['@attributes']['locName'] : ''; //得到显示的html代码[S] $search_reqult_html .= ' <div style="height: 250px;margin:10px 20px 0 21px; border: solid 1px;"> <div style="width: 70%;float:left;"> <div> <img src="' . $html_imgPath . '"> </div> <div> <div>车型 ' . $html_group . ' </div> <div>' . $html_seats . '个座位。。。。</div> <div> <span>取车门店地址:' . $html_pickUp_location_locName . '</span><br/> <span>还车门店地址:' . $html_dropOff_location_locName . '</span> </div> </div> </div> <div style="width: 30%;vertical-align:middle;float:left;"> <div style="height: 110px;"> ' . $html_unitPrice . ' /日 </div> <div style="height: 60px;"> ' . $search_days . ' 天的价格 ' . ($html_basePrice + $html_discount) . '元</div> <div style="height: 80px;"><input type="button" value="预定"/></div> </div> </div> '; //得到显示的html代码[E] } } //将搜索结果数组转换为html展示的数据格式[S] } echo $search_reqult_html; }
/** * 对bos提供的特别接口 * 24对返回数据进行整理 * url:/index.php?r=CarrentalApi/rc/GetFilterSearch */ public function actionGetFilterSearch() { $json_params = Yii::app()->request->getParam('json_params'); //客户端请求的json参数 $Redis = YiiRedis::getInstance(); //测试用例[S] $json_params_go = Yii::app()->request->getParam('go'); if ($json_params_go == 'go') { // $json_params='{"PickUp":{"Location":{"country":"UK","city":"Manchester"},"Date":{"year":"2014","month":"12","day":"1","hour":"10","minute":"30"}},"DropOff":{"Location":{"country":"UK","city":"Manchester"},"Date":{"year":"2014","month":"12","day":"2","hour":"10","minute":"30"}},"DriverAge":26}'; $json_params = '{"PickUp":{"Location":{"country":"UK","city":"Manchester"},"Date":{"year":"2014","month":"12","day":"1","hour":"10","minute":"30"}},"DropOff":{"Location":{"country":"UK","city":"Manchester"},"Date":{"year":"2014","month":"12","day":"3","hour":"10","minute":"30"}},"DriverAge":26}'; $array_params = json_decode($json_params, true); $array_params['remoteIp'] = '106.2.184.106'; $json_params = json_encode($array_params); } //测试用例[E] if ($Redis->get('GetFilterSearch_' . md5($json_params))) { $Rs = $Redis->get('GetFilterSearch_' . md5($json_params)); $Rs_array = json_decode($Rs, true); } else { $Rs = RcManager::SearchRQ($json_params); $Rs_array = json_decode($Rs, true); if ($Rs_array['status']) { $Redis->set('GetFilterSearch_' . md5($json_params), $Rs); } } if ($Rs_array['status'] && !empty($Rs_array['data'])) { $Redis->set('GetFilterSearch_' . md5($json_params), $Rs); $matchList_filter = array(); //整理后的车辆列表数组 $Rs_array_data = $Rs_array['data']; foreach ($Rs_array_data as $Rs_key => $Rs_val) { if (!empty($Rs_val['Match'])) { $match = $Rs_val['Match']; $match_vehicle = $match['Vehicle']['@attributes']; $matchList_filter[$Rs_key]['CarCode'] = $match_vehicle['id']; //车辆ID $matchList_filter[$Rs_key]['Name'] = $match['Vehicle']['Name']['@text']; //车辆名称 $matchList_filter[$Rs_key]['Description'] = !empty($match['Vehicle']['Description']['@text']) ? $match['Vehicle']['Description']['@text'] : ''; //车辆描述 $matchList_filter[$Rs_key]['CompanyID'] = $match['Supplier']['@text']; //公司名称 $matchList_filter[$Rs_key]['SuppID'] = 'rentalcars'; $matchList_filter[$Rs_key]['GroupCode'] = $match_vehicle['group']; $matchList_filter[$Rs_key]['Doors'] = $match_vehicle['doors']; $matchList_filter[$Rs_key]['Seats'] = $match_vehicle['seats']; $matchList_filter[$Rs_key]['Automatic'] = $match_vehicle['automatic']; $matchList_filter[$Rs_key]['Aircon'] = $match_vehicle['aircon']; $matchList_filter[$Rs_key]['Airbag'] = $match_vehicle['airbag']; $matchList_filter[$Rs_key]['Petrol'] = $match_vehicle['petrol']; $matchList_filter[$Rs_key]['ImageURL'] = $match['Vehicle']['ImageURL']['@text']; $matchList_filter[$Rs_key]['LargeImageURL'] = $match['Vehicle']['LargeImageURL']['@text']; $matchList_filter[$Rs_key]['LogoUrl'] = $match['Supplier']['@attributes']['small_logo']; $matchList_filter[$Rs_key]['Longitude'] = $match['Supplier']['@attributes']['long']; $matchList_filter[$Rs_key]['Latitude'] = $match['Supplier']['@attributes']['lat']; } } $return_array = array('status' => true, 'data' => $matchList_filter); $return_json = json_encode($return_array); exit($return_json); } echo $Rs; }
public static function CarRentalTapeCompany($updateRedis) { $request_time = time(); $Redis = YiiRedis::getInstance(); $is_updateRedis = true; if (!empty($updateRedis)) { if ($updateRedis == 'Yes') { $is_updateRedis = false; } } if ($Redis->get('CarRentalTapeCompany') && $is_updateRedis) { $RS_boss_json = $Redis->get('CarRentalTapeCompany'); } else { $client = new SoapClient(CARRENTALAPI_BOS_URL); $bosArr = array(); $bosArr['AppKey'] = CARRENTALAPI_BOS_APPKEY; $bosArr['AppSecrete'] = CARRENTALAPI_BOS_APPSECRETE; $bosArr['Request'] = '{}'; $bos_result = $client->CarRentalTapeCompany(array('requestString' => json_encode($bosArr))); if (!empty($bos_result->CarRentalTapeCompanyResult)) { $rs_bos_arr = json_decode($bos_result->CarRentalTapeCompanyResult, true); if ($rs_bos_arr['ErrorCode'] === 0) { $RS_boss_arr = json_decode($rs_bos_arr['Response']['Response'], true); ApiLogManage::addRentalcars('CarRentalTapeCompany', json_encode($bosArr), '', json_encode($bos_result), $request_time, time(), 1); //记录日志 } } if (!empty($rs_bos_arr['ErrorMsg'])) { ApiLogManage::addRentalcars('CarRentalTapeCompany', json_encode($bosArr), '', json_encode($bos_result), $request_time, time(), 10); //记录日志 $RS_boss_arr = array(); } $RS_boss_json = json_encode($RS_boss_arr); $Redis->set('CarRentalTapeCompany', $RS_boss_json, 60 * 60 * 24 * 7); } return $RS_boss_json; }