Files
liche/api/libraries/liche/Progressopt.php
T
2022-01-05 15:47:05 +08:00

229 lines
12 KiB
PHP

<?php
/**
* 狸车我的购车流程
*/
class Progressopt{
private $ci;
private $progress_arr = [
[
"id" => 1,
"title"=>"合同签订",
"icon"=>"icon-qiandinghetong",
"key" => 0,
"state"=>2//0未开启/1已开启/2当前开启
],
[
"id" => 2,
"title"=>"定金支付",
"icon"=>"icon-yijiaodingjin",
"key" => 0,
"state"=>0
],
[
"id" => 3,
"title"=>"按揭办理",
"icon"=>"icon-banlianjie",
"key" => 1,
"state"=>0
],
[
"id" => 4,
"title"=>"配车准备",
"icon"=>"icon-peichezhunbei",
"key" => 2,
"state"=>0
],
[
"id" => 5,
"title"=>"车辆确认",
"icon"=>"icon-cheliangqueren",
"key" => 2,
"state"=>0
],
[
"id" => 6,
"title"=>"发票开具",
"icon"=>"icon-yikaifapiao",
"key" => 3,
"state"=>0
],
[
"id" => 7,
"title"=>"保险上牌",
"icon"=>"icon-baoxianshangpai",
"key" => 4,
"state"=>0
],
[
"id" => 8,
"title"=>"恭喜提车",
"icon"=>"icon-gongxitiche",
"key" => 5,
"state"=>0
],
];
public function __construct(){
$this->ci = & get_instance();
$this->ci->load->model('receiver/order/receiver_orders_model','orders_model');
$this->ci->load->model('receiver/order/receiver_order_signs_model');
$this->ci->load->model('receiver/order/receiver_order_contracts_model');
$this->ci->load->model('receiver/order/receiver_order_loans_model');
$this->ci->load->model('receiver/order/receiver_order_ckcars_model');
$this->ci->load->model('receiver/order/receiver_order_deliverys_model');
$this->ci->load->model('receiver/order/receiver_order_oplogs_model');
$this->ci->load->library('receiver/orders_entity');
}
//获取狸车用户进度列表
public function lists($mobile){
if(!$mobile){
return [];
}
$where = [
'status>=' => 0,
'status<' => 6,
'brand_id>' => 0,
"(mobile='{$mobile}' or (ifentrust=1 and json_extract(info_json,'$.entrust_mobile')='{$mobile}'))" => null
];
$rows = $this->ci->orders_model->select($where,'id asc','','','id,name,payway,money_json,status,s_id,v_id,cor_id,incor_id,srv_ids,jsondata,price');
$progress_list = [];
if($rows){
foreach($rows as $order){
$progress = $progressOpt = [];
$progress_arr = $this->progress_arr;
if($order['payway']) unset($progress_arr[2]); //全款移除贷款步骤
$sign_row = $this->ci->receiver_order_signs_model->get(['o_id'=>$order['id']],'status');
$ckcar_row = $this->ci->receiver_order_ckcars_model->get(['o_id'=>$order['id']],'status');
$delivery_row = $this->ci->receiver_order_deliverys_model->get(['o_id'=>$order['id']],'status');
$sign_count = $this->ci->receiver_order_contracts_model->count(['o_id'=>$order['id'],'type in (0,1,4,5)','status'=>1]);
$car_count = $this->ci->receiver_order_contracts_model->count(['o_id'=>$order['id'],'type' => 4,'status'=>1]); //合同补充协议
$agent_count = $this->ci->receiver_order_contracts_model->count(['o_id'=>$order['id'],'type' => 5,'status'=>1]); //服务补充协议
$opt_row = $this->ci->receiver_order_oplogs_model->select(['order_id'=>$order['id'],'type'=>3],'id desc',1,1);//最后修改日志
$opt_row = json_decode($opt_row[0]['log_json'],true);
$opt_money_json = json_decode($opt_row['money_json'],true);
$opt_jsondata = json_decode($opt_row['jsondata'],true);
$money_json = json_decode($order['money_json'],true);
$jsondata = json_decode($order['jsondata'],true);
$progressOpt = [];
foreach($progress_arr as $item){
$imgs = [];
if($order['status']>$item['key']){
if($item['key']==0 && $item['id']==1){
$imgs = $this->ci->orders_entity->get_sign_imgs($order['id'],[0,1,4,5]);
}
if($item['key']==2 && $item['id']==5){
$imgs = $this->ci->orders_entity->get_sign_imgs($order['id'],[2]);
}
$state = 1;
}elseif($order['status']==$item['key']){
switch($item['key']){
case 0:
$state = 0;
if(!$sign_row['status']){//未签名
if($sign_count>=2){ //需要签补充协议
if($opt_row['s_id']!=$order['s_id'] || $opt_row['v_id']!=$order['v_id'] || $opt_row['cor_id']!=$order['cor_id'] || $opt_row['incor_id']!=$order['incor_id'] || $opt_row['payway']!=$order['payway'] || $money_json['price_discount']!=$opt_money_json['price_discount'] ||$opt_row['price'] != $order['price']){
$need_resign_car = true; //需要签合同补充协议
}
if($opt_row['srv_ids']!=$order['srv_ids']){
$need_resign_agent = true; //需要签服务补充协议
}
//修改精品
if($jsondata['if_fine']!=$opt_jsondata['if_fine']){
$need_resign_agent = true; //需要签服务补充协议
}
if($money_json['fee_carno'] != $opt_money_json['fee_carno']){ //修改挂牌费
$need_resign_agent = true;
}
if($jsondata['if_fine'] && $opt_jsondata['if_fine']){
$price_fine = $money_json['price_fine_discount'] ? $money_json['fine_price'] - $money_json['price_fine_discount'] : $money_json['fine_price'];
$opt_price_fine = $opt_money_json['price_fine_discount'] ? $opt_money_json['fine_price'] - $opt_money_json['price_fine_discount'] : $opt_money_json['fine_price'];
if($price_fine!=$opt_price_fine){
$need_resign_agent = true; //需要签服务补充协议
}
}
if($need_resign_agent && !$agent_count){
$url = '/pages/mine/signContract/weiTuoBu?id='.$order['id'];
}
if($need_resign_car && !$car_count){
$url = '/pages/mine/signContract/maiMaiBu?id='.$order['id'];
}
}elseif($sign_count==1){
$url = '/pages/mine/signContract/daiLi?id='.$order['id'];
if($opt_row){ //修改内容
if($opt_row['s_id']!=$order['s_id'] || $opt_row['v_id']!=$order['v_id'] || $opt_row['cor_id']!=$order['cor_id'] || $opt_row['incor_id']!=$order['incor_id'] || $opt_row['payway']!=$order['payway'] || $money_json['price_discount']!=$opt_money_json['price_discount'] || $opt_row['price'] !== $order['price']){
$url = '/pages/mine/signContract/maiMaiBu?id='.$order['id'];//需要签合同补充协议
}
}
}else{
$url = '/pages/mine/signContract/zhengChe?id='.$order['id'];
}
$progressOpt = ['title'=> '合同签订','url'=>$url];
$item['id']== 1 && $state = 2;
}else{ //已签约
if($sign_row['status']==1){//未交定金
if($item['id']==1){
$imgs = $this->ci->orders_entity->get_sign_imgs($order['id'],['0,1']);
$state = 1;
}else{
$state = 2;
}
$progressOpt = ['title'=> '交定金','url'=>'/pages/mine/carOrder/index?oid='.$order['id']];
}else{ //已交定金
$state = 1;
}
}
break;
case 2: //车辆确认
if($ckcar_row['status']){
if($item['id']==5){
$state = 2;
if($ckcar_row['status']==2){ //未支付
$title = $order['payway'] ? '去支付尾款' : '去支付首付';
$progressOpt = ['title'=> $title,'url'=>'/pages/mine/carOrder/index?oid='.$order['id']];
}else{
$progressOpt = ['title'=> '确认车辆','url'=>'/pages/mine/signContract/queRen?id='.$order['id']];
}
}else{
$state = 1;
}
}else{
$state = $item['id'] == 4 ? 2:0;
}
break;
case 5: //交付确认
$state = 2;
if($delivery_row['status']==2){
$imgs = $this->ci->orders_entity->get_sign_imgs($order['id'],[3]);
}elseif($delivery_row['status']==1){
$progressOpt = ['title'=> '交接车辆','url'=>'/pages/mine/signContract/jiaoJie?id='.$order['id']];
}
break;
default:
$state = 2;
}
}else{
$state = 0;
}
$progress[] = [
'title' => $item['title'],
'icon' => $item['icon'],
'state' => $state,
'imgs' => $imgs
];
}
$progress_list[] = [
'title' => count($rows)>1 ? $order['name'] : '',
'progressOpt' => $progressOpt,
'progress' => $progress
];
}
}
return $progress_list;
}
}