Commit 78e94c4e by Jansa Jose

dc

parent 1a3f5be7
...@@ -209,7 +209,6 @@ ...@@ -209,7 +209,6 @@
$post = file_get_contents("php://input"); $post = file_get_contents("php://input");
$postData = json_decode($post, true); $postData = json_decode($post, true);
$this->load->model('Mechanic_model'); $this->load->model('Mechanic_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.'); $respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['pickup_data']) || !isset($postData['sub_issues']) || if(empty($postData) || !isset($postData['pickup_data']) || !isset($postData['sub_issues']) ||
...@@ -473,11 +472,12 @@ ...@@ -473,11 +472,12 @@
$vehicle_data['car_loc_lat'] = $locationData['location_lat']; $vehicle_data['car_loc_lat'] = $locationData['location_lat'];
$vehicle_data['car_loc_lng'] = $locationData['location_lng']; $vehicle_data['car_loc_lng'] = $locationData['location_lng'];
$vehicle_data['car_location'] = $locationData['location']; $vehicle_data['car_location'] = $locationData['location'];
$this->load->model('Settings_model'); $this->load->model('Settings_model');
$settings = $this->Settings_model->settings_viewing(); $settings = $this->Settings_model->settings_viewing();
$searchData = $postData['vehicleData']; $searchData = $postData['vehicleData'];
if($searchType == 1 && if($searchType == 1 &&
isset($searchData['car_maker']) && !empty($searchData['car_maker']) && isset($searchData['car_maker']) && !empty($searchData['car_maker']) &&
isset($searchData['modelName']) && !empty($searchData['modelName']) && isset($searchData['modelName']) && !empty($searchData['modelName']) &&
...@@ -1267,6 +1267,28 @@ ...@@ -1267,6 +1267,28 @@
$getServices = $this->Webservice_model->get_service($postData); $getServices = $this->Webservice_model->get_service($postData);
echo json_encode($getServices);exit; echo json_encode($getServices);exit;
} }
public function rate_mechanic(){
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'] = 'error';
$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;
}
$postData['customer_id'] = $authRes['data'];
$result = $this->Webservice_model->rate_mechanic($postData);
echo json_encode($result);exit;
}
} }
?> ?>
...@@ -14,19 +14,21 @@ class Booking_model extends CI_Model { ...@@ -14,19 +14,21 @@ class Booking_model extends CI_Model {
!isset($postData['selected_issues']) || empty($postData['selected_issues'])){ !isset($postData['selected_issues']) || empty($postData['selected_issues'])){
return 0; return 0;
} }
$vehData = $postData['vechile_info']; $vehData = $postData['vechile_info'];
$car_name = $vehData['modelYear'].' '.$vehData['maker'].' '.$vehData['modelName']; $car_name = $vehData['modelYear'].' '.$vehData['maker'].' '.$vehData['modelName'];
$vehJson = array('vehicle' => $car_name, $vehJson = array('vehicle' => $car_name,'attributes' =>
'attributes' => array('Year' => $vehData['modelYear'],
array('Year' => $vehData['modelYear'], 'Make' => $vehData['maker'],
'Make' => $vehData['maker'], 'Trim' => $vehData['trim'],
'Trim' => $vehData['trim'], 'Model' => $vehData['modelName'],
'Model' => $vehData['modelName'], 'Engine' => $vehData['emgine']));
'Engine' => $vehData['emgine'])); if(isset($vehData['lastMaintanceDate']) && !empty($vehData['lastMaintanceDate'])){
$last_date = $vehData['lastMaintanceDate'];
$insert_array = array('customer_id' => $postData['customer_id'], }else{
$last_date ='';
}
$insert_array = array('customer_id' => $postData['customer_id'],
'car_name' => $car_name, 'car_name' => $car_name,
'car_model' => $vehData['modelName'], 'car_model' => $vehData['modelName'],
'car_maker' => $vehData['maker'], 'car_maker' => $vehData['maker'],
...@@ -35,21 +37,22 @@ class Booking_model extends CI_Model { ...@@ -35,21 +37,22 @@ class Booking_model extends CI_Model {
'car_location' => $postData['pickup_data']['pickup_loc'], 'car_location' => $postData['pickup_data']['pickup_loc'],
'vehicle_data' => json_encode($vehJson), 'vehicle_data' => json_encode($vehJson),
'car_model_year'=> $vehData['modelYear'], 'car_model_year'=> $vehData['modelYear'],
'last_maintenance_date'=>$last_date,
'status' => '3'); 'status' => '3');
$selected_issues = array(); $selected_issues = array();
foreach($postData['selected_issues'] AS $selIssue){ foreach($postData['selected_issues'] AS $selIssue){
$selected_issues[] = array('issue' =>$selIssue['issue'], $selected_issues[] = array('issue' => $selIssue['issue'],
'issue_id' =>$selIssue['issue_id'], 'issue_id' => $selIssue['issue_id'],
'sub_issue_id' =>$selIssue['sub_issue_id'], 'sub_issue_id' => $selIssue['sub_issue_id'],
'issue_category' =>$selIssue['issue_category']); 'issue_category' => $selIssue['issue_category']);
} }
if($this->db->insert('customer_vehicle',$insert_array)){ if($this->db->insert('customer_vehicle',$insert_array)){
$last_id = $this->db->insert_id(); $last_id = $this->db->insert_id();
$book_data = array('cost' => $postData['cost'], $book_data = array('cost' => $postData['cost'],
'mileage' => $vehData['milage'], 'mileage' => $vehData['milage'],
'customer_id' => $postData['customer_id'], 'customer_id' => $postData['customer_id'],
'mechanic_id' => $postData['mechanic_id'], 'mechanic_id' => $postData['mechanic_id'],
......
...@@ -150,6 +150,7 @@ class Mechanic_model extends CI_Model { ...@@ -150,6 +150,7 @@ class Mechanic_model extends CI_Model {
POWER(SIN(($current_lng-ME.location_lng)*pi()/180/2),2) )) AS distance POWER(SIN(($current_lng-ME.location_lng)*pi()/180/2),2) )) AS distance
FROM mechanic AS ME FROM mechanic AS ME
INNER JOIN admin_users AS AU ON (AU.id=ME.mechanic_id) INNER JOIN admin_users AS AU ON (AU.id=ME.mechanic_id)
LEFT JOIN mechanic_rating AS MR ON (MR.mechanic_id=ME.mechanic_id)
LEFT JOIN mechanic_shop AS MS ON (MS.shop_id=ME.shop_id AND MS.status='1') LEFT JOIN mechanic_shop AS MS ON (MS.shop_id=ME.shop_id AND MS.status='1')
WHERE AU.status='1' WHERE AU.status='1'
-- HAVING distance<30"; -- HAVING distance<30";
...@@ -162,6 +163,7 @@ class Mechanic_model extends CI_Model { ...@@ -162,6 +163,7 @@ class Mechanic_model extends CI_Model {
$estimate = 0; $estimate = 0;
$mechDataArr = array(); $mechDataArr = array();
foreach($mechData AS $index => $data){ foreach($mechData AS $index => $data){
$data['distance'] = (int)$data['distance'];
if(empty($data['start_time']) || empty($data['end_time'])){ 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', $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'); '02:00 PM','03:00 PM','04:00 PM','05:00 PM','06:00 PM');
...@@ -175,6 +177,11 @@ class Mechanic_model extends CI_Model { ...@@ -175,6 +177,11 @@ class Mechanic_model extends CI_Model {
} }
} }
$rating = $this->db->query("SELECT round(avg(rate),2) AS rating
FROM mechanic_rating
WHERE mechanic_id='".$data['mechanic_id']."'");
$rating = (!empty($rating) && !empty($rating = $rating->row_array()))?$rating['rating']:'0';
$mechanic_id = $data['mechanic_id']; $mechanic_id = $data['mechanic_id'];
$sql = "SELECT ISS.*, IC.*, MI.* $sql = "SELECT ISS.*, IC.*, MI.*
FROM issues_category AS IC FROM issues_category AS IC
...@@ -201,6 +208,7 @@ class Mechanic_model extends CI_Model { ...@@ -201,6 +208,7 @@ class Mechanic_model extends CI_Model {
} }
} }
$mechData[$index]['rating'] = $rating;
$mechData[$index]['estimate'] = $estimate; $mechData[$index]['estimate'] = $estimate;
$mechData[$index]['sub_issues'] = $sIssueData; $mechData[$index]['sub_issues'] = $sIssueData;
$mechData[$index]['scheduleTiming'] = $scheduleTiming; $mechData[$index]['scheduleTiming'] = $scheduleTiming;
......
...@@ -125,6 +125,7 @@ class Webservice_model extends CI_Model { ...@@ -125,6 +125,7 @@ class Webservice_model extends CI_Model {
if(!empty($bookData) && (count($bookData) > 0)){ if(!empty($bookData) && (count($bookData) > 0)){
foreach ($bookData as $key => $value) { foreach ($bookData as $key => $value) {
$bookData[$key]['date'] = (string) strtotime($value['date'])*1000; $bookData[$key]['date'] = (string) strtotime($value['date'])*1000;
$bookData[$key]['date'] = $bookData[$key]['date']."";
} }
$respArr['data']['booked_services'] = $bookData; $respArr['data']['booked_services'] = $bookData;
}else{ }else{
...@@ -230,7 +231,6 @@ class Webservice_model extends CI_Model { ...@@ -230,7 +231,6 @@ class Webservice_model extends CI_Model {
$respArr['message'] = 'All Field is required'; $respArr['message'] = 'All Field is required';
return $respArr; return $respArr;
} }
//pr($postData['date']);exit();
$insert_array = array('cost'=>$postData['total_cost'],'mechanic_id'=>$postData['mechanic_id'],'scheduled_date'=>date('Y-m-d',$postData['date']/1000),'scheduled_time'=>$postData['time'],'issues_selected'=>json_encode($postData['service_id'])); $insert_array = array('cost'=>$postData['total_cost'],'mechanic_id'=>$postData['mechanic_id'],'scheduled_date'=>date('Y-m-d',$postData['date']/1000),'scheduled_time'=>$postData['time'],'issues_selected'=>json_encode($postData['service_id']));
if($this->db->update('bookings',$insert_array,array('booking_id'=>$postData['booking_id']))){ if($this->db->update('bookings',$insert_array,array('booking_id'=>$postData['booking_id']))){
$this->db->select("bookings.scheduled_time,bookings.scheduled_date,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,TRIM(concat(mechanic.first_name,' ',IFNULL(mechanic.last_name,''))) as mechanic_name,mechanic_shop.shop_name as mechanic_shop,mechanic.address,mechanic.phone,admin_users.profile_image as image,bookings.mileage,bookings.issues_selected"); $this->db->select("bookings.scheduled_time,bookings.scheduled_date,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,TRIM(concat(mechanic.first_name,' ',IFNULL(mechanic.last_name,''))) as mechanic_name,mechanic_shop.shop_name as mechanic_shop,mechanic.address,mechanic.phone,admin_users.profile_image as image,bookings.mileage,bookings.issues_selected");
...@@ -293,9 +293,10 @@ class Webservice_model extends CI_Model { ...@@ -293,9 +293,10 @@ class Webservice_model extends CI_Model {
} }
unset($mechanic_data['issues_selected']); unset($mechanic_data['issues_selected']);
$issue_data = json_decode($mechanic_data['custom_issue_data']); $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['optional_images'][] = (isset($issue_data->optionalImages))?$issue_data->optionalImages:'';
$mechanic_data['booking_description'] = ($issue_data->optionlaDescription)?$issue_data->optionlaDescription:''; $mechanic_data['optional_video'][] = (isset($issue_data->optionalVideos))?$issue_data->optionalVideos:'';
$mechanic_data['booking_description'] = (isset($issue_data->optionlaDescription))?$issue_data->optionlaDescription:'';
unset($mechanic_data['custom_issue_data']); unset($mechanic_data['custom_issue_data']);
$respArr['status'] = 'success'; $respArr['status'] = 'success';
$respArr['message'] = 'success'; $respArr['message'] = 'success';
...@@ -322,9 +323,9 @@ class Webservice_model extends CI_Model { ...@@ -322,9 +323,9 @@ class Webservice_model extends CI_Model {
3956*2*ASIN(SQRT(POWER(SIN(($current_lat-ME.location_lat)*pi()/180/2),2)+ 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)* COS($current_lat*pi()/180 )*COS(ME.location_lat*pi()/180)*
POWER(SIN(($current_lng-ME.location_lng)*pi()/180/2),2) )) AS distance POWER(SIN(($current_lng-ME.location_lng)*pi()/180/2),2) )) AS distance
FROM mechanic AS ME FROM mechanic AS ME
INNER JOIN admin_users AS AU ON (AU.id=ME.mechanic_id) 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') LEFT JOIN mechanic_shop AS MS ON (MS.shop_id=ME.shop_id AND MS.status='1')
WHERE AU.status='1' WHERE AU.status='1'
-- HAVING distance<30 -- HAVING distance<30
".$limt; ".$limt;
...@@ -346,6 +347,12 @@ class Webservice_model extends CI_Model { ...@@ -346,6 +347,12 @@ class Webservice_model extends CI_Model {
$scheduleTiming[] = date('h:i A',$schTime); $scheduleTiming[] = date('h:i A',$schTime);
} }
} }
$rating = $this->db->query("SELECT round(avg(rate),2) AS rating
FROM mechanic_rating
WHERE mechanic_id='".$data['mechanic_id']."'");
$rating = (!empty($rating) && !empty($rating = $rating->row_array()))?$rating['rating']:'0';
$mechanic_id = $data['mechanic_id']; $mechanic_id = $data['mechanic_id'];
$sql = "SELECT ISS.*, IC.*, MI.mechanic_id, MI.custom_description, MI.custom_service_fee $sql = "SELECT ISS.*, IC.*, MI.mechanic_id, MI.custom_description, MI.custom_service_fee
FROM issues_category AS IC FROM issues_category AS IC
...@@ -369,6 +376,7 @@ class Webservice_model extends CI_Model { ...@@ -369,6 +376,7 @@ class Webservice_model extends CI_Model {
$sIssueData[$sIndex]['service_fee'] = $sIssue['default_service_fee']; $sIssueData[$sIndex]['service_fee'] = $sIssue['default_service_fee'];
} }
} }
$mechData[$index]['rating'] = $rating;
$mechData[$index]['estimate'] = $estimate; $mechData[$index]['estimate'] = $estimate;
$mechData[$index]['sub_issues'] = $sIssueData; $mechData[$index]['sub_issues'] = $sIssueData;
$mechData[$index]['scheduleTiming'] = $scheduleTiming; $mechData[$index]['scheduleTiming'] = $scheduleTiming;
...@@ -437,6 +445,32 @@ class Webservice_model extends CI_Model { ...@@ -437,6 +445,32 @@ class Webservice_model extends CI_Model {
} }
return $respArr; return $respArr;
} }
public function rate_mechanic($auth,$postData){
$respArr = array('status'=>'error','message'=>'Something went Wrong.. Try Again');
if(empty($postData['rate'])){
$respArr['message'] = 'Rating is Required';
return $respArr;
}
if(empty($postData['mechanic_id'])){
$respArr['message'] = 'Mechanic Id is Required';
return $respArr;
}
if(empty($postData['description'])){
$respArr['message'] = 'Description is Required';
return $respArr;
}
$mechRate = $this->db->get_where('mechanic_rating',array('customer_id'=>$postData['customer_id'],'mechanic_id'=>$postData['mechanic_id']));
if(!empty($mechRate) && !empty($mechRate = $booked_data->row_array())){
$respArr['message'] = 'Sorry, You are already Rated for this mechanic';
return $respArr;
}
if($this->db->insert('mechanic_rating',$postData)){
$respArr['status'] = 'success';
$respArr['message'] = 'success';
}
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