Commit e3b21539 by Jansa Jose

daily web service commit

parent 351edda3
......@@ -543,7 +543,7 @@ class Webservices extends CI_Controller {
$postData = json_decode($post, true);
$respArr = array('status'=>'error','error'=>'901','message'=>'Something went wrong.');
if(!isset($postData['phone']) || empty($postData['phone'])){
if(!isset($postData['phone']) || empty($postData['phone']) && !isset($postData['country_code']) || empty($postData['country_code'])){
$respArr = array('status'=>'0','error'=>'903','message'=>'Required Fields are empty.');
echo json_encode($respArr);exit;
}
......@@ -783,7 +783,7 @@ class Webservices extends CI_Controller {
$total = 0;
if($serviceresult['status'] == 1){
if($serviceresult['status'] == 'success'){
$total = count($serviceresult['data']);
}
......@@ -795,7 +795,7 @@ class Webservices extends CI_Controller {
$totalPages = 1;
}
if($serviceList['status'] == '1'){
if($serviceList['status'] == 'success'){
$respArr = array('status' => 'success',
'message'=>'success',
'data' => array(
......@@ -1008,7 +1008,127 @@ class Webservices extends CI_Controller {
}
public function get_booking_summary(){
header('Content-type: application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = '0';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$res = $this->Webservice_model->get_booking_summary($postData);
echo json_encode($res);exit;
}
public function get_mechanics(){
header('Content-type: application/json');
$headers = apache_request_headers();
$postData = $_GET;
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = '0';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$err = 0;
if(!isset($postData['service_id']) || empty($postData['service_id'])){
$err = 1;
$msg = 'Service Id is Required';
}
else if(!isset($postData['location']) || empty($postData['location'])){
$err = 1;
$msg = 'Location is Required';
}
else if(!isset($postData['location_lat']) || empty($postData['location_lat'])){
$err = 1;
$msg = 'Location is Required';
}
else if(!isset($postData['location_lng']) || empty($postData['location_lng'])){
$err = 1;
$msg = 'Location is Required';
}
if($err == 1){
$respArr['status'] = 'error';
$respArr['message'] = $msg;
echo json_encode($respArr);exit;
}
$currentpage = 0;
$start = 0;
$per_page = 10;
if(isset($postData['page']) && strlen(trim($postData['page']," ")) > 0 ) {
$currentpage = (int)$postData['page'];
$currentpage = $currentpage==0 ? $currentpage : $currentpage-1;
$start = $currentpage * $per_page;
}
$mechanicsListcount = $this->Webservice_model->getNearMechanics($postData,0,0);
$mechanicsList = $this->Webservice_model->getNearMechanics($postData,$start,$per_page);
$total = 0;
if($mechanicsList['status'] == 'success'){
$total = count($mechanicsListcount['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($mechanicsList['status'] == 'success'){
$respArr = array('status' => 'success',
'message'=>'success',
'data' => array(
'services' => $mechanicsList['data']
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => $currentpage+1,
'per_page' => $per_page)
);
}else{
$respArr = array('status' => 'error',
'message'=>'No data',
'data' => array(
'services' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => $currentpage+1,
'per_page' => $per_page)
);
}
echo json_encode($respArr);exit;
}
}
?>
\ No newline at end of file
?>
......@@ -281,6 +281,126 @@ class Webservice_model extends CI_Model {
}
return $respArr;
}
}
?>
\ No newline at end of file
public function get_booking_summary($postData = ''){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
if(empty($postData['booking_id'])){
$respArr['message'] = 'Booking Id is required';
return $respArr;
}
$this->db->select("customer_vehicle.car_model as vehicle_model,customer_vehicle.car_maker as vehicle_make,customer_vehicle.car_model_year as vehicle_year,customer_vehicle.vehicle_data,bookings.mileage,bookings.issues_selected,bookings.custom_issue_data");
$this->db->join('customer_vehicle','customer_vehicle.customer_veh_id = bookings.customer_veh_id');
$mech_data = $this->db->get_where('bookings',array('booking_id'=>$postData['booking_id']));
if(!empty($mech_data) && !empty($mechanic_data = $mech_data->row_array())){
$mech_veh_data = json_decode($mechanic_data['vehicle_data']);
$mechanic_data['engine_no'] = $mech_veh_data->attributes->Engine;
$mechanic_data['vehicle_trim'] = $mech_veh_data->attributes->Trim;
unset($mechanic_data['vehicle_data']);
$mechanic_data['services'] = json_decode($mechanic_data['issues_selected']);
unset($mechanic_data['issues_selected']);
$issue_data = json_decode($mechanic_data['custom_issue_data']);
$mechanic_data['optional_images'][] = ($issue_data->optionalImages)?$issue_data->optionalImages:'';
$mechanic_data['optional_video'][] = ($issue_data->optionalVideos)?$issue_data->optionalVideos:'';
$mechanic_data['booking_description'] = ($issue_data->optionlaDescription)?$issue_data->optionlaDescription:'';
unset($mechanic_data['custom_issue_data']);
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data'] = $mechanic_data;
}
return $respArr;
}
public function getNearMechanics($postData = '',$start,$per_page){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
if(empty($postData)){
return $respArr;
}
$current_lat = $postData['location_lat'];
$current_lng = $postData['location_lng'];
// $issue_cat_id = implode(',',$postData['service_id']);
$issue_cat_id = $postData['service_id'];
if($start != 0 || $per_page != 0){
$limt = "limit ".$start.",".$per_page;
}else{
$limt = "";
}
$sql = "SELECT AU.display_name,AU.profile_image,ME.*,MS.shop_name,MS.address AS shop_address,
MS.phone AS shop_phone,MS.email_id AS shop_email_id,
3956*2*ASIN(SQRT(POWER(SIN(($current_lat-ME.location_lat)*pi()/180/2),2)+
COS($current_lat*pi()/180 )*COS(ME.location_lat*pi()/180)*
POWER(SIN(($current_lng-ME.location_lng)*pi()/180/2),2) )) AS distance
FROM mechanic AS ME
INNER JOIN admin_users AS AU ON (AU.id=ME.mechanic_id)
LEFT JOIN mechanic_shop AS MS ON (MS.shop_id=ME.shop_id AND MS.status='1')
WHERE AU.status='1'
-- HAVING distance<30
".$limt;
$mechData = $this->db->query($sql);
if(empty($mechData) || empty($mechData = $mechData->result_array())){
return 0;
}
$estimate = 0;
$mechDataArr = array();
foreach($mechData AS $index => $data){
if(empty($data['start_time']) || empty($data['end_time'])){
$scheduleTiming = array('09:00 AM','10:00 AM','11:00 AM','12:00 PM','01:00 PM',
'02:00 PM','03:00 PM','04:00 PM','05:00 PM','06:00 PM');
} else {
$endTime = strtotime($data['end_time']);
$schTime = strtotime($data['start_time']);
$scheduleTiming = array();
for( ; $schTime <= ($endTime-3600) ; $schTime += 3600){
$scheduleTiming[] = date('h:i A',$schTime);
}
}
$mechanic_id = $data['mechanic_id'];
$sql = "SELECT ISS.*, IC.*, MI.*
FROM issues_category AS IC
INNER JOIN issues AS ISS ON (IC.issue_id=ISS.issue_id)
LEFT JOIN mechanic_issues AS MI ON (MI.issue_cat_id=IC.issue_cat_id AND
MI.mechanic_id='$mechanic_id' AND MI.status='1')
WHERE ISS.status='1' AND IC.status='1' AND IC.issue_cat_id IN ($issue_cat_id)";
$subIssData = $this->db->query($sql);
$sIssueData = array();
if(!empty($subIssData) && !empty($subIssData = $subIssData->result_array())){
$sIssueData = $subIssData;
}
$estimate = 0;
foreach($sIssueData AS $sIndex => $sIssue){
if(!empty($sIssue['custom_service_fee'])){
$estimate += $sIssue['custom_service_fee'];
$sIssueData[$sIndex]['service_fee'] = $sIssue['custom_service_fee'];
} else {
$estimate += $sIssue['default_service_fee'];
$sIssueData[$sIndex]['service_fee'] = $sIssue['default_service_fee'];
}
}
$mechData[$index]['estimate'] = $estimate;
$mechData[$index]['sub_issues'] = $sIssueData;
$mechData[$index]['scheduleTiming'] = $scheduleTiming;
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data'] = $mechData;
}
return $respArr;
}
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment