diff --git a/application/controllers/Webservice.php b/application/controllers/Webservice.php index c608a1b..33992eb 100644 --- a/application/controllers/Webservice.php +++ b/application/controllers/Webservice.php @@ -581,5 +581,16 @@ class Webservice extends CI_Controller { $this->errorResponse($res['code'],$res['message']); } } + + public function hotel_search(){ + $data = (array)json_decode(file_get_contents('php://input')); + $data['auth_token'] = $this->auth_token; + $res = $this->Webservice_model->hotel_search($data); + if($res['status'] == 1){ + $this->response($res['data']); + }else{ + $this->errorResponse($res['code'],$res['message']); + } + } } ?> diff --git a/application/models/Validation_app_model.php b/application/models/Validation_app_model.php index 19995f9..c0866dc 100644 --- a/application/models/Validation_app_model.php +++ b/application/models/Validation_app_model.php @@ -170,6 +170,14 @@ class Validation_app_model extends CI_Model { ) ), 'get_hotel_city_list'=>array(), + 'hotel_search'=>array( + 'auth_token' => array( + 'required' => array( + 'code' => 'ER02', + 'message' => 'User id is null or empty' + ) + ) + ) ); public function validation_check($method_name, $parms) { diff --git a/application/models/Webservice_model.php b/application/models/Webservice_model.php index 7adb3ce..74cd9de 100644 --- a/application/models/Webservice_model.php +++ b/application/models/Webservice_model.php @@ -2045,7 +2045,7 @@ class Webservice_model extends CI_Model { $user_id = $this->auth_token_get($data['auth_token']); if($user_id > 0) { $cond = ''; - if(isset($data['query']) && empty($data['query'])){ + if(isset($data['query']) && !empty($data['query'])){ $cond = "AND THC.hotel_city_name LIKE '%".$data['query']."%'"; } $sql = "SELECT HC.hotel_city_id FROM hotel_cities AS HC @@ -2061,7 +2061,7 @@ class Webservice_model extends CI_Model { $sql = "SELECT THC.hotel_city_id AS id,HC.hotel_city_icon AS image FROM translator_hotel_city AS THC INNER JOIN hotel_cities AS HC ON (HC.hotel_city_id=THC.hotel_city_id) - WHERE THC.status=1 $cond LIMIT $limit,$perPage"; + WHERE THC.status=1 $cond GROUP BY HC.hotel_city_id LIMIT $limit,$perPage"; $hotelData = $this->db->query($sql)->result_array(); $countryData = $this->getCountryData($user_id); @@ -2087,5 +2087,42 @@ class Webservice_model extends CI_Model { } return $res; } + + public function hotel_search($data){ + try{ + $user_id = $this->auth_token_get($data['auth_token']); + if($user_id > 0) { + $trackingId = time().rand(100000,999999); + $settings = getSettings(); + if(!isset($data['nextToken']) && empty($data['nextToken'])){ + $this->db->select('nationality'); + $userData = $this->db->get_where('customer',array('customer_id'=>$user_id))->row_array(); + $countryData = $this->getCountryData($user_id); + } + $url = (isset($data['nextToken']) && !empty($data['nextToken']))?"https://trawex.biz/api/hotel_trawexv5/getMoreHotels?user_id=".$settings['trawex_user_id']."&user_password=".$settings['trawex_user_password']."&access=".$settings['trawex_access']."&ip_address=".$settings['trawex_ip_address']."&sessionId=".$data['sessionId']."&nextToken=".$data['nextToken']."&trackingId=".$data['trackingId']."":"https://trawex.biz/api/hotel_trawexv5/hotel_search"; + + $postFields = (isset($data['nextToken']) && !empty($data['nextToken']))?'':json_encode(array('user_id'=>$settings['trawex_user_id'],'user_password'=>$settings['trawex_user_password'],'access'=>$settings['trawex_access'],'ip_address'=>$settings['trawex_ip_address'],'trackingId'=>$trackingId,'city_name'=>$data['city_name'],'country_name'=>(!empty($userData['nationality']))?$userData['nationality']:'','room_count'=>$data['room_count'],'adult'=>$data['adult'],'child'=>$data['child'],'child_age'=>$data['child_age'],'checkin'=>$data['checkin'],'checkout'=>$data['checkout'],'client_nationality'=>$countryData['country_code'],'requiredCurrency'=>$countryData['currency'])); + + $ch = curl_init(); + curl_setopt($ch,CURLOPT_URL,$url); + curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch,CURLOPT_POST,1); + curl_setopt($ch,CURLOPT_POSTFIELDS,$postFields); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-Type:application/json')); + $result = curl_exec($ch); + curl_close($ch); + $result = json_decode($result); + $result->status->trackingId = (!isset($data['nextToken']) && empty($data['nextToken']))?$trackingId:$data['trackingId']; + $res = array('status'=>1,'data'=>array('itineraries'=> $result)); + }else{ + $res = array('status'=>0,'message'=>'User Authentication Error','code'=>'ER10'); + } + }catch(Exception $e){ + $res = array('status'=>0,'message'=>'Ohh No!! Something Went South!!','code'=>'ER08'); + } + return $res; + } } ?>