Commit 78e94c4e by Jansa Jose

dc

parent 1a3f5be7
......@@ -209,7 +209,6 @@
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Mechanic_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['pickup_data']) || !isset($postData['sub_issues']) ||
......@@ -473,11 +472,12 @@
$vehicle_data['car_loc_lat'] = $locationData['location_lat'];
$vehicle_data['car_loc_lng'] = $locationData['location_lng'];
$vehicle_data['car_location'] = $locationData['location'];
$this->load->model('Settings_model');
$settings = $this->Settings_model->settings_viewing();
$searchData = $postData['vehicleData'];
if($searchType == 1 &&
isset($searchData['car_maker']) && !empty($searchData['car_maker']) &&
isset($searchData['modelName']) && !empty($searchData['modelName']) &&
......@@ -1267,6 +1267,28 @@
$getServices = $this->Webservice_model->get_service($postData);
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 {
!isset($postData['selected_issues']) || empty($postData['selected_issues'])){
return 0;
}
$vehData = $postData['vechile_info'];
$car_name = $vehData['modelYear'].' '.$vehData['maker'].' '.$vehData['modelName'];
$vehJson = array('vehicle' => $car_name,
'attributes' =>
array('Year' => $vehData['modelYear'],
'Make' => $vehData['maker'],
'Trim' => $vehData['trim'],
'Model' => $vehData['modelName'],
'Engine' => $vehData['emgine']));
$insert_array = array('customer_id' => $postData['customer_id'],
$vehJson = array('vehicle' => $car_name,'attributes' =>
array('Year' => $vehData['modelYear'],
'Make' => $vehData['maker'],
'Trim' => $vehData['trim'],
'Model' => $vehData['modelName'],
'Engine' => $vehData['emgine']));
if(isset($vehData['lastMaintanceDate']) && !empty($vehData['lastMaintanceDate'])){
$last_date = $vehData['lastMaintanceDate'];
}else{
$last_date ='';
}
$insert_array = array('customer_id' => $postData['customer_id'],
'car_name' => $car_name,
'car_model' => $vehData['modelName'],
'car_maker' => $vehData['maker'],
......@@ -35,21 +37,22 @@ class Booking_model extends CI_Model {
'car_location' => $postData['pickup_data']['pickup_loc'],
'vehicle_data' => json_encode($vehJson),
'car_model_year'=> $vehData['modelYear'],
'last_maintenance_date'=>$last_date,
'status' => '3');
$selected_issues = array();
foreach($postData['selected_issues'] AS $selIssue){
$selected_issues[] = array('issue' =>$selIssue['issue'],
'issue_id' =>$selIssue['issue_id'],
'sub_issue_id' =>$selIssue['sub_issue_id'],
'issue_category' =>$selIssue['issue_category']);
$selected_issues[] = array('issue' => $selIssue['issue'],
'issue_id' => $selIssue['issue_id'],
'sub_issue_id' => $selIssue['sub_issue_id'],
'issue_category' => $selIssue['issue_category']);
}
if($this->db->insert('customer_vehicle',$insert_array)){
$last_id = $this->db->insert_id();
$book_data = array('cost' => $postData['cost'],
$book_data = array('cost' => $postData['cost'],
'mileage' => $vehData['milage'],
'customer_id' => $postData['customer_id'],
'mechanic_id' => $postData['mechanic_id'],
......
......@@ -150,6 +150,7 @@ class Mechanic_model extends CI_Model {
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_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')
WHERE AU.status='1'
-- HAVING distance<30";
......@@ -162,6 +163,7 @@ class Mechanic_model extends CI_Model {
$estimate = 0;
$mechDataArr = array();
foreach($mechData AS $index => $data){
$data['distance'] = (int)$data['distance'];
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');
......@@ -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'];
$sql = "SELECT ISS.*, IC.*, MI.*
FROM issues_category AS IC
......@@ -201,6 +208,7 @@ class Mechanic_model extends CI_Model {
}
}
$mechData[$index]['rating'] = $rating;
$mechData[$index]['estimate'] = $estimate;
$mechData[$index]['sub_issues'] = $sIssueData;
$mechData[$index]['scheduleTiming'] = $scheduleTiming;
......
......@@ -125,6 +125,7 @@ class Webservice_model extends CI_Model {
if(!empty($bookData) && (count($bookData) > 0)){
foreach ($bookData as $key => $value) {
$bookData[$key]['date'] = (string) strtotime($value['date'])*1000;
$bookData[$key]['date'] = $bookData[$key]['date']."";
}
$respArr['data']['booked_services'] = $bookData;
}else{
......@@ -230,7 +231,6 @@ class Webservice_model extends CI_Model {
$respArr['message'] = 'All Field is required';
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']));
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");
......@@ -293,9 +293,10 @@ class Webservice_model extends CI_Model {
}
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:'';
$mechanic_data['optional_images'][] = (isset($issue_data->optionalImages))?$issue_data->optionalImages:'';
$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']);
$respArr['status'] = 'success';
$respArr['message'] = 'success';
......@@ -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)+
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')
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;
......@@ -346,6 +347,12 @@ class Webservice_model extends CI_Model {
$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'];
$sql = "SELECT ISS.*, IC.*, MI.mechanic_id, MI.custom_description, MI.custom_service_fee
FROM issues_category AS IC
......@@ -369,6 +376,7 @@ class Webservice_model extends CI_Model {
$sIssueData[$sIndex]['service_fee'] = $sIssue['default_service_fee'];
}
}
$mechData[$index]['rating'] = $rating;
$mechData[$index]['estimate'] = $estimate;
$mechData[$index]['sub_issues'] = $sIssueData;
$mechData[$index]['scheduleTiming'] = $scheduleTiming;
......@@ -437,6 +445,32 @@ class Webservice_model extends CI_Model {
}
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