Commit a3a0b0a1 by Tobin

dc

parent 637f6a6b
...@@ -59,6 +59,9 @@ class Vehicle extends CI_Controller { ...@@ -59,6 +59,9 @@ class Vehicle extends CI_Controller {
echo json_encode($return_arr);exit; echo json_encode($return_arr);exit;
} }
if($searchType == 2){ if($searchType == 2){
$vehicle_data['car_model'] = $vehData['attributes']['Model'];
$vehicle_data['car_maker'] = $vehData['attributes']['Make'];
$vehicle_data['car_model_year'] = $vehData['attributes']['Year'];
$vehData['vehicle'] = $vehData['attributes']['Year'].' '.$vehData['attributes']['Make'].' '. $vehData['vehicle'] = $vehData['attributes']['Year'].' '.$vehData['attributes']['Make'].' '.
$vehData['attributes']['Model'].' '.$vehData['attributes']['Trim']; $vehData['attributes']['Model'].' '.$vehData['attributes']['Trim'];
} }
......
...@@ -50,7 +50,7 @@ class Webservices extends CI_Controller { ...@@ -50,7 +50,7 @@ class Webservices extends CI_Controller {
$respArr = array('status'=>'0','message'=>'Required Fields are empty.'); $respArr = array('status'=>'0','message'=>'Required Fields are empty.');
if(!isset($postData['email']) || empty($postData['email']) || if(!isset($postData['email']) || empty($postData['email']) ||
!isset($postData['password']) || empty($postData['password'])){ !isset($postData['password']) || empty($postData['password'] = md5($postData['password']))){
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
...@@ -132,7 +132,7 @@ class Webservices extends CI_Controller { ...@@ -132,7 +132,7 @@ class Webservices extends CI_Controller {
$err = 1; $err = 1;
$msg = 'Provide a valid Email ID'; $msg = 'Provide a valid Email ID';
} }
else if(!isset($postData['password']) || empty($postData['password'])){ else if(!isset($postData['password']) || empty($postData['password'] = md5($postData['password']))){
$err = 1; $err = 1;
$msg = 'Provide a Password'; $msg = 'Provide a Password';
} }
...@@ -155,19 +155,14 @@ class Webservices extends CI_Controller { ...@@ -155,19 +155,14 @@ class Webservices extends CI_Controller {
} }
unset($postData['promocode']); unset($postData['promocode']);
$custResp = $this->Customer_model->customer_registration($postData); $custResp = $this->Customer_model->createCustomer($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){ if(empty($custResp)){
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
if($custResp['status'] == '2'){ if($custResp == '1'){
$respArr['status'] = '2';
$respArr['message'] = 'Email Address already in use';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$custResp = $this->Customer_model->checkCustomerLogin($postData); $custResp = $this->Customer_model->checkCustomerLogin($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){ if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
...@@ -178,7 +173,17 @@ class Webservices extends CI_Controller { ...@@ -178,7 +173,17 @@ class Webservices extends CI_Controller {
$respArr['message'] = 'Success'; $respArr['message'] = 'Success';
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
} else if($custResp == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Email Address already in use';
echo json_encode($respArr);exit;
} else if($custResp == '3'){
$respArr['status'] = '2';
$respArr['message'] = 'Phone already in use';
echo json_encode($respArr);exit;
} }
echo json_encode($respArr); exit; echo json_encode($respArr); exit;
} }
...@@ -207,8 +212,13 @@ class Webservices extends CI_Controller { ...@@ -207,8 +212,13 @@ class Webservices extends CI_Controller {
$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.');
pr($postData);
if(empty($postData) || !isset($postData['pickup_data']) || !isset($postData['sub_issues']) ||
empty($postData['pickup_data']) || empty($postData['sub_issues']) ){
echo json_encode($respArr); exit;
}
$mechanic_data = $this->Mechanic_model->getNearByMechanics($postData); $mechanic_data = $this->Mechanic_model->getNearByMechanics($postData['pickup_data'],$postData['sub_issues']);
if(!empty($mechanic_data)){ if(!empty($mechanic_data)){
$respArr['status'] = '1'; $respArr['status'] = '1';
...@@ -229,8 +239,8 @@ class Webservices extends CI_Controller { ...@@ -229,8 +239,8 @@ class Webservices extends CI_Controller {
if(empty($postData)){ if(empty($postData)){
echo json_encode($respArr); exit; echo json_encode($respArr); exit;
} }
$this->load->model('Vehicle_model'); $this->load->model('Booking_model');
$status = $this->Vehicle_model->scheduleBooking($postData); $status = $this->Booking_model->scheduleBooking($postData);
if($status){ if($status){
$respArr['status'] = '1'; $respArr['status'] = '1';
$respArr['message'] = 'Success'; $respArr['message'] = 'Success';
...@@ -241,12 +251,13 @@ class Webservices extends CI_Controller { ...@@ -241,12 +251,13 @@ class Webservices extends CI_Controller {
// edit_customer_profile // edit_customer_profile
public function edit_customer_profile(){ public function edit_customer_profile(){
header('Content-type: application/json'); header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true); $postData = $_POST;
$this->load->model('Customer_model'); $this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.'); $respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData)){ if(empty($postData) || empty($postData = json_decode($postData['data'],true)) ||
!isset($postData['customer_id']) || empty($postData['customer_id'])){
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
...@@ -277,26 +288,45 @@ class Webservices extends CI_Controller { ...@@ -277,26 +288,45 @@ class Webservices extends CI_Controller {
$respArr['message'] = $msg; $respArr['message'] = $msg;
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
pr($postData);
unset($postData['cpassword']); if(isset($_FILES) && !empty($_FILES) &&
if(isset($postData['password']) && !empty($postData['password'])){ isset($_FILES['profile_image']) && !empty($_FILES['profile_image'])){
$config = set_upload_service("assets/uploads/services");
$this->load->library('upload');
$config['file_name'] = $postData['customer_id']."_".$_FILES['profile_image']['name'];
$this->upload->initialize($config);
if($this->upload->do_upload('profile_image')){
$upload_data = $this->upload->data();
$postData['profile_image'] = $config['upload_path']."/".$upload_data['file_name'];
}
}
$customer_id = $postData['customer_id'];
if(isset($postData['password']) && !empty($postData['password']) &&
isset($postData['cpassword']) && !empty($postData['cpassword']) &&
$postData['password'] == $postData['cpassword']){
$postData['password'] = md5($postData['password']); $postData['password'] = md5($postData['password']);
} else {
unset($postData['password']);
} }
unset($postData['cpassword']);
unset($postData['customer_id']);
$custResp = $this->Customer_model->custProfileEdit($postData); $custResp = $this->Customer_model->updateCustomer($customer_id,$postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){ if(empty($custResp)){
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
if($custResp['status'] == '1'){ if($custResp == '1'){
$respArr['status'] = '1'; $respArr['status'] = '1';
$respArr['message'] = 'Profile successfully updated'; $respArr['message'] = 'Profile successfully updated';
$respArr['profile_image'] = $postData['profile_image'];
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} else if($custResp['status'] == '2'){ } else if($custResp == '2'){
$respArr['status'] = '2'; $respArr['status'] = '2';
$respArr['message'] = 'Email Address already in use'; $respArr['message'] = 'Email Address already in use';
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} else if($custResp['status'] == '3'){ } else if($custResp == '3'){
$respArr['status'] = '3'; $respArr['status'] = '3';
$respArr['message'] = 'Phone Number already in use'; $respArr['message'] = 'Phone Number already in use';
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
...@@ -304,6 +334,172 @@ class Webservices extends CI_Controller { ...@@ -304,6 +334,172 @@ class Webservices extends CI_Controller {
echo json_encode($respArr); exit; echo json_encode($respArr); exit;
} }
// customerVechiles
function customerVechiles(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Vehicle_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['customer_id']) || empty($postData['customer_id'])){
echo json_encode($respArr);exit;
}
$vehData = $this->Vehicle_model->getCustVechiles($postData);
if($vehData != '0'){
$respArr['status'] = 1;
$respArr['message'] = 'success';
$respArr['vehData'] = $vehData;
}
echo json_encode($respArr);exit;
}
// getCustBookDetails
function getCustBookDetails(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Booking_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['customer_id']) || empty($postData['customer_id'])){
echo json_encode($respArr);exit;
}
$status = (isset($postData['status']) && !empty($postData['status']))?$postData['status']:'';
$bookingDetails = $this->Booking_model->getCustBookDetails($postData,$status);
if($bookingDetails != '0'){
$respArr['status'] = 1;
$respArr['message'] = 'success';
$respArr['bookData'] = $bookingDetails;
}
echo json_encode($respArr);exit;
}
// cancelBooking
function cancelBooking(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Booking_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['customer_id']) || empty($postData['customer_id']) ||
!isset($postData['booking_id']) || empty($postData['booking_id'])){
echo json_encode($respArr);exit;
}
$status=$this->Booking_model->changeBookStatus($postData['customer_id'],$postData['booking_id'],'3');
if($status){
$respArr['status'] = 1;
$respArr['message'] = 'success';
}
echo json_encode($respArr);exit;
}
// deleteCustomerCar
function deleteCustomerCar(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Vehicle_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['customer_id']) || empty($postData['customer_id']) ||
!isset($postData['customer_veh_id']) || empty($postData['customer_veh_id'])){
echo json_encode($respArr);exit;
}
$status = $this->Vehicle_model->changeCustomerCarStatus($postData['customer_id'],
$postData['customer_veh_id'],'2');
if($status){
$respArr['status'] = 1;
$respArr['message'] = 'success';
}
echo json_encode($respArr);exit;
}
// addCustomerCar
function addCustomerCar(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Vehicle_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData) || !isset($postData['customer_id']) || empty($postData['customer_id'])){
echo json_encode($respArr);exit;
}
$param = "";
$searchType = $postData['type'];
$searchData = $postData['vehicleData'];
$locationData = $postData['location'];
$vehicle_data['status'] = '1';
$vehicle_data['customer_id'] = $postData['customer_id'];
$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']) &&
isset($searchData['modelYear']) && !empty($searchData['modelYear'])){
$vehicle_data['car_maker'] = $searchData['car_maker'];
$vehicle_data['car_model'] = $searchData['modelName'];
$vehicle_data['car_model_year'] = $searchData['modelYear'];
$param = "?format=json&key=".urlencode($settings['vin_audit_api'])."&year=".
urlencode($searchData['modelYear'])."&make=".urlencode($searchData['car_maker']).
"&model=".urlencode($searchData['modelName']);
}
else if($searchType == 2 && isset($searchData['vin']) && !empty($searchData['vin'])){
$vehicle_data['car_vin'] = $searchData['vin'];
$param = "?format=json&key=".urlencode($settings['vin_audit_api']).
"&vin=".urlencode($searchData['vin']);
}
if(!empty($param)){
$vehData=file_get_contents("https://specifications.vinaudit.com/getspecifications.php".$param);
if(empty($vehData) || empty($vehData = json_decode($vehData,true))){
echo json_encode($return_arr);exit;
}
if(!isset($vehData['success']) || empty($vehData['success']) || $vehData['success'] == false){
$return_arr['status'] = 2;
$return_arr['message'] = 'No Data Found.';
echo json_encode($return_arr);exit;
}
if($searchType == 2){
$vehicle_data['car_model'] = $vehData['attributes']['Model'];
$vehicle_data['car_maker'] = $vehData['attributes']['Make'];
$vehicle_data['car_model_year'] = $vehData['attributes']['Year'];
$vehData['vehicle']= $vehData['attributes']['Year'].' '.$vehData['attributes']['Make'].' '.
$vehData['attributes']['Model'].' '.$vehData['attributes']['Trim'];
}
$vehicle_data['car_name'] = $vehData['vehicle'];
$vehicle_data['vehicle_data'] = json_encode($vehData);
$car_id = $this->Vehicle_model->addVehicle($vehicle_data);
if(!empty($car_id)){
$return_arr['status'] = '1';
$return_arr['car_id'] = $car_id;
$return_arr['veh_data'] = $vehData;
}
}
echo json_encode($return_arr);exit;
}
} }
?> ?>
\ No newline at end of file
\ No newline at end of file
<?php
class Booking_model extends CI_Model {
public function _consruct(){
parent::_construct();
}
public function scheduleBooking($postData = array()){
if(empty($postData)){
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'],
'car_name' => $car_name,
'car_model' => $vehData['modelName'],
'car_maker' => $vehData['maker'],
'car_loc_lat' => $postData['pickup_data']['pickup_lat'],
'car_loc_lng' => $postData['pickup_data']['pickup_lng'],
'car_location' => $postData['pickup_data']['pickup_loc'],
'vehicle_data' => json_encode($vehJson),
'car_model_year'=> $vehData['modelYear'],
'status' => '3');
if($this->db->insert('customer_vehicle',$insert_array)){
$last_id = $this->db->insert_id();
$book_data = array(
'customer_veh_id' => $last_id,
'customer_id' => $postData['customer_id'],
'mechanic_id' => $postData['mechanic_id'],
'scheduled_date' => $postData['schedule_date']['date'],
'scheduled_time' => $postData['schedule_date']['time'],
'mileage' => $vehData['milage'],
'status' => '0');
if($this->db->insert('bookings',$book_data)){
return 1;
}
}
return 0;
}
function getCustBookDetails($postData = array(), $status = ''){
$cond = array();
if(empty($postData) || !isset($postData['customer_id']) || empty($postData['customer_id'])){
return 0;
}
$cond = "BK.customer_id='".$postData['customer_id']."' ";
$cond .= (!empty($status))?"AND BK.status IN (".$status.") ":'';
$sql = "SELECT BK.booking_id,BK.customer_id,BK.mechanic_id,BK.customer_veh_id,BK.scheduled_date,
BK.scheduled_time,BK.cost,BK.status,MECH.first_name,MECH.last_name,VEH.car_name,
BK.status
FROM bookings AS BK
INNER JOIN mechanic AS MECH ON (MECH.mechanic_id AND BK.mechanic_id)
INNER JOIN customer_vehicle AS VEH ON (VEH.customer_veh_id AND BK.customer_veh_id)
WHERE $cond
GROUP BY BK.booking_id";
$bookData = $this->db->query($sql);
if(!empty($bookData)){
return $bookData->result();
}
return 0;
}
function changeBookStatus($customer_id = '', $booking_id = '', $status = ''){
if(empty($customer_id) || empty($booking_id) || $status == ''){
return 0;
}
$status = $this->db->update('bookings',
array('status'=>$status),
array('customer_id'=>$customer_id,'booking_id'=>$booking_id));
return $status;
}
}
?>
\ No newline at end of file
...@@ -38,6 +38,7 @@ class Customer_model extends CI_Model { ...@@ -38,6 +38,7 @@ class Customer_model extends CI_Model {
return 2; return 2;
} }
} }
if(isset($customer_data['phone']) && !empty($customer_data['phone'])){ if(isset($customer_data['phone']) && !empty($customer_data['phone'])){
$phoneChk = $this->db->get_where('customers',array('phone'=>$customer_data['phone'],'status !='=>'2')); $phoneChk = $this->db->get_where('customers',array('phone'=>$customer_data['phone'],'status !='=>'2'));
if(!empty($phoneChk) && $phoneChk->num_rows() > 0){ if(!empty($phoneChk) && $phoneChk->num_rows() > 0){
...@@ -99,7 +100,7 @@ class Customer_model extends CI_Model { ...@@ -99,7 +100,7 @@ class Customer_model extends CI_Model {
} }
$result = $this->db->get_where('customers',array('email'=>$userLogData['email'], $result = $this->db->get_where('customers',array('email'=>$userLogData['email'],
'password'=>md5($userLogData['password']), 'password'=>$userLogData['password'],
'status'=>'1')); 'status'=>'1'));
$respArr['status'] = 3; $respArr['status'] = 3;
if(!empty($result) && $result->num_rows() == 1 && !empty($custData = $result->row())){ if(!empty($result) && $result->num_rows() == 1 && !empty($custData = $result->row())){
...@@ -131,23 +132,5 @@ class Customer_model extends CI_Model { ...@@ -131,23 +132,5 @@ class Customer_model extends CI_Model {
} }
return $respArr; return $respArr;
} }
function customer_registration($userData = array()){
$respArr = array('status'=>0);
if(empty($userData)){
return $respArr;
}
$result = $this->db->get_where('customers',array('email'=>$userData['email'],'status'=>'1'));
if(!empty($result) && $result->num_rows() >= 1){
$respArr['status'] = 2;
return $respArr;
}
$userData['password'] = md5($userData['password']);
$status = $this->db->insert('customers',$userData);
if($status){
$respArr['status'] = 1;
}
return $respArr;
}
} }
?> ?>
\ No newline at end of file
...@@ -26,52 +26,34 @@ class Vehicle_model extends CI_Model { ...@@ -26,52 +26,34 @@ class Vehicle_model extends CI_Model {
return $status; return $status;
} }
public function scheduleBooking($postData = array()){ function getCustVechiles($searchData = array()){
if(empty($postData)){ if(empty($searchData)){
return 0; return 0;
} }
$vehData = $postData['vechile_info']; $cond = array();
$car_name = $vehData['modelYear'].' '.$vehData['maker'].' '.$vehData['modelName'];
$cond['status'] = 1;
$vehJson = array('vehicle' => $car_name, if(isset($searchData['customer_id']) && !empty($searchData['customer_id'])){
'attributes' => $cond['customer_id'] = $searchData['customer_id'];
array( }
'Year' => $vehData['modelYear'], $vehData = $this->db->get_where('customer_vehicle',$cond);
'Make' => $vehData['maker'],
'Trim' => $vehData['trim'], if(!empty($vehData)){
'Model' => $vehData['modelName'], return $vehData->result();
'Engine' => $vehData['emgine'] }
)); return 0;
}
$insert_array = array(
'customer_id' => $postData['customer_id'],
'car_name' => $car_name,
'car_model' => $vehData['modelName'],
'car_maker' => $vehData['maker'],
'car_loc_lat' => $postData['pickup_data']['pickup_lat'],
'car_loc_lng' => $postData['pickup_data']['pickup_lng'],
'car_location' => $postData['pickup_data']['pickup_loc'],
'vehicle_data' => json_encode($vehJson),
'car_model_year'=> $vehData['modelYear'],
'status' => '3');
if($this->db->insert('customer_vehicle',$insert_array)){ function changeCustomerCarStatus($customer_id = '', $customer_veh_id = '', $status = ''){
$last_id = $this->db->insert_id(); if(empty($customer_id) || empty($customer_veh_id) || $status == ''){
return 0;
}
$book_data = array( $upStatus = $this->db->update('customer_vehicle',
'customer_veh_id' => $last_id, array('status'=>$status),
'customer_id' => $postData['customer_id'], array('customer_id'=>$customer_id,'customer_veh_id'=>$customer_veh_id));
'mechanic_id' => $postData['mechanic_id'],
'scheduled_date' => $postData['schedule_date']['date'],
'scheduled_time' => $postData['schedule_date']['time'],
'mileage' => $vehData['milage'],
'status' => '0');
if($this->db->insert('bookings',$book_data)){ return $upStatus;
return 1;
}
}
return 0;
} }
} }
?> ?>
\ No newline at end of file
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