Commit 3e57f196 by Jansa Jose

Merge branch 'master' into 'dev_production'

Master See merge request !155
parents 9061518e 22098448
<?php
defined('BASEPATH')OR exit('No direct script access allowed');
defined('BASEPATH') OR exit('No direct script access allowed');
header('Content-Type: text/html; charset=utf-8');
if(isset($_SERVER['HTTP_ORIGIN'])) {
......@@ -1273,7 +1273,7 @@
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$postData['customer_id'] = $authRes['data'];
$postData['customer_id'] = $authRes['data']['customer_id'];
$result = $this->Webservice_model->rate_mechanic($postData);
echo json_encode($result);exit;
}
......@@ -1430,6 +1430,12 @@
}
send_mail($subject,$email_id,$message);
}
$fcm_data = $this->Webservice_model->getfcmData($ref,$mobile);
if($fcm_data['status'] == "success"){
$fcm_data['data']['title'] = "CarFixxers";
$fcm_data['data']['message'] = "A New Service Available";
$this->push_sent_cancel($fcm_data['data']);
}
if($mobile == '1'){
redirect('Webservices/mobPaySuccess');
} else {
......@@ -1443,6 +1449,28 @@
}
}
}
public function push_sent_cancel($fcm_data=array()) {
$settings = getSettings();
$key = $settings['app_id'];
if(empty($key) || empty($fcm_data)){
return;
}
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"service_id\" : \"".$fcm_data['booking_id']."\", \"type\" : \"".$fcm_data['service_type']."\"}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_data['device_id']."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
//Search Products
public function productSearch(){
header('Content-type:application/json');
......@@ -2705,5 +2733,40 @@
}
echo json_encode($respArr);exit;
}
public function forgot_password(){
header('Content-Type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
if(!isset($postData['email']) || empty($postData['email'])){
$respArr['status'] = "error";
$respArr['message'] = "Email Id is Required";
echo json_encode($respArr);exit;
}
$respArr = $this->Webservice_model->forgot_password($postData['email']);
echo json_encode($respArr);exit;
}
public function change_password(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
if(!isset($postData['email']) || empty($postData['email'])){
$respArr['status'] = "error";
$respArr['message'] = "Email Id is Required";
echo json_encode($respArr);exit;
}
else if(!isset($postData['password']) || empty($postData['password'])){
$respArr['status'] = "error";
$respArr['message'] = "Password is Required";
echo json_encode($respArr);exit;
}
$respArr = $this->Webservice_model->change_password($postData);
echo json_encode($respArr);exit;
}
}
?>
......@@ -151,7 +151,7 @@
$postData = json_decode($post, true);
$postData['mechanic_id'] = $authRes['data']['mechanic_id'];
$bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,0,3);
$bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,0,3);
$bookDataResult=$this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,0,3);
$total = 0;
if($bookDataCount['status'] == 'success'){
$total = count($bookDataCount['data']);
......
......@@ -113,6 +113,9 @@ class Booking_model extends CI_Model {
$bookDetails = array();
$bookData = $bookData->result();
foreach($bookData AS $book) {
if(empty($book->scheduled_date) || empty($book->scheduled_time)){
continue;
}
$bookMechData=$this->db->query("SELECT * FROM mechanic_booking
WHERE booking_id='$book->booking_id' AND status!='2'");
if(!empty($bookMechData)){
......
......@@ -86,7 +86,7 @@ public function getBookedService($postData = array(),$start = '',$per_page = '',
// $where['BUK.scheduled_date'] = date("Y-m-d", strtotime('tomorrow'));
// }
$this->db->select("BUK.scheduled_date as date,BUK.scheduled_time as time,BUK.booking_id as service_id,BUK.status,CSTVEH.car_name,BUK.mileage,BUK.issues_selected,BUK.custom_issue_data,BUK.service_type as type,MCHBUK.amount as total_amount,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,CUST.phone as phone_number,CSTVEH.vehicle_data,CSTVEH.car_loc_lat as cust_lat,CSTVEH.car_loc_lng as cust_lng,CSTVEH.car_location as cust_address");
$this->db->select("BUK.scheduled_date as date,BUK.scheduled_time as time,BUK.booking_id as service_id,BUK.status,CSTVEH.car_name,BUK.mileage,BUK.issues_selected,BUK.custom_issue_data,BUK.service_type as type,MCHBUK.amount,BUK.cost,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,CUST.phone as phone_number,CSTVEH.vehicle_data,CSTVEH.car_loc_lat as cust_lat,CSTVEH.car_loc_lng as cust_lng,CSTVEH.car_location as cust_address");
$this->db->from('bookings as BUK');
$this->db->join('customers as CUST','CUST.customer_id = BUK.customer_id');
$this->db->join('customer_vehicle as CSTVEH','CSTVEH.customer_veh_id = BUK.customer_veh_id');
......@@ -97,15 +97,22 @@ public function getBookedService($postData = array(),$start = '',$per_page = '',
if($start != 0 || $per_page != 0){
$this->db->limit($per_page,$start);
}
$this->db->order_by('BUK.booking_id','DESC');
$bookData = $this->db->get();
if(!empty($bookData) && $bookData->num_rows() > 0){
$bookData = $bookData->result_array();
foreach ($bookData as $key => $value) {
$issues_selected = json_decode($value['issues_selected']);
$custom_issue_data = json_decode($value['custom_issue_data']);
$bookData[$key]['service_image'] = $custom_issue_data->optionalImages;
$bookData[$key]['service_message'] = $custom_issue_data->optionlaDescription;
unset($bookData[$key]['issues_selected'],$bookData[$key]['custom_issue_data']);
$bookData[$key]['trim'] = json_decode($value['vehicle_data'])->trim;
$bookData[$key]['engine_no'] = json_decode($value['vehicle_data'])->engine;
$bookData[$key]['service_image'] = (isset($custom_issue_data->optionalImages))?$custom_issue_data->optionalImages:[];
$bookData[$key]['service_message'] = (isset($custom_issue_data->optionlaDescription))?$custom_issue_data->optionlaDescription:'';
$bookData[$key]['total_amount'] = ($value['type'] == '1')?$value['amount']:$value['cost'];
unset($bookData[$key]['issues_selected'],$bookData[$key]['custom_issue_data'],$bookData[$key]['amount'],$bookData[$key]['cost']);
if(!empty($issues_selected)){
$new = array();
foreach ($issues_selected as $issue_key => $issue_value) {
$sql = "SELECT IC.*, MI.custom_description, MI.custom_service_fee
......@@ -127,6 +134,7 @@ public function getBookedService($postData = array(),$start = '',$per_page = '',
$bookData[$key]['service_name'] = $new;
}
}
}
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data'] = $bookData;
......@@ -177,7 +185,7 @@ public function start_service($postData = array(),$type = 0){
return $respArr;
}
$status = ($type == '1')?3:6;
$cost = ($postData['emergency'] == '2')?$postData['amount']:'';
$cost = ($postData['emergency'] == '2')?$postData['amount']:0;
if($this->db->update('bookings',array('service_type'=>$postData['emergency'],'cost'=>$cost,'status'=>$status),array('booking_id'=>$postData['service_id']))){
$respArr['status'] = "success";
$respArr['message'] = ($type == '1')?"Service Completed Successfully":"Service Started Successfully";
......
......@@ -162,15 +162,19 @@ 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,bookings.cost,TRIM(concat(mechanic.first_name,' ',IFNULL(mechanic.last_name,''))) as mechanic_name,mechanic.address,mechanic.phone,mechanic.mechanic_id");
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,mechanic_shop.
shop_name,bookings.car_location as user_loc,bookings.car_loc_lat as user_lat,bookings.car_loc_lng as user_lng");
$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_booking","mechanic_booking.booking_id = bookings.booking_id");
$this->db->join("mechanic","mechanic_booking.mechanic_id = mechanic.mechanic_id");
$this->db->where('scheduled_date >',date('Y-m-d h:i'));
$this->db->join("mechanic_shop","mechanic_shop.shop_id = mechanic.shop_id","left");
// $this->db->where('scheduled_date >',date('Y-m-d h:i'));
$this->db->where('bookings.status !=','0');
if($start != 0 || $per_page != 0){
$this->db->limit($per_page,$start);
}
$this->db->group_by('id');
$this->db->order_by('id','DESC');
$bookData = $this->db->get_where('bookings',$where)->result_array();
$respArr['status'] = 'success';
$respArr['message'] = 'success';
......@@ -335,12 +339,19 @@ class Webservice_model extends CI_Model {
$date =(isset($postData['is_emergency']) && !empty($postData['is_emergency']))?date('Y-m-d'):date('Y-m-d',$postData['date']/1000);
$time = (isset($postData['is_emergency']) && !empty($postData['is_emergency']))?date('h:i A'):$postData['time'];
$cost = (isset($postData['is_emergency']) && !empty($postData['is_emergency']))?0:$postData['total_cost'];
$car_location = (isset($postData['location']) && !empty($postData['location']))?$postData['location']:'';
$car_loc_lat = (isset($postData['location_lat']) && !empty($postData['location_lat']))?$postData['location_lat']:'';
$car_loc_lng = (isset($postData['location_lng']) && !empty($postData['location_lng']))?$postData['location_lng']:'';
$insert_array = array(
'cost'=>$cost,
'scheduled_date'=>$date,
'scheduled_time'=>$time,
'issues_selected'=>$issues,
'service_type'=>(isset($postData['is_emergency']) && !empty($postData['is_emergency']))?2:1
'service_type'=>(isset($postData['is_emergency']) && !empty($postData['is_emergency']))?2:1,
'status'=>(isset($postData['is_emergency']) && !empty($postData['is_emergency']))?1:5,
'car_location'=> $car_location,
'car_loc_lat'=>$car_loc_lat,
'car_loc_lng'=>$car_loc_lng
);
if($this->db->update('bookings',$insert_array,array('booking_id'=>$postData['booking_id']))){
$this->db->insert("mechanic_booking",array('booking_id'=>$postData['booking_id'],'mechanic_id'=>$postData['mechanic_id'],'amount'=>$cost,'status'=>'0'));
......@@ -451,6 +462,24 @@ class Webservice_model extends CI_Model {
if(empty($mechData) || empty($mechData = $mechData->result_array())){
return 0;
}
foreach ($mechData as $key => $value) {
$mechData[$key]['distance'] = round((float)$value['distance'],2);
$mechData[$key]['review'] = [];
$this->db->order_by('id','DESC');
$this->db->limit('2','0');
$mechRvw = $this->db->get_where('mechanic_rating',array('mechanic_id'=>$value['mechanic_id'],'status'=>'1'));
if(!empty($mechRvw) && !empty($mechRvw = $mechRvw->result_array())){
$mechData[$key]['review'] = $mechRvw;
}
$rating = $this->db->query("SELECT COUNT(id) AS count, round(AVG(rate),2) AS rating
FROM mechanic_rating
WHERE mechanic_id='".$value['mechanic_id']."'");
if(!empty($rating) && !empty($rating = $rating->row_array())){
$mechData[$key]['total_review'] = (empty($rating['count']))?'0':$rating['count'];
$mechData[$key]['avg_rate'] = (empty($rating['rating']))?'0':$rating['rating'];
}
}
if($type == 0){
$respArr = $this->getNearMechanicsDetails($mechData,$issue_cat_id);
if($respArr['status'] == 'success'){
......@@ -478,10 +507,10 @@ 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';
// $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
......@@ -504,7 +533,7 @@ class Webservice_model extends CI_Model {
$sIssueData[$sIndex]['service_fee'] = $sIssue['default_service_fee'];
}
}
$mechData[$index]['rating'] = $rating;
//$mechData[$index]['rating'] = $rating;
$mechData[$index]['estimate'] = $estimate;
$mechData[$index]['sub_issues'] = $sIssueData;
$mechData[$index]['scheduleTiming'] = $scheduleTiming;
......@@ -574,7 +603,7 @@ class Webservice_model extends CI_Model {
return $respArr;
}
public function rate_mechanic($auth,$postData){
public function rate_mechanic($postData){
$respArr = array('status'=>'error','message'=>'Something went Wrong.. Try Again');
if(empty($postData['rate'])){
$respArr['message'] = 'Rating is Required';
......@@ -588,8 +617,12 @@ class Webservice_model extends CI_Model {
$respArr['message'] = 'Description is Required';
return $respArr;
}
if(empty($postData['title'])){
$respArr['message'] = 'Title 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())){
if(!empty($mechRate) && !empty($mechRate = $mechRate->row_array())){
$respArr['message'] = 'Sorry, You are already Rated for this mechanic';
return $respArr;
}
......@@ -1093,7 +1126,7 @@ class Webservice_model extends CI_Model {
}
$postData['datetime'] = date('Y-m-d h:i:s');
$result = $this->db->get_where('product_rating',array('product_id'=>$postData['product_id'],'customer_id'=>$postData['customer_id']));
if(!empty($result) && $result->num_rows > 0 && !empty($result = $result->row())){
if(!empty($result) || $result->num_rows > 0 || !empty($result = $result->row())){
$respArr['status'] = 'error';
$respArr['message'] = 'Sorry Your are Already Rated for this Product';
return $respArr;
......@@ -1195,8 +1228,8 @@ class Webservice_model extends CI_Model {
$lmt .= "LIMIT $start,$per_page";
}
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.product_name,PRD.short_description,PRD.part_id,TRANS.id AS transId,
TRANS.status AS tranStatus,TRANS.datetime,ORD.*,PI.image as product_image,BRND.brand_name
COUNT(REV.id) AS reviews,PRD.product_name,PRD.short_description,PRD.part_id,TRANS.id AS transId,TRANS.status AS tranStatus,TRANS.datetime,ORD.*,
PI.image as product_image,BRND.brand_name
FROM orders ORD
JOIN products PRD ON ORD.product_id = PRD.product_id
JOIN transaction TRANS ON (ORD.order_id = TRANS.booking_id AND TRANS.payment_for= '2')
......@@ -1244,8 +1277,7 @@ class Webservice_model extends CI_Model {
$lmt .= "LIMIT $start,$per_page";
}
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.product_name,PRD.short_description,PRD.part_id,CRT.cart_id,CRT.quantity
,CRT.product_id,PI.image as product_image,BRND.brand_name,PRD.amount
COUNT(REV.id) AS reviews,PRD.product_name,PRD.short_description,PRD.part_id,CRT.cart_id,CRT.quantity,CRT.product_id,PI.image as product_image,BRND.brand_name,PRD.amount
FROM cart CRT
JOIN products PRD ON CRT.product_id = PRD.product_id
JOIN product_brand BRND ON BRND.brand_id = PRD.brand_id
......@@ -1509,11 +1541,56 @@ class Webservice_model extends CI_Model {
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())){
$review = $this->db->get_where('mechanic_rating',array('mechanic_id'=>$postData['mechanic_id'],'mechanic_rating.status'=>'1'));
if(!empty($review) && !empty($reviewData = $review->result_array())){
foreach ($reviewData as $key => $value) {
$reviewData[$key]['rate'] = (float)$value['rate'];
}
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data']= $reviewData;
$respArr['data'] = $reviewData;
}
return $respArr;
}
public function getfcmData($transId,$mobile){
$respArr = array('status'=>'error');
$this->db->select('bookings.service_type,bookings.booking_id,mechanic.device_id');
$this->db->join('bookings','bookings.booking_id = transaction.booking_id');
if($mobile == '1'){
$this->db->join("mechanic_booking","mechanic_booking.booking_id = bookings.booking_id");
$this->db->join('mechanic','mechanic_booking.mechanic_id = mechanic.mechanic_id');
}else{
$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 AND mechanic_booking.status='1'");
}
$result = $this->db->get_where('transaction',array('transaction.id'=>$transId,'transaction.payment_for'=>'1'))->row_array();
if($result){
$respArr['status'] = "success";
$respArr['data'] = $result;
}
return $respArr;
}
public function forgot_password($email){
$respArr = array('status'=>'error','message'=>'Invalid Email Id');
$custData = $this->db->get_where('customers',array('email'=>$email));
if(!empty($custData) && $custData->num_rows() > 0 && !empty($custData = $custData->row_array())){
$respArr['status'] = "success";
$respArr['data']['phone_number'] = $custData['phone'];
$respArr['data']['email'] = $custData['email'];
}
return $respArr;
}
public function change_password($postData = array()){
$respArr= array('status'=>'error','message'=>'Invalid Email Id');
$custData = $this->db->get_where('customers',array('email'=>$postData['email']));
if(!empty($custData) && $custData->num_rows() > 0 && !empty($custData = $custData->row_array())){
if($this->db->update('customers',array('password'=>md5($postData['password'])),array('customer_id'=>$custData['customer_id']))){
$respArr['status'] = "success";
$respArr['message'] = "Password Changed Successfully";
}
}
return $respArr;
}
......
......@@ -95,6 +95,10 @@
<label>Web Url</label>
<input type="text" name="web_url" class="form-control required" placeholder="Enter Web Url" value="<?= $data['web_url'] ?>">
</div>
<div class="form-group col-xs-4">
<label>App Id</label>
<input type="text" name="app_id" class="form-control required" placeholder="Enter App Id" value="<?= $data['app_id'] ?>">
</div>
</div>
</div>
<div class="box-footer" style="padding-left:46%">
......
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