edit-api-user_orders

This commit is contained in:
lccsw
2021-11-15 17:57:42 +08:00
parent a452cb0470
commit 8166b547e1
6 changed files with 244 additions and 233 deletions
+8 -174
View File
@@ -198,178 +198,9 @@ class User extends Wxapp{
* @return array
*/
protected function get_my(){
$this->load->library('liche/progressopt');
$mobile = $this->session['mobile'];
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$this->load->model('receiver/order/receiver_order_signs_model');
$this->load->model('receiver/order/receiver_order_contracts_model');
$this->load->model('receiver/order/receiver_order_loans_model');
$this->load->model('receiver/order/receiver_order_ckcars_model');
$this->load->model('receiver/order/receiver_order_deliverys_model');
$this->load->model('receiver/order/receiver_order_oplogs_model');
$row = $this->orders_model->get_step($mobile);
$progressOpt = $progress = [];
if($row){
$progressOpt = [];
$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
],
];
if($row['payway']){ //全款
unset($progress_arr[2]);
}
$progress = [];
$sign_row = $this->receiver_order_signs_model->get(['o_id'=>$row['id']],'status');
$ckcar_row = $this->receiver_order_ckcars_model->get(['o_id'=>$row['id']],'status');
$delivery_row = $this->receiver_order_deliverys_model->get(['o_id'=>$row['id']],'status');
$sign_count = $this->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1,4,5)','status'=>1]);
$car_count = $this->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type' => 4,'status'=>1]); //合同补充协议
$agent_count = $this->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type' => 5,'status'=>1]); //服务补充协议
$opt_row = $this->receiver_order_oplogs_model->select(['order_id'=>$row['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);
$money_json = json_decode($row['money_json'],true);
$this->load->library('receiver/orders_entity');
foreach($progress_arr as $key=>$val){
$imgs = [];
if($row['status']>$val['key']){
if($val['key']==0 && $val['id']==1){
$imgs = $this->orders_entity->get_sign_imgs($row['id'],[0,1,4,5]);
}
if($val['key']==2 && $val['id']==5){
$imgs = $this->orders_entity->get_sign_imgs($row['id'],[2]);
}
$state = 1;
}elseif($row['status']==$val['key']){
switch($val['key']){
case 0:
$state = 0;
if(!$sign_row['status']){//未签名
if($sign_count>=2){ //需要签补充协议
if($opt_row['s_id']!=$row['s_id'] || $opt_row['v_id']!=$row['v_id'] || $opt_row['cor_id']!=$row['cor_id'] || $opt_row['incor_id']!=$row['incor_id'] || $opt_row['payway']!=$row['payway'] || $money_json['price_discount']!=$opt_money_json['price_discount']){
$need_resign_car = true; //需要签合同补充协议
}
if($opt_row['srv_ids']!=$row['srv_ids']){
$need_resign_agent = true; //需要签服务补充协议
}
if($need_resign_car && !$car_count){
$url = '/pages/mine/signContract/maiMaiBu?id='.$row['id'];
}elseif($need_resign_agent && !$agent_count){
$url = '/pages/mine/signContract/weiTuoBu?id='.$row['id'];
}
}elseif($sign_count==1){
$url = '/pages/mine/signContract/daiLi?id='.$row['id'];
}else{
$url = '/pages/mine/signContract/zhengChe?id='.$row['id'];
}
$progressOpt = ['title'=> '合同签订','url'=>$url];
$val['id']== 1 && $state = 2;
}else{ //已签约
if($sign_row['status']==1){//未交定金
if($val['id']==1){
$imgs = $this->orders_entity->get_sign_imgs($row['id'],['0,1']);
$state = 1;
}else{
$state = 2;
}
$progressOpt = ['title'=> '交定金','url'=>'/pages/mine/carOrder/index'];
}else{ //已交定金
$state = 1;
}
}
break;
case 2: //车辆确认
if($ckcar_row['status']){
if($val['id']==5){
$state = 2;
if($ckcar_row['status']==2){ //未支付
$title = $row['payway'] ? '去支付尾款' : '去支付首付';
$progressOpt = ['title'=> $title,'url'=>'/pages/mine/carOrder/index'];
}else{
$progressOpt = ['title'=> '确认车辆','url'=>'/pages/mine/signContract/queRen?id='.$row['id']];
}
}else{
$state = 1;
}
}else{
$state = $val['id'] == 4 ? 2:0;
}
break;
case 5: //交付确认
$state = 2;
if($delivery_row['status']==2){
$imgs = $this->orders_entity->get_sign_imgs($row['id'],[3]);
}elseif($delivery_row['status']==1){
$progressOpt = ['title'=> '交接车辆','url'=>'/pages/mine/signContract/jiaoJie?id='.$row['id']];
}
break;
default:
$state = 2;
}
}else{
$state = 0;
}
$progress[] = [
'title' => $val['title'],
'icon' => $val['icon'],
'state' => $state,
'imgs' => $imgs
];
}
}
$about = [
['title'=>'购车订单','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-5.png','url'=>'/pages/mine/carOrder/index'],
['title'=>'我的爱车','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-1.png','url'=>'/pages/mine/myCar/index'],
@@ -378,9 +209,11 @@ class User extends Wxapp{
if($this->session['dealer'] || $this->session['manage']){
$about[] = ['title'=>'推广提现','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-4.png','url'=>'/pages/distribute/index'];
}
$progress_list = $this->progressopt->lists($mobile);
$data = [
'progressOpt' => $progressOpt,
'progress' => $progress,
//'progressOpt' => $progressOpt,
//'progress' => $progress,
'progress_list' => $progress_list,
'about' => $about,
'order' => [
['title' => '全部订单', 'icon' => 'https://qs.haodian.cn/wechat_app/liche/mine/order-icon-1.png', 'url' => '/pages/order/index?typeId=0'],
@@ -399,9 +232,10 @@ class User extends Wxapp{
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 10;
$mobile = $this->session['mobile'];
$where = [
"mobile" => $this->session['mobile'],
"(mobile={$mobile} or (ifentrust=1 and json_extract(info_json,'$.entrust_mobile')='{$mobile}'))" => null,
"status" => 6,
];
$count = $this->orders_model->count($where);
+16 -11
View File
@@ -101,7 +101,7 @@ class Cusorder extends Wxapp{
}
//判断是否存在未完成流程
$omobile = $mobile ? $mobile : $row['mobile'];
$o_order = $this->orders_model->get_step($omobile);
$o_order = $this->orders_model->get(['mobile'=>$omobile,'status>='=>0,'status<'=>6]);
if($o_order){
$this->orders_model->update(['status'=>-1],['id'=>$o_order['id']]);
// throw new Exception('该手机号用户存在未完成订单', API_CODE_FAIL);
@@ -110,17 +110,22 @@ class Cusorder extends Wxapp{
if(!$car_row){
throw new Exception('参数错误', API_CODE_FAIL);
}
$total_dis_money = $disc_money; //优惠金额包含精品
if(is_array($fine_ids) && $fine_ids){
$fine_id_str = implode(',',$fine_ids);
$fine_rows = $this->receiver_fine_model->select(["id in ({$fine_id_str})" => null],'','','','id,price');
foreach($fine_rows as $item){
$total_dis_money += $item['price'];
$can_dis_money = $car_row['price_car'] - $car_row['price_floor']; //优惠金额
if($can_dis_money>0){
if(is_array($fine_ids) && $fine_ids){
$fine_id_str = implode(',',$fine_ids);
$fine_rows = $this->receiver_fine_model->select(["id in ({$fine_id_str})" => null],'','','','id,price');
foreach($fine_rows as $item){
$total_dis_money += $item['price'];
}
}
if($disc_money && $car_row['price_floor'] > $price-$total_dis_money){
throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL);
}
}else{
if($disc_money) throw new Exception('当前车型没有优惠额度', API_CODE_FAIL);
}
if($disc_money && $car_row['price_floor'] > $price-$total_dis_money){
throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL);
}
$total_dis_money = $disc_money; //总优惠金额包含精品
if(!$payway){ //分期
$finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]);
if(!$finance_row){
@@ -222,7 +227,7 @@ class Cusorder extends Wxapp{
$this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]);
$this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单");
return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_PAY_IMG];
return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_CREATE_PAY_IMG];
}else{
throw new Exception('创建失败', ERR_PARAMS_ERROR);
}
+16 -11
View File
@@ -64,7 +64,7 @@ class Cusorder2 extends Wxapp{
}
//判断是否存在未完成流程
$omobile = $mobile ? $mobile : $row['mobile'];
$o_order = $this->orders_model->get_step($omobile);
$o_order = $this->orders_model->get(['mobile'=>$omobile,'status>='=>0,'status<'=>6]);
if($o_order){
$this->orders_model->update(['status'=>-1],['id'=>$o_order['id']]);
}
@@ -117,7 +117,7 @@ class Cusorder2 extends Wxapp{
$userinfo = $this->app_liche_users_model->get(['mobile'=>$data['mobile']]);
$orders_entity->c_intention($o_id,$userinfo,$inten_money);
}
return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_PAY_IMG];
return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_CREATE_PAY_IMG];
}
//修改订单信息
@@ -151,16 +151,21 @@ class Cusorder2 extends Wxapp{
throw new Exception('请选择代办项目', ERR_PARAMS_ERROR);
}
}
$total_dis_money = $disc_money; //优惠金额包含精品
if(is_array($fine_ids) && $fine_ids){
$fine_id_str = implode(',',$fine_ids);
$fine_rows = $this->receiver_fine_model->select(["id in ({$fine_id_str})" => null],'','','','id,price');
foreach($fine_rows as $item){
$total_dis_money += $item['price'];
$can_dis_money = $car_row['price_car'] - $car_row['price_floor']; //优惠金额
if($can_dis_money>0){
$total_dis_money = $disc_money; //总优惠金额包含精品
if(is_array($fine_ids) && $fine_ids){
$fine_id_str = implode(',',$fine_ids);
$fine_rows = $this->receiver_fine_model->select(["id in ({$fine_id_str})" => null],'','','','id,price');
foreach($fine_rows as $item){
$total_dis_money += $item['price'];
}
}
}
if($disc_money && $car_row['price_floor'] > $car_row['price_car']-$total_dis_money){
throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL);
if($disc_money && $car_row['price_floor'] > $car_row['price_car']-$total_dis_money){
throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL);
}
}else{
if($disc_money) throw new Exception('当前车型没有优惠额度', API_CODE_FAIL);
}
if(!$payway){ //分期
$finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]);
+201
View File
@@ -0,0 +1,201 @@
<?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){
$where = [
'status>=' => 0,
'status<' => 6,
"(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');
$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);
$money_json = json_decode($order['money_json'],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']){
$need_resign_car = true; //需要签合同补充协议
}
if($opt_row['srv_ids']!=$order['srv_ids']){
$need_resign_agent = true; //需要签服务补充协议
}
if($need_resign_car && !$car_count){
$url = '/pages/mine/signContract/maiMaiBu?id='.$order['id'];
}elseif($need_resign_agent && !$agent_count){
$url = '/pages/mine/signContract/weiTuoBu?id='.$order['id'];
}
}elseif($sign_count==1){
$url = '/pages/mine/signContract/daiLi?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'];
}else{ //已交定金
$state = 1;
}
}
break;
case 2: //车辆确认
if($ckcar_row['status']){
if($item['id']==5){
$state = 2;
if($ckcar_row['status']==2){ //未支付
$title = $row['payway'] ? '去支付尾款' : '去支付首付';
$progressOpt = ['title'=> $title,'url'=>'/pages/mine/carOrder/index'];
}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;
}
}
+2 -1
View File
@@ -9,7 +9,8 @@ class Orders_entity{
const PRICE_FINANCE = 1000; //金融服务费写死
const PRICE_FINANCE_NZ = 2000; //哪吒金融服务费
const API_ADMIN_IMG = 'https://img.liche.cn/liche/2021/08/7725fc9ab0dc0ba1/f3c84cf3b805bac4.png'; //api 客服二维码
const API_PAY_IMG = 'https://img.liche.cn/liche/1634022931.png'; //api 跳转支付二维码
const API_PAY_IMG = 'https://img.liche.cn/liche/1634022931.png'; //api 意向金跳转支付二维码
const API_CREATE_PAY_IMG = 'https://img.liche.cn/liche/2021/11/65b34b962f5f06b3/62e7d28d77bfe404.png'; //api 创建订单跳转支付二维码
private $ci;
private $order_row;
@@ -49,42 +49,7 @@ class Receiver_orders_model extends HD_Model
}
return $return_status;
}
public function get_step($mobile)
{
//$t1 = 'lc_receiver_orders';
//$this->db->select("$t1.*");
//$this->db->from($t1);
//$where = [
// "$t1.mobile" => $mobile,
// "$t1.status<" => 6,
// "$t1.status>=" => 0,
// "$t1.brand_id>" => 0
//];
//$this->db->where($where);
//$this->db->order_by("$t1.id desc");
//$this->db->limit(1);
//$row = $this->db->get()->row_array();
$where = [
'mobile' => $mobile,
'status>=' => 0,
'status<' => 6,
'brand_id>' => 0
];
$row = $this->select($where,'id desc',1,1);
if(!$row){ //本人不存在订单 代办订单
$where = [
'ifentrust' => 1,
"json_extract(info_json,'$.entrust_mobile')='{$mobile}'" => null,
'status>=' => 0,
'status<' => 6,
'brand_id>' => 0
];
$row = $this->select($where,'id desc',1,1);
}
return $row[0];
}
public function get_status()
{
return $this->status_arr;