From 8e4c965b4f5b2c1ad56a65f9c593087fa1a7aaca Mon Sep 17 00:00:00 2001
From: jansa <jansa@techware.in>
Date: Fri, 19 Jul 2019 13:20:41 +0530
Subject: [PATCH] dc

---
 application/controllers/Webservices.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 application/models/Webservice_model.php | 23 ++++++++++++++++++++---
 2 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/application/controllers/Webservices.php b/application/controllers/Webservices.php
index d463476..c99fe67 100644
--- a/application/controllers/Webservices.php
+++ b/application/controllers/Webservices.php
@@ -2643,5 +2643,67 @@
 			$result = $this->Webservice_model->remove_vehicle($postData);
 			echo json_encode($result);exit;
 	    }
+
+	    public function get_mechanics_reviews(){
+	    	header('Content-type:application/json');
+			$headers = apache_request_headers();
+			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;
+			}
+			$post = file_get_contents("php://input");
+			$postData = json_decode($post,true);
+			$postData['user_id'] = $authRes['data']['customer_id'];
+			$per_page = 10;
+			$page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1; 
+		    $start = ($page - 1) * $per_page; 
+			$reviewResult = $this->Webservice_model->get_mechanics_reviews($postData,0,0);
+			$reviewList = $this->Webservice_model->get_mechanics_reviews($postData,$start,$per_page);
+			$total = 0;
+			if($reviewResult['status'] == 'success'){
+				$total = count($reviewResult['data']);	
+			}
+			if($total >= $per_page){
+				$totalPages =(int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
+			}
+			else{
+				$totalPages = 1;
+			}
+			if($reviewList['status'] == 'success'){
+				$respArr = array(
+					'status' => 'success',
+					'message'=>'success',
+					'data' => array(
+						'reviews' => $reviewList['data']
+					),
+					'meta' => array(
+						'total_pages' => $totalPages,
+						'total' => $total,
+						'current_page' => ($page == 0)?1:$page,
+						'per_page' => $per_page
+					)
+				);
+			}else{
+				$respArr = array(
+					'status' => 'error',
+					'message'=>'No data',
+					'data' => array(
+						'reviews' => []
+					),
+					'meta' => array(
+						'total_pages' => $totalPages,
+						'total' => $total,
+						'current_page' => ($page == 0)?1:$page,
+						'per_page' => $per_page
+					)
+				);
+			}
+			echo json_encode($respArr);exit;
+	    }
 	}
 ?>
diff --git a/application/models/Webservice_model.php b/application/models/Webservice_model.php
index 3048692..f2964d5 100644
--- a/application/models/Webservice_model.php
+++ b/application/models/Webservice_model.php
@@ -162,7 +162,7 @@ class Webservice_model extends CI_Model {
     }
     $where = ($type == 1)?array('bookings.booking_id'=>$id):array('bookings.customer_id'=>$id);
     $this->db->select("bookings.booking_id as id,bookings.scheduled_date as booked_date,bookings.scheduled_time as time,customer_vehicle.vehicle_data,customer_vehicle.customer_veh_id as vehicle_id,customer_vehicle.car_model_year as year,customer_vehicle.car_maker as vehcle_make,customer_vehicle.car_model as vehicle_type,bookings.mileage,
-      bookings.service_type as is_emergency,bookings.status as service_status,bookings.issues_selected,bookings.custom_issue_data,mechanic.location,mechanic.location_lat,mechanic.location_lng,mechanic_booking.amount,TRIM(concat(mechanic.first_name,' ',IFNULL(mechanic.last_name,''))) as mechanic_name,mechanic.address,mechanic.phone");
+      bookings.service_type as is_emergency,bookings.status as service_status,bookings.issues_selected,bookings.custom_issue_data,mechanic.location,mechanic.location_lat,mechanic.location_lng,mechanic_booking.amount,bookings.cost,TRIM(concat(mechanic.first_name,' ',IFNULL(mechanic.last_name,''))) as mechanic_name,mechanic.address,mechanic.phone,mechanic.mechanic_id");
     $this->db->join('customer_vehicle','customer_vehicle.customer_veh_id = bookings.customer_veh_id');
     $this->db->join("mechanic_booking","mechanic_booking.booking_id = bookings.booking_id AND mechanic_booking.status='1'");
     $this->db->join("mechanic","mechanic_booking.mechanic_id = mechanic.mechanic_id");
@@ -184,7 +184,8 @@ class Webservice_model extends CI_Model {
           $bookData[$key]['services'] = !empty($value['issues_selected'])?json_decode($value['issues_selected']):'';
         }
         $bookData[$key]['service_description'] = !empty($value['custom_issue_data'])?json_decode($value['custom_issue_data'])->optionlaDescription:'';
-        unset($bookData[$key]['vehicle_data'],$bookData[$key]['issues_selected'],$bookData[$key]['custom_issue_data']);
+        $bookData[$key]['book_amount'] = ($value['is_emergency'] == '1')?$value['amount']:$value['cost'];
+        unset($bookData[$key]['vehicle_data'],$bookData[$key]['issues_selected'],$bookData[$key]['custom_issue_data'],$bookData[$key]['amount'],$bookData[$key]['cost']);
       }
       if($type == 1){  
         $respArr['data'] = $bookData[0];
@@ -1498,7 +1499,23 @@ class Webservice_model extends CI_Model {
       $respArr['status'] = "success";
       $respArr['message'] = "Vehicle Deleted Successfully";
     }
+    return $respArr;
+  }
+
+  public function get_mechanics_reviews($postData=array(),$start='',$per_page=''){
+    $respArr = array('status'=>'error','message'=>'Something Went Wrong.');
+    $this->db->select("mechanic_rating.*,TRIM(CONCAT(customers.first_name,' ' ,IFNULL(customers.last_name,''))) as customers_name");
+    $this->db->join('customers','customers.customer_id = mechanic_rating.customer_id');
+    if($start != 0 || $per_page != 0){
+      $this->db->limit($per_page,$start);
+    }
+    $review = $this->db->get_where('mechanic_rating',array('mechanic_id'=>$postData['mechanic_id']));
+    if(!empty($service) && !empty($reviewData = $review->result_array())){
+      $respArr['status'] = 'success';
+      $respArr['message'] = 'success';
+      $respArr['data']= $reviewData;
+    }
+    return $respArr;
   }
-  return $respArr;
 }
 ?>
--
libgit2 0.27.1