Beispiel #1
0
 /**
  * 20 得到车辆信息 (根据pickUP ,DropOff和车辆id得到车辆信息)
  *  /index.php?r=CarrentalApi/rc/GetMatchInfoRQ
  */
 public function actionGetMatchInfoRQ()
 {
     $Redis = YiiRedis::getInstance();
     $json_params = Yii::app()->request->getParam('json_params');
     //客户端请求的json参数
     $request_time = time();
     //测试用例[S]
     $json_params_go = Yii::app()->request->getParam('go');
     if ($json_params_go == 'go') {
         $json_params = '{"PickUp":{"Location":{"id":"3541"},"Date":{"year":"2014","month":"11","day":"23","hour":"10","minute":"30"}},"DropOff":{"Location":{"id":"3541"},"Date":{"year":"2014","month":"11","day":"26","hour":"10","minute":"30"}},"remoteIp":"106.2.184.106","vehicleId":"260278021"}';
     }
     //测试用例[E]
     // 验证JSON串的正确性
     if (!empty($json_params) && IconvEncode::IsJson($json_params)) {
         $request_param = json_decode($json_params, true);
         //得到搜索数据[S]
         //生成redis key
         //$search_reasult_key=RcManager::getKeyForPickUpDropOff($request_param).'_GetMatchInfoRQ';
         // $search_reasult_key='carrental_search__getMatchInfoRQ_'.md5($json_params);
         $search_reasult_key = RcManager::MatchListKey($request_param);
         // 同一个搜索车辆的条件 ,使用相同的key
         if (!$search_reasult_key) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x200002_PickUp和DropOff的数据格式不正确'));
             exit($return_json);
         }
         if ($Redis->get($search_reasult_key)) {
             $Rs = $Redis->get($search_reasult_key);
             $Rs_array = json_decode($Rs, true);
         } else {
             $Rs = RcManager::SearchRQ($json_params);
             $Rs_array = json_decode($Rs, true);
             if ($Rs_array['status']) {
                 $Redis->set($search_reasult_key, $Rs, 60 * 30);
             }
         }
         //得到搜索数据[E]
         //处理返回数据[S]
         if (!empty($Rs_array['status']) && (bool) $Rs_array['status']) {
             $match_arr = array();
             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']['id'])) {
                         $Vehicle_id = $match['Match']['Vehicle']['@attributes']['id'];
                         //得到车辆类型编号
                         if ($Vehicle_id == trim($request_param['vehicleId'])) {
                             $match_arr = $match;
                             break;
                         }
                     }
                 }
             }
             $return_array = array('status' => true, 'data' => $match_arr);
             $return_json = json_encode($return_array);
             ApiLogManage::addRentalcars('GetMatchInfoRQ', $json_params, $Rs, $return_json, $request_time, time(), 1);
             //记录日志
             exit($return_json);
         } else {
             exit($Rs);
         }
         //处理返回数据[S]
     } else {
         $return_json = json_encode(array('status' => false, 'error_msg' => '0x200001_JSON格式不正确'));
         exit($return_json);
     }
 }