Commit 256df255 by Jansa Jose

indent

parent 7128c223
......@@ -10,14 +10,11 @@ class Webservice_model extends CI_Model {
public function checkMobAvailability($data = array()){
$res = array('status'=>'success', 'message'=>'Mobile Number Available','data'=>array('phone'=>$data['phone'],'is_available'=>true));
if(empty($data)){
$res = array('status'=>'error','error'=>'901','message'=>'Something went wrong.');
return $res;
}
$result = $this->db->get_where('customers',array('phone'=>$data['phone'],'country_code'=>$data['country_code']));
if(!empty($result) && $result->num_rows() > 0){
$res=array('status'=>'error','error'=>'902','message'=>'Mobile number already in use.');
}
......@@ -26,22 +23,18 @@ class Webservice_model extends CI_Model {
public function checkCustomerLogin($userLogData){
$respArr = array('status'=>0);
if(empty($userLogData)){
return $returnStatus;
}
$result = $this->db->get_where('customers',array('email'=>$userLogData['email'],'status'=>'1'));
if(empty($result) || $result->num_rows() < 1 || empty($custData = $result->row())){
$respArr['status'] = 2;
return $respArr;
}
$this->db->select("customer_id as id,is_otp_verified,phone as phone_number,TRIM(CONCAT(first_name,' ' ,IFNULL(last_name,''))) as user_name");
$result = $this->db->get_where('customers',array('email'=>$userLogData['email'],
'password'=>$userLogData['password'],
'status'=>'1'));
$respArr['status'] = 3;
if(!empty($result) && $result->num_rows() == 1 && !empty($custData = $result->row())){
$authdata = $this->insert_auth($custData->id);
......@@ -67,12 +60,10 @@ class Webservice_model extends CI_Model {
public function createCustomer($customer_data = array()){
$respArr = array('status'=>0);
if(empty($customer_data)){
$respArr['status'] = 0;
return $respArr;
}
if(isset($customer_data['email']) && !empty($customer_data['email'])){
$emailChk = $this->db->get_where('customers',array('email'=>$customer_data['email'],'status !='=>'2'));
if(!empty($emailChk) && $emailChk->num_rows() > 0){
......@@ -80,7 +71,6 @@ class Webservice_model extends CI_Model {
return $respArr;
}
}
if(isset($customer_data['phone']) && !empty($customer_data['phone'])){
$phoneChk = $this->db->get_where('customers',array('phone'=>$customer_data['phone'],'status !='=>'2'));
if(!empty($phoneChk) && $phoneChk->num_rows() > 0){
......@@ -88,20 +78,14 @@ class Webservice_model extends CI_Model {
return $respArr;
}
}
$customer_data['first_name'] = $customer_data['name'];
unset($customer_data['name']);
if($this->db->insert('customers',$customer_data)){
$last_id = $this->db->insert_id();
$this->db->select("TRIM(CONCAT(first_name,' ' ,IFNULL(last_name,''))) as name,customer_id as user_id");
$custData = $this->db->get_where('customers',array('customer_id'=>$last_id))->row();
$authdata = $this->insert_auth($last_id);
$custData->auth_token = $authdata;
$respArr['data'] = $custData;
$respArr['status'] = 1;
}
......@@ -110,11 +94,9 @@ class Webservice_model extends CI_Model {
public function get_customer_authtoken($auth = ''){
$respArr = array('status'=>0,'error'=>'901','message'=>'Something Went Wrong.');
if(empty($auth)){
return $respArr;
}
$auth = $this->db->get_where('authtable',array('authtoken'=>$auth));
if(!empty($auth) && $auth->num_rows() >= 1 && !empty($custAuth = $auth->row_array())){
$respArr['status'] = 'success';
......@@ -129,17 +111,13 @@ class Webservice_model extends CI_Model {
public function getBookedService($id = ''){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
if(empty($id)){
return $respArr;
}
$this->db->select('booking_id as id,scheduled_date as date,scheduled_time as time');
$bookData = $this->db->get_where('bookings',array('customer_id'=>$id))->result_array();
$respArr['status'] = 'success';
$respArr['message'] = 'success';
if(!empty($bookData) && (count($bookData) > 0)){
$respArr['data']['booked_services'] = $bookData;
}else{
......@@ -150,13 +128,10 @@ class Webservice_model extends CI_Model {
public function addVehicleDetails($postData = array(),$customer_id = ''){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
if(empty($postData)){
return $respArr;
}
$car_name = $postData['vehicle_year'].' '.$postData['vehicle_make'].' '.$postData['vehicle_model'];
$vehJson = array(
'vehicle' => $car_name,
'attributes' => array(
......@@ -167,7 +142,6 @@ class Webservice_model extends CI_Model {
'Engine'=> $postData['engine_no']
)
);
$insert_array = array(
'customer_id' => $customer_id,
'car_name' => $car_name,
......@@ -180,20 +154,16 @@ class Webservice_model extends CI_Model {
'car_model_year'=> $postData['vehicle_year'],
'status' => '3'
);
if($this->db->insert('customer_vehicle',$insert_array)){
$last_id = $this->db->insert_id();
$book_data = array(
'mileage' => $postData['mileage'],
'customer_id' => $customer_id,
'customer_veh_id'=> $last_id,
'status' => '5'
);
if($this->db->insert('bookings',$book_data)){
$book_id = $this->db->insert_id();
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data']['booking_id'] = $book_id;
......@@ -205,7 +175,6 @@ class Webservice_model extends CI_Model {
public function get_service_list($postData = '',$start,$per_page){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
$this->db->select("issue_id as id,issue as service_name,IF(issue_image != NULL OR issue_image != '' , concat('".base_url()."',issue_image) , '') as icon");
if(!empty($postData['query'])){
$where = "issue LIKE '".$postData['query']."%'";
......@@ -216,7 +185,6 @@ class Webservice_model extends CI_Model {
$this->db->limit($per_page,$start);
}
$service = $this->db->get('issues');
if(!empty($service) && !empty($serviceData = $service->result_array())){
$respArr['status'] = 'success';
$respArr['message'] = 'success';
......@@ -227,24 +195,20 @@ class Webservice_model extends CI_Model {
public function search_sub_services($postData = '',$start,$per_page){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
if(!isset($postData['service_id']) && empty($postData['service_id'])){
$respArr['status'] = 1;
$respArr['message'] = 'Service Id is Required';
return $respArr;
}
$this->db->select("issue_cat_id as id,issue_category as sub_service_name,IF(issue_cat_image != NULL OR issue_cat_image != '' , concat('".base_url()."',issue_cat_image) , '') as icon");
if(!empty($postData['query'])){
$where = "issue_category LIKE '".$postData['query']."%'";
$this->db->where($where);
}
if($start != 0 || $per_page != 0){
$this->db->limit($per_page,$start);
}
$subservice = $this->db->get_where('issues_category',array('status'=>'1','issue_id'=>$postData['service_id']));
if(!empty($subservice) && !empty($subserviceData = $subservice->result_array())){
$respArr['status'] = 'success';
$respArr['message'] = 'success';
......@@ -255,14 +219,11 @@ class Webservice_model extends CI_Model {
public function book_service($postData){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
if(empty($postData)){
$respArr['message'] = 'All Field is required';
return $respArr;
}
$insert_array = array('cost'=>$postData['total_cost'],'mechanic_id'=>$postData['mechanic_id'],'scheduled_date'=>$postData['date'],'scheduled_time'=>$postData['time']);
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->join('customer_vehicle','customer_vehicle.customer_veh_id = bookings.customer_veh_id');
......@@ -270,14 +231,11 @@ class Webservice_model extends CI_Model {
$this->db->join('admin_users','admin_users.id = mechanic.mechanic_id');
$this->db->join('mechanic_shop','mechanic_shop.shop_id = mechanic.shop_id','left');
$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']);
$respArr['status'] = 'success';
......@@ -291,7 +249,6 @@ class Webservice_model extends CI_Model {
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;
......@@ -299,14 +256,11 @@ class Webservice_model extends CI_Model {
$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,bookings.mechanic_id");
$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']);
if(!empty($mechanic_data['services'])){
foreach($mechanic_data['services'] as $key => $value){
......@@ -329,15 +283,12 @@ class Webservice_model extends CI_Model {
}else{
$mechanic_data['services'] = [];
}
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;
......@@ -347,21 +298,17 @@ class Webservice_model extends CI_Model {
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 = $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)+
......@@ -373,12 +320,10 @@ class Webservice_model extends CI_Model {
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){
......@@ -389,12 +334,10 @@ class Webservice_model extends CI_Model {
$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
......@@ -402,14 +345,11 @@ class Webservice_model extends CI_Model {
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'])){
......@@ -420,11 +360,9 @@ class Webservice_model extends CI_Model {
$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;
......@@ -434,18 +372,15 @@ class Webservice_model extends CI_Model {
public function add_service_details($postData){
$respArr = array('status'=>'error','message'=>'Something Went Wrong');
if(empty($postData['booking_id'])){
$respArr['message'] = 'Booking Id is Required';
return $respArr;
}
$custom_issue_data = array(
'optionlaDescription'=>(isset($postData['description']) && !empty($postData['description']))?$postData['description']:"",
'optionalImages'=>(isset($postData['image']) && !empty($postData['image']))?$postData['image']:[],
'optionalVideos'=>(isset($postData['video']) && !empty($postData['video']))?$postData['video']:[],
);
if($this->db->update('bookings',array('custom_issue_data'=>json_encode($custom_issue_data)),array('booking_id'=>$postData['booking_id']))){
$respArr['status'] = 'success';
$respArr['message'] = 'success';
......@@ -455,7 +390,6 @@ class Webservice_model extends CI_Model {
public function remove_booking($postData = array()){
$respArr = array('status'=>'error','message'=>'Something Went Wrong..!');
if(empty($postData['booking_id'])){
$respArr['message'] = 'Booking Id is Required';
return $respArr;
......@@ -463,7 +397,6 @@ class Webservice_model extends CI_Model {
$respArr['message'] = 'Service Id is Required';
return $respArr;
}
$booked_data = $this->db->get_where('bookings',array('booking_id'=>$postData['booking_id']));
if(!empty($booked_data) && !empty($booked_data = $booked_data->row_array())){
$issues_selected = json_decode($booked_data['issues_selected']);
......@@ -483,14 +416,11 @@ class Webservice_model extends CI_Model {
public function get_service($postData = array()){
$respArr = array('status'=>'error','message'=>'Something went Wrong.. Try Again');
if(empty($postData['booking_id'])){
$respArr['message'] = 'Booking Id is Required';
return $respArr;
}
$booked_data = $this->db->get_where('bookings',array('booking_id'=>$postData['booking_id']));
if(!empty($booked_data) && !empty($booked_data = $booked_data->row_array())){
$respArr['status'] = 'success';
$respArr['message'] = 'success';
......
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