From b643f5b1e3c8a3f0cccb305b2cdb6b1329823472 Mon Sep 17 00:00:00 2001
From: lccsw <1127794702@qq.com>
Date: Fri, 22 Oct 2021 11:50:54 +0800
Subject: [PATCH] add-api-edit-order
---
admin/controllers/receiver/Orders.php | 3 +-
admin/views/receiver/orders/get.php | 15 +-
api/controllers/wxapp/liche/Contract.php | 77 ++++++-
api/controllers/wxapp/liche/Order.php | 9 +-
api/controllers/wxapp/liche/User.php | 24 +-
api/controllers/wxapp/licheb/Cusorder.php | 25 +-
api/controllers/wxapp/licheb/Cusorder2.php | 215 ++++++++++++++++++
api/controllers/wxapp/licheb/Protocol.php | 158 ++++++++++++-
api/controllers/wxapp/licheb/Services.php | 8 +-
api/controllers/wxapp/licheb/User.php | 2 +-
api/views/wxapp/licheb/html2pdf/agent_sp.php | 49 ++++
api/views/wxapp/licheb/html2pdf/car_sp.php | 47 ++++
api/views/wxapp/licheb/protocol/agent_sp.php | 52 +++++
api/views/wxapp/licheb/protocol/car_sp.php | 53 +++++
common/libraries/Pdf.php | 2 +-
common/libraries/entity/Deal_entity.php | 61 ++++-
common/libraries/receiver/Orders_entity.php | 95 +++++++-
.../order/Receiver_order_contracts_model.php | 2 +-
.../receiver/order/Receiver_orders_model.php | 3 +-
common/services/apporder/Payment_service.php | 7 +-
sql/receiver/order.sql | 5 +-
21 files changed, 859 insertions(+), 53 deletions(-)
create mode 100644 api/controllers/wxapp/licheb/Cusorder2.php
create mode 100644 api/views/wxapp/licheb/html2pdf/agent_sp.php
create mode 100644 api/views/wxapp/licheb/html2pdf/car_sp.php
create mode 100644 api/views/wxapp/licheb/protocol/agent_sp.php
create mode 100644 api/views/wxapp/licheb/protocol/car_sp.php
diff --git a/admin/controllers/receiver/Orders.php b/admin/controllers/receiver/Orders.php
index a160a53c..6bf58057 100644
--- a/admin/controllers/receiver/Orders.php
+++ b/admin/controllers/receiver/Orders.php
@@ -408,7 +408,8 @@ class Orders extends HD_Controller
$file = $_FILES['file'];
$row = $this->order_loans_model->get(['o_id' => $oid]);
if (!$row) {
- return $this->show_json(SYS_CODE_FAIL, '参数错误!');
+ $this->order_loans_model->add(['o_id'=>$oid,'c_time'=>time()]);
+ $row = $this->order_loans_model->get(['o_id' => $oid]);
}
$update = [];
if ($file) { //上传按揭通知函
diff --git a/admin/views/receiver/orders/get.php b/admin/views/receiver/orders/get.php
index 1852675a..0a9cd5d9 100644
--- a/admin/views/receiver/orders/get.php
+++ b/admin/views/receiver/orders/get.php
@@ -219,7 +219,20 @@
{{info.contract_data[3]['status_name']}}
-
+
+
diff --git a/api/controllers/wxapp/liche/Contract.php b/api/controllers/wxapp/liche/Contract.php
index bb2c8d46..e7886ce3 100644
--- a/api/controllers/wxapp/liche/Contract.php
+++ b/api/controllers/wxapp/liche/Contract.php
@@ -23,10 +23,12 @@ class Contract extends Wxapp{
$this->load->model('receiver/order/receiver_order_ckcars_model','ckcars_model');
$this->load->model('receiver/order/receiver_order_bills_model','bills_model');
$this->load->model('receiver/order/receiver_order_deliverys_model','deliverys_model');
+ $this->load->model('receiver/order/receiver_order_oplogs_model');
$this->load->model('receiver/receiver_service_package_model','package_model');
$this->load->model("biz/biz_model");
$this->load->model("sys/sys_company_model");
+ $this->load->library('receiver/orders_entity');
}
protected function get(){
@@ -41,7 +43,6 @@ class Contract extends Wxapp{
}
$contract = $this->contracts_model->get(['type'=>$type,'o_id'=>$id]);
- $this->load->library('receiver/orders_entity');
$this->load->library('pdf');
list($h5_url,$title) = $this->orders_entity->get_contract_h5($id,$type,1);
@@ -81,11 +82,30 @@ class Contract extends Wxapp{
$this->contracts_model->update($update,['id'=>$contract['id']]);
}
}
-
+ $next_path = ''; //下一步合同
+ switch($type){
+ case 0: //整车
+ $next_path = '/pages/mine/signContract/daiLi?id='.$row['id'];
+ break;
+ case 1: //协议
+ break;
+ case 4://车辆买卖合同补充协议
+ $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);
+ if($opt_row['pack_id']!=$row['pack_id']){
+ //需要签服务补充协议
+ $next_path = '/pages/mine/signContract/weiTuoBu?id='.$row['id'];
+ }
+ break;
+ case 5://委托服务补充协议
+ break;
+ default:
+ }
$data = [
'title' => $title,
'url' => $h5_url,
'img' => 'https://qs.haodian.cn/wechat_app/liche/mine/he-demo-2.jpg',
+ 'netx_path' => $next_path
];
return $data;
}
@@ -182,7 +202,6 @@ class Contract extends Wxapp{
];
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
if($result){
- $this->load->library('receiver/orders_entity');
$this->orders_entity->sign_after_v2($id,$this->session);
$redis->delete($cache_key);
throw new Exception('签名成功', API_CODE_SUCCESS);
@@ -209,7 +228,6 @@ class Contract extends Wxapp{
if($result){
$this->ckcars_model->update(['status'=>2],['o_id'=>$id]);
//生成支付订单
- $this->load->library('receiver/orders_entity');
$this->orders_entity->check_finish_v2($id,$this->session);
$redis->delete($cache_key);
throw new Exception('签名成功', API_CODE_SUCCESS);
@@ -240,6 +258,57 @@ class Contract extends Wxapp{
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
}
break;
+ case 4://车辆买卖合同补充协议
+ $sign_img = array_pop($imgs);
+ $height = $order['ifentrust'] ? 1470 : 1350;
+ $res = $sign_entity->merge($sign_img,$img,1050,$height,350);
+ if(!$res){
+ throw new Exception('签名失败', API_CODE_INVILD_PARAM);
+ }
+ $imgs[] = http_host_com('api').'/'.$res;
+ $imgs = $this->up_qiniu($imgs,$res);
+ $update = [
+ 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE),
+ 'sign_time' => date('Y-m-d H:i:s'),
+ 'status' => 1
+ ];
+ $result = $this->contracts_model->update($update,['id'=>$row['id']]);
+ if($result){
+ $redis->delete($cache_key);
+ $opt_row = $this->receiver_order_oplogs_model->select(['order_id'=>$id,'type'=>3],'id desc',1,1);//最后修改日志
+ $opt_row = json_decode($opt_row[0]['log_json'],true);
+ if($opt_row['pack_id']==$order['pack_id']){
+ //不需要签服务补充协议 完成重新补充协议签约
+ $this->orders_entity->finish_sp($id);
+ }
+ throw new Exception('签名成功', API_CODE_SUCCESS);
+ }else{
+ throw new Exception('签名失败', API_CODE_INVILD_PARAM);
+ }
+ break;
+ case 5://委托服务补充协议
+ $sign_img = array_pop($imgs);
+ $height = $order['ifentrust'] ? 1270 : 1150;
+ $res = $sign_entity->merge($sign_img,$img,1050,$height,340);
+ if(!$res){
+ throw new Exception('签名失败', API_CODE_INVILD_PARAM);
+ }
+ $imgs[] = http_host_com('api').'/'.$res;
+ $imgs = $this->up_qiniu($imgs,$res);
+ $update = [
+ 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE),
+ 'sign_time' => date('Y-m-d H:i:s'),
+ 'status' => 1
+ ];
+ $result = $this->contracts_model->update($update,['id'=>$row['id']]);
+ if($result){
+ $redis->delete($cache_key);
+ $this->orders_entity->finish_sp($id);
+ throw new Exception('签名成功', API_CODE_SUCCESS);
+ }else{
+ throw new Exception('签名失败', API_CODE_INVILD_PARAM);
+ }
+ break;
default:
$redis->delete($cache_key);
throw new Exception('未知签名类型', API_CODE_INVILD_PARAM);
diff --git a/api/controllers/wxapp/liche/Order.php b/api/controllers/wxapp/liche/Order.php
index 9b4f1ada..3bfe2e55 100644
--- a/api/controllers/wxapp/liche/Order.php
+++ b/api/controllers/wxapp/liche/Order.php
@@ -146,9 +146,13 @@ class Order extends Wxapp{
$type_arr = $this->app_liche_orders_model->get_type_arr();
foreach($rows as $key=>$val){
+ $order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'payway,price,brand_id,s_id,v_id,cor_id');
+ $select_car = false;
+ if($order['brand_id'] && $order['s_id'] && $order['cor_id']){
+ $select_car = true;
+ }
$brand_name = $brands[$val['brand_id']] ? $brands[$val['brand_id']][0]['name'] : '';
$serie_name = $series[$val['s_id']] ? $series[$val['s_id']][0]['name'] : '';
- $order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'payway,price');
$info['车辆级别'] = $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '';
$info['车身颜色'] = $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '';
$info['内饰颜色'] = $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'] : '';
@@ -194,8 +198,9 @@ class Order extends Wxapp{
'price' => $order['price'],
'sid' => $val['sid'],
'payway' => $order['payway'],
+ 'type' => $select_car,
'info' => $info,
- 'sub_order' => $sub_order
+ 'sub_order' => $sub_order,
];
}
}
diff --git a/api/controllers/wxapp/liche/User.php b/api/controllers/wxapp/liche/User.php
index a7a4dc5a..07f44346 100644
--- a/api/controllers/wxapp/liche/User.php
+++ b/api/controllers/wxapp/liche/User.php
@@ -197,6 +197,7 @@ class User extends Wxapp{
$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){
@@ -266,12 +267,17 @@ class User extends Wxapp{
$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);
$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]);
+ $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]);
@@ -282,8 +288,20 @@ class User extends Wxapp{
case 0:
$state = 0;
if(!$sign_row['status']){//未签名
- $count = $this->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)','status'=>1]);
- if($count>0){
+ if($sign_count>=2){ //需要签补充协议
+ $diff_key_arr = ['s_id','v_id','cor_id','incor_id','pack_id']; //修改其中一项需要签补充协议
+ 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']){
+ $need_resign_car = true; //需要签合同补充协议
+ }
+ if($opt_row['pack_id']!=$row['pack_id']){
+ $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'];
diff --git a/api/controllers/wxapp/licheb/Cusorder.php b/api/controllers/wxapp/licheb/Cusorder.php
index e0cee147..f3820aed 100644
--- a/api/controllers/wxapp/licheb/Cusorder.php
+++ b/api/controllers/wxapp/licheb/Cusorder.php
@@ -70,6 +70,7 @@ class Cusorder extends Wxapp{
$ifentrust = $this->input_param('ifentrust');
$entrust_name = $this->input_param('entrust_name');
$entrust_idcard = $this->input_param('entrust_idcard');
+ $entrust_idcard = $this->input_param('entrust_idcard');
$name = $this->input_param('name');
$mobile = $this->input_param('mobile');
$address = $this->input_param('address');
@@ -183,10 +184,7 @@ class Cusorder extends Wxapp{
if($series_row['brand_id']==3){ //狸车品牌写死挂牌费用0.01 测试用
$money_json['fee_carno'] = 0.01;
}else{
- $biz = $this->biz_model->get(['id'=>$row['biz_id']],'company_id,city_id');
- if($series_row['brand_id']==4){ //哪吒品牌 公司固定厦门狸车销售公司
- $biz['company_id'] = 1;
- }
+ $biz = $this->biz_model->get(['id'=>$row['biz_id']],'city_id');
$city = $this->sys_city_model->get(['city_id'=>$biz['city_id']],'fee_carno');
$money_json['fee_carno'] = $city['fee_carno'];
}
@@ -396,10 +394,14 @@ class Cusorder extends Wxapp{
//是否存在意向金订单
$inten_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>4,'status>='=>0]);
$pay_status = 0;
+ $inten_money = 0;
$pay_img = 'https://img.liche.cn/liche/1634022931.png';
if($inten_row && $inten_row['status']==0){
$pay_status = 1;
}
+ if($inten_row['status']==1){//已支付意向金
+ $inten_money = floatval($inten_row['total_price']);
+ }
//开票信息
$bill_status = 0;
$bill_data = [];
@@ -428,7 +430,7 @@ class Cusorder extends Wxapp{
'name' => $row['name'],
'mobile' => mobile_asterisk($row['mobile']),
'admin_img' => 'https://img.liche.cn/liche/2021/08/7725fc9ab0dc0ba1/f3c84cf3b805bac4.png',
- 'payway' => $row['payway'],
+ 'payway' => $row['brand_id'] ? $row['payway'] : '',
'car_data' => $car_data,
'pay_status' => $pay_status,
'pay_img' => $pay_img,
@@ -437,8 +439,19 @@ class Cusorder extends Wxapp{
'bill_status' => $bill_status,
'bill_data' => $bill_data,
'ckcar_status' => $ckcar_status,
- 'pack_id' => $row['pack_id']
+ 'pack_id' => $row['pack_id'],
+ 'brand_id' => $row['brand_id'],
+ 'car_id' => $row['s_id'],
+ 'v_id' => $row['v_id'],
+ 'color_id' => $row['cor_id'],
+ 'incolor_id' => $row['incor_id'],
+ 'ifentrust' => $row['brand_id'] ? $row['ifentrust'] : '',
+ 'entrust_name' => $info_json['entrust_name'] ? $info_json['entrust_name']:'',
+ 'entrust_idcard' => $info_json['entrust_idcard'] ? $info_json['entrust_idcard']:'',
+ 'delry_time' => $row['delry_time']!='0000-00-00 00:00:00' ? date('Y-m-d',strtotime($row['delry_time'])):'',
+ 'finance_id' => !$row['payway'] ? $row['finance_id'] : ''
];
+ $inten_money && $data['inten_money'] = $inten_money;
return $data;
}
//确认交付
diff --git a/api/controllers/wxapp/licheb/Cusorder2.php b/api/controllers/wxapp/licheb/Cusorder2.php
new file mode 100644
index 00000000..7f7641b5
--- /dev/null
+++ b/api/controllers/wxapp/licheb/Cusorder2.php
@@ -0,0 +1,215 @@
+login_white = array();//登录白名单
+ $this->check_status = array();//用户状态校验
+ $this->check_mobile = array();//需要手机号
+ $this->check_headimg =array();//授权微信信息
+
+ $this->load->model('receiver/receiver_customers_model','customers_model');
+ $this->load->model('receiver/order/receiver_orders_model','orders_model');
+ $this->load->model('receiver/order/receiver_order_contracts_model');
+
+ $this->load->model('auto/auto_series_model');
+ $this->load->model('auto/auto_attr_model');
+ $this->load->model('auto/auto_cars_model');
+
+ $this->load->model("biz/biz_model");
+ $this->load->model('sys/sys_finance_model');
+ $this->load->model('sys/sys_city_model');
+
+ $this->load->model('app/liche/app_liche_users_model');
+ $this->load->model('app/liche/app_liche_orders_model');
+
+ $this->load->library('receiver/orders_entity');
+ }
+
+ protected function get(){
+ }
+
+ //创建订单
+ protected function post(){
+ $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
+ $cus_id = $this->input_param('cus_id');
+ $name = $this->input_param('name');
+ $mobile = $this->input_param('mobile');
+ $address = $this->input_param('address');
+ $cardid = $this->input_param('cardid');
+ $ifentrust = $this->input_param('ifentrust');
+ $entrust_name = $this->input_param('entrust_name');
+ $entrust_mobile = $this->input_param('entrust_mobile');
+ $entrust_idcard = $this->input_param('entrust_idcard');
+ $inten_money = floatval($this->input_param('inten_money'));//意向金
+
+ $row = $this->customers_model->get(['id'=>$cus_id]);
+ if(!$row || !$cardid || !$address){
+ throw new Exception('参数错误', ERR_PARAMS_ERROR);
+ }
+ if($inten_money > 2000){
+ throw new Exception('意向金不得高于2000', ERR_PARAMS_ERROR);
+ }
+ //判断是否存在未完成流程
+ $omobile = $mobile ? $mobile : $row['mobile'];
+ $o_order = $this->orders_model->get_step($omobile);
+ if($o_order){
+ $this->orders_model->update(['status'=>-1],['id'=>$o_order['id']]);
+ }
+ $data = [
+ 'rid' => $cus_id,
+ 'sid' => create_order_no(350200,$this->app_key),
+ 'name' => $name ? $name : $row['name'],
+ 'mobile' => $mobile ? $mobile : $row['mobile'],
+ 'biz_id' => $biz_id,
+ 'admin_id' => $this->session['uid'],
+ 'c_time' => time()
+ ];
+ $info_json = [];
+ $cardid && $info_json['c_cardid'] = $cardid;
+ $address && $info_json['c_address'] = $address;
+ if($ifentrust){
+ if(!$entrust_name || !$entrust_mobile || !$entrust_idcard){
+ throw new Exception('参数错误', ERR_PARAMS_ERROR);
+ }
+ $info_json['entrust_name'] = $entrust_name;
+ $info_json['entrust_mobile'] = $entrust_mobile;
+ $info_json['entrust_idcard'] = $entrust_idcard;
+ }
+ $info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE);
+
+ //获取挂牌价
+ if($series_row['brand_id']==3){ //狸车品牌写死挂牌费用0.01 测试用
+ $money_json['fee_carno'] = 0.01;
+ }else{
+ $biz = $this->biz_model->get(['id'=>$row['biz_id']],'city_id');
+
+ $city = $this->sys_city_model->get(['city_id'=>$biz['city_id']],'fee_carno');
+ $money_json['fee_carno'] = $city['fee_carno'];
+ }
+ $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
+
+ $row['rid'] && $data['clue_id'] = $row['rid'];
+ $o_id = $this->orders_model->add($data);
+ if(!$o_id){
+ throw new Exception('创建失败', ERR_PARAMS_ERROR);
+ }
+ //增加分销记录
+ $this->load->library('entity/deal_entity',['app_id'=>1]);
+ $this->deal_entity->deal_log($o_id);
+ //意向金订单
+ if($inten_money){
+ $userinfo = $this->app_liche_users_model->get(['mobile'=>$data['mobile']]);
+ $this->orders_entity->c_intention($o_id,$userinfo,$inten_money);
+ }
+ return ['id'=>$o_id];
+ }
+
+ //修改订单信息
+ protected function put(){
+ $id = $this->input_param('id');
+ $car_id = $this->input_param('car_id');
+ $color_id = $this->input_param('color_id');
+ $incolor_id = $this->input_param('incolor_id');
+ $v_id = $this->input_param('v_id');
+ $payway = $this->input_param('payway');
+ $pack_id = $this->input_param('pack_id');
+ $main_type = $this->input_param('main_type');
+ $delry_time = $this->input_param('delry_time');
+ $finance_id = $this->input_param('finance_id');
+
+ $row = $this->orders_model->get(['id'=>$id]);
+ $series_row = $this->auto_series_model->get(['id'=>$car_id]);
+ $car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id,'cor_id'=>$color_id,'incor_id'=>$incolor_id]);
+ if(!$row || !$series_row || !$car_row){
+ throw new Exception('参数错误', ERR_PARAMS_ERROR);
+ }
+ if($row['status']>2){ //车辆确认后不可修改
+ throw new Exception('修改失败,信息不可修改', ERR_PARAMS_ERROR);
+ }
+ if(!$payway){ //分期
+ $finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]);
+ if(!$finance_row){
+ throw new Exception('参数错误', ERR_PARAMS_ERROR);
+ }
+ }
+
+ $where = [
+ "id in ($v_id,$color_id,$incolor_id)" => null
+ ];
+ $attr_row = $this->auto_attr_model->map('id','',$where);
+ if($attr_row[$color_id]){
+ $color_row = $attr_row[$color_id][0];
+ $color_row['jsondata'] = json_decode($color_row['jsondata'],true);
+ }
+ if($attr_row[$incolor_id]){
+ $incolor_row = $attr_row[$incolor_id][0];
+ $incolor_row['jsondata'] = json_decode($incolor_row['jsondata'],true);
+ }
+ if($attr_row[$v_id]){
+ $version_row = $attr_row[$v_id][0];
+ $version_row['jsondata'] = json_decode($version_row['jsondata'],true);
+ }
+ $car_json = [
+ 'c_id' => $color_id,
+ 'inc_id' => $incolor_id,
+ 'v_id' => $v_id,
+ 'color' => isset($color_row) ? $color_row : '',
+ 'incolor' => isset($incolor_row) ? $incolor_row : '',
+ 'version' => isset($version_row) ? $version_row : ''
+ ];
+
+ $data = [
+ 'brand_id' => $series_row['brand_id'],
+ 's_id' => $series_row['id'],
+ 'v_id' => $v_id,
+ 'cor_id' => $color_id,
+ 'incor_id' => $incolor_id,
+ 'car_json' => json_encode($car_json,JSON_UNESCAPED_UNICODE),
+ 'price' => $car_row['price_car'],
+ 'deposit' => $car_row['price_book'],
+ 'payway' => $payway ? 1 : 0,
+ 'status' => 0,
+ ];
+ $pack_id && $data['pack_id'] = $pack_id;
+ $main_type && $data['main_type'] = 1;
+ $delry_time && $data['delry_time'] = $delry_time;
+ $finance_row && $data['finance_id'] = $finance_row['id'];
+
+ //获取金额json数据
+ $money_json = json_decode($row['money_json'],true);
+ $money_json['price_car'] = $car_row['price_car'];
+ $money_json['price_book'] = $car_row['price_book'];
+ $money_json['price_insure'] = $car_row['price_insure'];
+ $money_json['price_fine'] = $car_row['price_fine'];
+ $orders_entity = new Orders_entity();
+ if(!$payway){
+ if($series_row['brand_id']==4){ //哪吒品牌 金融服务费2000
+ $money_json['price_finance'] = 2000;
+ }else{
+ $money_json['price_finance'] = $orders_entity::PRICE_FINANCE;
+ }
+ }
+ $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
+
+ $result = $this->orders_model->update($data,['id'=>$row['id']]);
+ if($result){
+ $orders_entity->edit_order($data,$row,$this->session['uid'],$this->session['uname']);
+ throw new Exception('修改成功', API_CODE_SUCCESS);
+ }else{
+ throw new Exception('创建失败', ERR_PARAMS_ERROR);
+ }
+
+ }
+
+}
diff --git a/api/controllers/wxapp/licheb/Protocol.php b/api/controllers/wxapp/licheb/Protocol.php
index 80eb52d8..7ad0a272 100644
--- a/api/controllers/wxapp/licheb/Protocol.php
+++ b/api/controllers/wxapp/licheb/Protocol.php
@@ -9,6 +9,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
*/
class Protocol extends CI_Controller{
+ private $folder;
public function __construct(){
parent::__construct();
$this->load->model('receiver/order/receiver_orders_model','orders_model');
@@ -18,10 +19,12 @@ class Protocol extends CI_Controller{
$this->load->model('receiver/order/receiver_order_ckcars_model','ckcars_model');
$this->load->model('receiver/receiver_service_package_model','package_model');
$this->load->model('receiver/receiver_services_model','services_model');
+ $this->load->model('receiver/order/receiver_order_oplogs_model');
$this->load->model('auto/auto_series_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_cars_model');
+ $this->load->model('auto/auto_attr_model');
$this->load->model("biz/biz_model");
$this->load->model('area_model');
@@ -29,11 +32,13 @@ class Protocol extends CI_Controller{
$this->load->model("items/items_model");
$this->load->model('apporder/order_purchase_model','purchase_model');
$this->load->model('app/liche/app_liche_orders_model');
+
+ $wxapp = $this->input->get('wxapp');
+ $this->folder = $wxapp ? 'protocol' : 'html2pdf';
}
//整车合同
public function car(){
- $wxapp = $this->input->get('wxapp');
$id = $this->input->get('id');
$row = $this->orders_model->get(['id'=>$id]);
$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>0]);
@@ -71,13 +76,11 @@ class Protocol extends CI_Controller{
$row['cid'] = $contract['cid'];
$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
$row['dep_price'] = number_format($row['deposit'],2); //定金
- $folder = $wxapp ? 'protocol' : 'html2pdf';
- $this->load->view("wxapp/licheb/{$folder}/car",$row);
+ $this->load->view("wxapp/licheb/{$this->folder}/car",$row);
}
//代理合同
public function agent(){
- $wxapp = $this->input->get('wxapp');
$id = $this->input->get('id');
$row = $this->orders_model->get(['id'=>$id]);
$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>1]);
@@ -102,12 +105,10 @@ class Protocol extends CI_Controller{
$row['info_json'] = json_decode($row['info_json'],true);
$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
$row['cid'] = $contract['cid'];
- $folder = $wxapp ? 'protocol' : 'html2pdf';
- $this->load->view("wxapp/licheb/{$folder}/agent",$row);
+ $this->load->view("wxapp/licheb/{$this->folder}/agent",$row);
}
//车辆信息确认单
public function car_ck(){
- $wxapp = $this->input->get('wxapp');
$id = $this->input->get('id');
$row = $this->orders_model->get(['id'=>$id]);
if($row){
@@ -130,13 +131,11 @@ class Protocol extends CI_Controller{
$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
$row['cid'] = $contract['cid'];
$row['vin'] = $items['vin'];
- $folder = $wxapp ? 'protocol' : 'html2pdf';
- $this->load->view("wxapp/licheb/{$folder}/car_ck",$row);
+ $this->load->view("wxapp/licheb/{$this->folder}/car_ck",$row);
}
//车辆交接信息
public function car_fh(){
$this->load->model('app/licheb/app_licheb_users_model');
- $wxapp = $this->input->get('wxapp');
$id = $this->input->get('id');
$row = $this->orders_model->get(['id'=>$id]);
@@ -191,7 +190,142 @@ class Protocol extends CI_Controller{
$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
$row['cid'] = $contract['cid'];
$row['vin'] = $items['vin'];
- $folder = $wxapp ? 'protocol' : 'html2pdf';
- $this->load->view("wxapp/licheb/{$folder}/car_fh",$row);
+ $this->load->view("wxapp/licheb/{$this->folder}/car_fh",$row);
+ }
+ //车辆买卖合同补充协议书
+ public function car_sp(){
+ $id = $this->input->get('id');
+ $row = $this->orders_model->get(['id'=>$id]);
+ $row['old_contract'] = $this->contracts_model->get(['o_id'=>$id,'type'=>0]); //买卖合同
+ $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>4]);
+ if($row){
+ $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
+ $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
+ $car_json = json_decode($row['car_json'],true);
+ $row['color'] = isset($car_json['color']) ? $car_json['color']['title'] : '';
+ $row['incolor'] = isset($car_json['incolor']) ? $car_json['incolor']['title'] : '';
+ $row['version'] = isset($car_json['version']) ? $car_json['version']['title'] : '';
+ $row['brand_name'] = $brand['name'];
+ $row['series_name'] = $series['name'];
+ //获取门店信息
+ $biz = $this->biz_model->get(['id'=>$row['biz_id']]);
+ $city = $this->area_model->get(['county_id'=>$biz['county_id']],'city_name,county_name');
+ $row['address'] = $city['city_name'].$city['county_name'].' '.$biz['address'] .'  '. $biz['biz_name'];
+ if($row['brand_id']==4){ //哪吒品牌 公司固定厦门狸车销售公司
+ $biz['company_id'] = 1;
+ }
+ $company = $this->sys_company_model->get(['id'=>$biz['company_id']]);
+ $row['company'] = $company;
+ //获取选择代办包
+ $pack_row = $this->package_model->get(['id'=>$row['pack_id']],'srv_ids');
+ $srv_total = count(explode(',',$pack_row['srv_ids']));
+ if($srv_total==4){
+ $row['give_time'] = 30;
+ }elseif($srv_total==3){
+ $row['give_time'] = 45;
+ }else{
+ $row['give_time'] = 60;
+ }
+ }
+ //修改信息
+ $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);
+ $logs = [];
+ if($opt_row){
+ $diff_key_arr = ['s_id','v_id','cor_id','incor_id'];
+ $diff_car = false;
+ foreach($diff_key_arr as $item){
+ if($opt_row[$item]!=$row[$item]){
+ $diff_car = true;
+ break;
+ }
+ }
+ if($diff_car){
+ $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
+ $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
+ $old_brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
+ $old_series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
+ $attr_arr = [
+ $row['v_id'],$row['cor_id'],$row['incor_id'],$opt_row['v_id'],$opt_row['cor_id'],$opt_row['incor_id']
+ ];
+ $attr_str = implode(',',array_filter($attr_arr));
+ $where = [
+ "id in ({$attr_str})" => null
+ ];
+ $attr_rows = $this->auto_attr_model->map('id','',$where);
+ $version = $attr_rows[$row['v_id']] ? $attr_rows[$row['v_id']][0]['title'] : '';
+ $cor = $attr_rows[$row['cor_id']] ? $attr_rows[$row['cor_id']][0]['title'] : '';
+ $incor = $attr_rows[$row['incor_id']] ? $attr_rows[$row['incor_id']][0]['title'] : '';
+ $old_version = $attr_rows[$opt_row['v_id']] ? $attr_rows[$opt_row['v_id']][0]['title'] : '';
+ $old_cor = $attr_rows[$opt_row['cor_id']] ? $attr_rows[$opt_row['cor_id']][0]['title'] : '';
+ $old_incor = $attr_rows[$opt_row['incor_id']] ? $attr_rows[$opt_row['incor_id']][0]['title'] : '';
+ $new_car = "{$brand['name']}{$series['name']}{$version}{$cor}{$incor}";
+ $old_car = "{$old_brand['name']}{$old_series['name']}{$old_version}{$old_car}{$old_incor}";
+ $b_price = num_to_rmb($row['price']);
+ $price = number_format($row['price'],2);
+ $logs[0] = "购买车型由 {$old_car} 变更为 {$new_car}
+ 车辆单价:{$price} 元 数量:1
+ 车辆总价:{$price}元,{$b_price}
";
+ $old_price = number_format($opt_row['price'],2);
+ $logs[] = "车辆单价由 {$old_price} 变更为 {$price} 车辆总价:{$price}元, {$b_price}";
+ }
+ if($row['payway']!=$opt_row['payway']){
+ $old_payway = $opt_row['payway'] ? '一次性付款' : '分期付款';
+ $payway = $row['payway'] ? '一次性付款' : '分期付款';
+ $logs[] = "付款方式由 {$old_payway} 变更为 {$payway}";
+ }
+ }
+ $row['logs'] = $logs;
+ $row['info_json'] = json_decode($row['info_json'],true);
+ $row['price_rmb'] = num_to_rmb($row['price']);
+ $row['cid'] = $contract['cid'];
+ $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
+ $row['dep_price'] = number_format($row['deposit'],2); //定金
+ $this->load->view("wxapp/licheb/{$this->folder}/car_sp",$row);
+ }
+ //委托服务补充协议书
+ public function agent_sp(){
+ $id = $this->input->get('id');
+ $row = $this->orders_model->get(['id'=>$id]);
+ $row['old_contract'] = $this->contracts_model->get(['o_id'=>$id,'type'=>1]);
+ $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>5]);
+ $total_price = 0;
+ $old_services = $services = '';
+ if($row){
+ //获取修改前数据
+ $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);
+ $money_json = json_decode($row['money_json'],true);
+ //获取门店信息
+ $biz = $this->biz_model->get(['id'=>$row['biz_id']]);
+ $row['company'] = $this->sys_company_model->get(["title like '%服务%'"=>null,'status'=>1]);
+ //获取选择代办包
+ $pack_ids[] = $row['pack_id'];
+ $pack_ids[] = $opt_row['pack_id'];
+ $pack_ids_str = implode(',',$pack_ids);
+ $pack_rows = $this->package_model->map('id','',["id in ($pack_ids_str)"=>null],'','','','id,srv_ids');
+ if($pack_rows){
+ $srv_ids_str = $pack_rows[$row['pack_id']][0]['srv_ids'];
+ if($srv_ids_str){
+ $service_rows = $this->services_model->select(["id in ({$srv_ids_str})"=>null],'','','','title');
+ $services = implode(',',array_column($service_rows,'title'));
+ }
+ $old_srv_ids_str = $pack_rows[$opt_row['pack_id']][0]['srv_ids'];
+ if($old_srv_ids_str){
+ $service_rows = $this->services_model->select(["id in ({$old_srv_ids_str})"=>null],'','','','title');
+ $old_services = implode(',',array_column($service_rows,'title'));
+ }
+ }
+ $this->load->library('receiver/orders_entity');
+ $srv_price = $this->orders_entity->order_srv_money($row['id']);
+ $total_price = $srv_price + $money_json['price_insure'];
+ }
+ $row['services'] = $services;
+ $row['old_services'] = $old_services;
+ $row['total_price'] = $total_price;
+ $row['info_json'] = json_decode($row['info_json'],true);
+ $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
+ $row['cid'] = $contract['cid'];
+ $this->load->view("wxapp/licheb/{$this->folder}/agent_sp",$row);
}
}
diff --git a/api/controllers/wxapp/licheb/Services.php b/api/controllers/wxapp/licheb/Services.php
index 568edb40..87d2a011 100644
--- a/api/controllers/wxapp/licheb/Services.php
+++ b/api/controllers/wxapp/licheb/Services.php
@@ -38,8 +38,8 @@ class Services extends Wxapp{
if(!is_array($srv_id_arr)){
continue;
}
- if($type==2){ //分期 必须包含金融包
- if(in_array($srv_id,$srv_id_arr)){
+ if($type==1){ //全款 过滤包含金融包
+ if(!in_array($srv_id,$srv_id_arr)){
$s_where = [
"id in ({$val['srv_ids']})" => null
];
@@ -50,8 +50,8 @@ class Services extends Wxapp{
'title' => $title
];
}
- }else{ //全款 过滤包含金融包
- if(!in_array($srv_id,$srv_id_arr)){
+ }else{ //分期 必须包含金融包
+ if(in_array($srv_id,$srv_id_arr)){
$s_where = [
"id in ({$val['srv_ids']})" => null
];
diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php
index 0c1a854b..80ab4cdb 100644
--- a/api/controllers/wxapp/licheb/User.php
+++ b/api/controllers/wxapp/licheb/User.php
@@ -41,7 +41,7 @@ class User extends Wxapp
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
}
//判断验证码
- if ($mobile != '15359333655') {//测试号码
+ if($mobile!='15359333655' && $this->env!='d'){//测试环境和测试号码
$mc = &load_cache();
$key = "licheb_login_code_" . $mobile;
$cache_code = $mc->get($key);
diff --git a/api/views/wxapp/licheb/html2pdf/agent_sp.php b/api/views/wxapp/licheb/html2pdf/agent_sp.php
new file mode 100644
index 00000000..e67f6527
--- /dev/null
+++ b/api/views/wxapp/licheb/html2pdf/agent_sp.php
@@ -0,0 +1,49 @@
+
+
+
+
+委托服务补充协议书
+
+
+
+
+
委托服务补充协议书
+
合同编号:=$cid?>
+
甲方(出卖人):=$company['title']?>
+
统一社会信用代码:=$company['credit_code']?>
+
乙方(买受人):=$name?>
+
+
身份证号码:=$info_json['c_cardid']?>
+ }?>
+
联系电话:=$mobile?>
+
+
受托代理人:=$info_json['entrust_name']?>
+
受托人身份证:=$info_json['entrust_idcard']?>
+ }?>
+
本协议中的所有术语,除非另有说明,否则其定义与双方于=date('Y-m-d',strtotime($old_contract['sign_time']))?>签订协议编号为=$old_contract['cid']?>的《委托服务协议》(以下简称“原协议”)中的定义相同。
+
甲、乙双方经友好协商,依据实际情况,在原协议基础上变更协议条款部分内容,特订立以下补充协议。
+
第一条 车辆基本情况
+
代办项目由 =$old_services?> 变更为 =$services?>
+
代办服务总价:=$total_price?>元, =num_to_rmb($total_price)?>,保险费用由乙方直接支付给保险公司。
+
二、本协议生效后,即成为原合同不可分割的组成部分,与原合同具有同等的法律效力。
+
除本协议中明确所作修改的条款之外,原合同的其余部分应完全继续有效。
+
本协议与原合同有相互冲突时,以本协议为准。
+
三、本协议一式贰份,甲方执壹份,乙方执壹份,具有同等法律效力,自双方签字盖章之日起生效。
+
+
+
+ |
+ 甲方(出卖人)
+ 日期:=$day?>
+ |
+
+ 乙方(=$ifentrust?'受托人':'买受人'?>)
+ 日期:=$day?>
+ |
+
+
+
+
+
+
+
diff --git a/api/views/wxapp/licheb/html2pdf/car_sp.php b/api/views/wxapp/licheb/html2pdf/car_sp.php
new file mode 100644
index 00000000..589a0596
--- /dev/null
+++ b/api/views/wxapp/licheb/html2pdf/car_sp.php
@@ -0,0 +1,47 @@
+
+
+
+
+车辆买卖合同补充协议书
+
+
+
+
+
车辆买卖合同补充协议书
+
合同编号:=$cid?>
+
甲方(出卖人):=$company['title']?>
+
统一社会信用代码:=$company['credit_code']?>
+
乙方(买受人):=$name?>
+
联系电话:=$mobile?>
+
+
委托代理人:=$info_json['entrust_name']?>
+
受托人身份证:=$info_json['entrust_idcard']?>
+ }?>
+
本协议中的所有术语,除非另有说明,否则其定义与双方于=date('Y-m-d',strtotime($old_contract['sign_time']))?>签订合同编号为=$old_contract['cid']?>的《车辆买卖合同》(以下简称“原合同”)中的定义相同。
+
甲、乙双方经友好协商,依据实际情况,在原合同基础上变更合同条款部分内容,特订立以下补充协议。
+
一、协议内容变更部分为:
+ $item){?>
+
=$key+1?> =$item?>
+ }?>
+
二、本协议生效后,即成为原合同不可分割的组成部分,与原合同具有同等的法律效力。
+
除本协议中明确所作修改的条款之外,原合同的其余部分应完全继续有效。
+
本协议与原合同有相互冲突时,以本协议为准。
+
三、本协议一式贰份,甲方执壹份,乙方执壹份,具有同等法律效力,自双方签字盖章之日起生效。
+
+
+
+ |
+ 甲方(出卖人)
+ 日期:=$day?>
+ |
+
+ 乙方(=$ifentrust?'受托人':'买受人'?>)
+ 日期:=$day?>
+ |
+
+
+
+
+
+
+
diff --git a/api/views/wxapp/licheb/protocol/agent_sp.php b/api/views/wxapp/licheb/protocol/agent_sp.php
new file mode 100644
index 00000000..afa96065
--- /dev/null
+++ b/api/views/wxapp/licheb/protocol/agent_sp.php
@@ -0,0 +1,52 @@
+
+
+
+
+委托服务补充协议书
+
+
+
+
+
+
委托服务补充协议书
+
合同编号:=$cid?>
+
甲方(出卖人):=$company['title']?>
+
统一社会信用代码:=$company['credit_code']?>
+
乙方(买受人):=$name?>
+
+
身份证号码:=$info_json['c_cardid']?>
+ }?>
+
+
受托代理人:=$info_json['entrust_name']?>
+
受托人身份证:=$info_json['entrust_idcard']?>
+ }?>
+
本协议中的所有术语,除非另有说明,否则其定义与双方于=date('Y-m-d',strtotime($old_contract['sign_time']))?>签订协议编号为=$old_contract['cid']?>的《委托服务协议》(以下简称“原协议”)中的定义相同。
+
甲、乙双方经友好协商,依据实际情况,在原协议基础上变更协议条款部分内容,特订立以下补充协议。
+
第一条 车辆基本情况
+
代办项目由 =$old_services?> 变更为 =$services?>
+
代办服务总价:=$total_price?>元, =num_to_rmb($total_price)?>,保险费用由乙方直接支付给保险公司。
+
二、本协议生效后,即成为原合同不可分割的组成部分,与原合同具有同等的法律效力。
+
除本协议中明确所作修改的条款之外,原合同的其余部分应完全继续有效。
+
本协议与原合同有相互冲突时,以本协议为准。
+
三、本协议一式贰份,甲方执壹份,乙方执壹份,具有同等法律效力,自双方签字盖章之日起生效。
+
+
+
+ |
+ 甲方(盖章)
+ 日期:=$day?>
+ |
+
+ 乙方(=$ifentrust?'受托人':'买受人'?>)
+ 日期:=$day?>
+ |
+
+
+
+
+
+
+
diff --git a/api/views/wxapp/licheb/protocol/car_sp.php b/api/views/wxapp/licheb/protocol/car_sp.php
new file mode 100644
index 00000000..54f11c47
--- /dev/null
+++ b/api/views/wxapp/licheb/protocol/car_sp.php
@@ -0,0 +1,53 @@
+
+
+
+
+车辆买卖合同补充协议书
+
+
+
+
+
+
车辆买卖合同补充协议书
+
合同编号:=$cid?>
+
甲方(出卖人):=$company['title']?>
+
统一社会信用代码:=$company['credit_code']?>
+
乙方(买受人):=$name?>
+
联系电话:=$mobile?>
+
+
受托代理人:=$info_json['entrust_name']?>
+
受托人身份证:=$info_json['entrust_idcard']?>
+ }?>
+
本协议中的所有术语,除非另有说明,否则其定义与双方于=date('Y-m-d',strtotime($old_contract['sign_time']))?>签订合同编号为=$old_contract['cid']?>的《车辆买卖合同》(以下简称“原合同”)中的定义相同。
+
甲、乙双方经友好协商,依据实际情况,在原合同基础上变更合同条款部分内容,特订立以下补充协议。
+
一、协议内容变更部分为:
+
1 购买车型由 XXX 变更为 XXX
+
车辆单价:XXX 元 数量:1
+
车辆总价:XXX元, 壹千贰百叁十个肆玩万元整
+
2 付款方式由 一次性付款 变更为 分期付款
+
3 车辆单价由 XXX 变更为 XXX 车辆总价:XXX元, 壹千贰百叁十个肆玩万元整
+
二、本协议生效后,即成为原合同不可分割的组成部分,与原合同具有同等的法律效力。
+
除本协议中明确所作修改的条款之外,原合同的其余部分应完全继续有效。
+
本协议与原合同有相互冲突时,以本协议为准。
+
三、本协议一式贰份,甲方执壹份,乙方执壹份,具有同等法律效力,自双方签字盖章之日起生效。
+
+
+
+ |
+ 甲方(盖章)
+ 日期:=$day?>
+ |
+
+ 乙方(=$ifentrust?'受托人':'买受人'?>)
+ 日期:=$day?>
+ |
+
+
+
+
+
+
+
diff --git a/common/libraries/Pdf.php b/common/libraries/Pdf.php
index b6122464..7d1ff8be 100644
--- a/common/libraries/Pdf.php
+++ b/common/libraries/Pdf.php
@@ -14,7 +14,7 @@ class Pdf {
private $pdf2img_url = 'https://open.xiaoyu.com/jar/pdf2img/index';
public function __construct($isdev=''){
- if($isdev){
+ if (false !== strpos($_SERVER['HTTP_HOST'], 'dev') || $isdev) {//dev
$this->pdf2img_url = 'https://liche-api-dev.xiaoyu.com/jar/pdf2img';
}
}
diff --git a/common/libraries/entity/Deal_entity.php b/common/libraries/entity/Deal_entity.php
index 1f7dd93f..6975de85 100755
--- a/common/libraries/entity/Deal_entity.php
+++ b/common/libraries/entity/Deal_entity.php
@@ -46,6 +46,10 @@ class Deal_entity
if(!$clue){
return array('code' => 0, 'msg' => '参数错误');
}
+ //该线索是否存在分销
+ if($this->ci->mdDealLog->get(['ex_id'=>$clue['id'],'status>='=>0])){
+ return array('code' => 0, 'msg' => '该线索已存在分销记录');
+ }
$where = [
'brand_id' => $order['brand_id'],
's_id' => $order['s_id'],
@@ -92,7 +96,62 @@ class Deal_entity
, 'ex_id' => $params[4], 'cf_sid' => $params[5], 'app_id' => $params[6], 'status' => 0, 'c_time' => time());
}
}
-
+ /**
+ * 确认交车
+ * @param $oid int 订单id
+ * @return bool
+ */
+ public function deal_log_finish($oid){
+ $this->load->model('app/User_account_model', 'mdUserAccount');
+ $this->load->model('app/User_accountlog_model', 'mdUserAccountLog');
+ $this->load->model('app/Deal_log_model', 'mdDealLog');
+ $this->load->model('receiver/order/receiver_orders_model');
+ $order = $this->ci->receiver_orders_model->get(['id'=>$oid]);
+ if(!$order){
+ return array('code' => 0, 'msg' => '订单不存在');
+ }
+ $where = array("app_id" => $this->app_id, "cf_sid" => $order['sid'], "status" => 0);
+ $res = $this->ci->mdDealLog->select($where, 'id DESC', 0, 0, 'id,app_uid,money');
+ if ($res) {
+ foreach ($res as $key => $value) {
+ $reUa = $this->ci->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $value['app_uid']));
+ if ($reUa['id']) {
+ $aid = $reUa['id'];
+ $money_total = $reUa['money_total'] + $value['money'];
+ $money_left = $reUa['money_left'] + $value['money'];
+ } else {
+ $money_total = $value['money'];
+ $money_left = $value['money'];
+ $addData = array('app_id' => $this->app_id, 'app_uid' => $value['app_uid'], 'status' => 1, 'c_time' => time());
+ $aid = $this->ci->mdUserAccount->add($addData);
+ }
+ if ($aid) {
+ $this->ci->mdUserAccountLog->db->trans_begin();
+ $this->ci->mdUserAccount->db->trans_begin();
+ $this->ci->mdDealLog->db->trans_begin();
+ //增加资金流水表
+ $this->ci->mdUserAccountLog->add(array('account_id' => $aid, 'trade_type' => 1, 'money_in' => $value['money']
+ , 'money_left' => $money_left, 'status' => 1, 'c_time' => time()));
+ //更新账户表
+ $this->ci->mdUserAccount->update(array('money_total' => $money_total, 'money_left' => $money_left), array('id' => $aid));
+ //更新分销记录表
+ $this->ci->mdDealLog->update(array('status' => 1), array('id' => $value['id']));
+ if ($this->ci->mdUserAccountLog->db->trans_status() && $this->ci->mdUserAccount->db->trans_status()
+ && $this->ci->mdDealLog->db->trans_status()) {
+ $this->ci->mdUserAccountLog->db->trans_commit();
+ $this->ci->mdUserAccount->db->trans_commit();
+ $this->ci->mdDealLog->db->trans_commit();
+ debug_log("[success] " . __FUNCTION__ . ":操作成功,account_id={$aid}", $this->log_file);
+ } else {
+ $this->ci->mdUserAccountLog->db->trans_rollback();
+ $this->ci->mdUserAccount->db->trans_rollback();
+ $this->ci->mdDealLog->db->trans_rollback();
+ debug_log("[finish] " . __FUNCTION__ . ":执行失败回滚,account_id={$aid}", $this->log_file);
+ }
+ }
+ }
+ }
+ }
/**
* Notes:核销成功/确认收货后加佣金
* Created on: 2020/7/9 16:30
diff --git a/common/libraries/receiver/Orders_entity.php b/common/libraries/receiver/Orders_entity.php
index cb3765ed..6f574455 100644
--- a/common/libraries/receiver/Orders_entity.php
+++ b/common/libraries/receiver/Orders_entity.php
@@ -59,6 +59,14 @@ class Orders_entity{
$path = '/wxapp/licheb/protocol/car_fh';
$title = '车辆交付表';
break;
+ case 4:
+ $path = '/wxapp/licheb/protocol/car_sp';
+ $title = '车辆买卖合同补充协议书';
+ break;
+ case 5:
+ $path = '/wxapp/licheb/protocol/agent_sp';
+ $title = '委托服务补充协议书';
+ break;
default:
}
if($path){
@@ -81,8 +89,9 @@ class Orders_entity{
if(!$pay_money){//未支付意向订单设置删除
$this->ci->app_liche_orders_model->update(['status'=>-1],['o_id'=>$oid,'uid'=>$userinfo['uid'],'type'=>4,'status'=>0]);
}
+ $deposit_count = $this->ci->app_liche_orders_model->count(['o_id'=>$oid,'uid'=>$userinfo['uid'],'type'=>1,'status'=>1]); //定金已支付
$need_pay_money = $this->order_row['deposit'] - $pay_money['total_price'];
- if($need_pay_money > 0){
+ if($need_pay_money > 0 && !$deposit_count){
$this->ci->signs_model->update(['status'=>1],['o_id'=>$this->order_row['id']]);
$srv_money = $this->order_srv_money($oid);
if($srv_money < $this->order_row['deposit']){ //服务费小于定金 给销售公司
@@ -137,7 +146,7 @@ class Orders_entity{
$res = $this->ci->app_liche_orders_model->add($sub_data);
}
}else{
- if($pay_money['status']){
+ if($pay_money['status'] || $deposit_count){
$this->ci->signs_model->update(['status'=>2],['o_id'=>$oid]);
if($this->order_row['payway']){//全款
$status = 2;
@@ -146,14 +155,10 @@ class Orders_entity{
$status = 1;
$this->ci->load->model('receiver/order/receiver_order_loans_model','next_model');
}
+ $this->ci->orders_model->update(['status'=>$status],['id'=>$this->order_row['id']]);
//判断下一步是否存在
if(!$this->ci->next_model->get(['o_id'=>$this->order_row['id']])){
- $res = $this->ci->orders_model->update(['status'=>$status],['id'=>$this->order_row['id']]);
- if($res){
- $this->ci->next_model->add(['o_id'=>$this->order_row['id'],'c_time'=>time()]);
- }
- }else{
- $res = $this->ci->orders_model->update(['status'=>2],['id'=>$this->order_row['id']]);
+ $this->ci->next_model->add(['o_id'=>$this->order_row['id'],'c_time'=>time()]);
}
}
}
@@ -257,10 +262,10 @@ class Orders_entity{
* @param $uid int 操作用户id
* @param $uname int 操作用户名
* @param $content string 日志内容
- * @param $type int 操作类型 (0普通日志 1短信 2拨打电话)
+ * @param $type int 操作类型 (0普通日志 1短信 2拨打电话 3修改订单信息)
* @param $cf_platform string 来源 (wxapp小程序 admin后台)
*/
- public function add_log($o_id,$uid,$uname,$content,$type='',$cf_platform='wxapp'){
+ public function add_log($o_id,$uid,$uname,$content,$type='',$cf_platform='wxapp',$jsondata = ''){
$this->ci->load->model('receiver/order/receiver_order_oplogs_model','order_oplogs_model');
$add_data = [
'order_id' => $o_id,
@@ -271,6 +276,7 @@ class Orders_entity{
$uname && $add_data['uname'] = $uname;
$type && $add_data['type'] = $type;
$cf_platform && $add_data['cf_platform'] = $cf_platform;
+ $jsondata && $add_data['log_json'] = $jsondata;
$result = $this->ci->order_oplogs_model->add($add_data);
return $result;
}
@@ -517,6 +523,75 @@ class Orders_entity{
];
return $config[$status] ? $config[$status] : '';
}
+ /*
+ * 修改完订单信息后操作
+ * @param array() $new_data 修改后的数据
+ * @param array() $row 修改前数据
+ */
+ public function edit_order($new_data,$row,$uid,$uname){
+ $sign_row = $this->ci->signs_model->get(['o_id'=>$row['id']]);
+ if($sign_row){
+ $diff_key_arr = ['s_id','v_id','cor_id','incor_id','payway','pack_id']; //修改其中一项需要签补充协议
+ $need_resign = false;
+ foreach($diff_key_arr as $item){
+ if($new_data[$item]!=$row[$item]){
+ $need_resign = true;
+ break;
+ }
+ }
+ if($new_data['payway']!=$row['payway']){ //修改付款方式
+ $this->ci->load->model('receiver/order/receiver_order_loans_model');
+ $this->ci->receiver_order_loans_model->delete(['o_id'=>$row['id']]);
+ }
+ if($need_resign){
+ $content = '修改订单信息';
+ $jsondata = json_encode($row,JSON_UNESCAPED_UNICODE);
+ $this->add_log($row['id'],$uid,$uname,$content,3,'wxapp',$jsondata); //添加日志
+ $this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (4,5)'=>null]);
+ if(!$row['status']){ //未签合同删除旧合同文件并且删除未支付订单
+ $this->ci->load->model('app/liche/app_liche_users_model');
+ $this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id']]);
+ $userinfo = $this->ci->app_liche_users_model->get(['mobile'=>$row['mobile']]);
+ $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]);
+ }
+ $this->ci->signs_model->update(['status'=>0],['id'=>$sign_row['id']]);
+ }
+ }else{
+ $this->ci->signs_model->add(['o_id'=>$row['id'],'c_time'=>time()]);
+ }
+ }
+ /**
+ * 完成补充协议签名
+ * @param int $oid 订单id
+ * return boolean
+ */
+ public function finish_sp($oid){
+ !$this->order_row && $this->order_row = $this->ci->orders_model->get(['id'=>$oid]);
+ if(!$this->order_row){
+ return false;
+ }
+ $this->ci->load->model('receiver/order/receiver_order_ckcars_model');
+ $this->ci->signs_model->update(['status'=>2],['o_id'=>$oid]);
+ if($this->order_row['payway']){//全款
+ $res = $this->ci->orders_model->update(['status'=>2],['id'=>$oid]);
+ if(!$this->ci->receiver_order_ckcars_model->get(['o_id'=>$oid])){
+ $this->ci->receiver_order_ckcars_model->add(['o_id'=>$oid,'c_time'=>time()]);
+ }
+ }else{
+ $this->ci->load->model('receiver/order/receiver_order_loans_model');
+ if($this->ci->receiver_order_loans_model->get(['o_id'=>$oid])){
+ if($this->ci->receiver_order_ckcars_model->get(['o_id'=>$oid])) {
+ $res = $this->ci->orders_model->update(['status'=>2],['id'=>$oid]);
+ }else{
+ $res = $this->ci->orders_model->update(['status'=>1],['id'=>$oid]);
+ }
+ }else{
+ $res = $this->ci->orders_model->update(['status'=>1],['id'=>$oid]);
+ $this->ci->receiver_order_loans_model->add(['o_id'=>$oid,'c_time'=>time()]);
+ }
+ }
+ return $res;
+ }
}
?>
diff --git a/common/models/receiver/order/Receiver_order_contracts_model.php b/common/models/receiver/order/Receiver_order_contracts_model.php
index e297e0fa..46fb353d 100644
--- a/common/models/receiver/order/Receiver_order_contracts_model.php
+++ b/common/models/receiver/order/Receiver_order_contracts_model.php
@@ -12,7 +12,7 @@ class Receiver_order_contracts_model extends HD_Model
{
private $table_name = 'lc_receiver_order_contracts';
- private $type_arr = [ 0 => '整车合同',1 => '代理协议',2 => '车辆信息确定',3 => '交接信息'];
+ private $type_arr = [ 0 => '整车合同',1 => '代理协议',2 => '车辆信息确定',3 => '交接信息', 4 => '合同补充协议', 5 => '委托服务补充协议'];
public function __construct()
{
diff --git a/common/models/receiver/order/Receiver_orders_model.php b/common/models/receiver/order/Receiver_orders_model.php
index 86de79c2..bfcb7c3a 100644
--- a/common/models/receiver/order/Receiver_orders_model.php
+++ b/common/models/receiver/order/Receiver_orders_model.php
@@ -64,7 +64,8 @@ class Receiver_orders_model extends HD_Model
$where = [
"$t1.mobile" => $mobile,
"$t1.status<" => 6,
- "$t1.status>=" => 0
+ "$t1.status>=" => 0,
+ "$t1.brand_id>" => 0
];
$this->db->where($where);
$this->db->order_by("$t1.id desc");
diff --git a/common/services/apporder/Payment_service.php b/common/services/apporder/Payment_service.php
index d26d3dac..7abcacab 100644
--- a/common/services/apporder/Payment_service.php
+++ b/common/services/apporder/Payment_service.php
@@ -151,6 +151,7 @@ class Payment_service extends HD_Service{
//更新订单状态
$row = $this->orders_model->get(['id' => $order['o_id']]);
if ($row) {
+ $this->order_signs_model->update(['status' => 2], ['o_id' => $row['id']]);
if ($row['payway']) {//全款
$status = 2;
$this->load->model('receiver/order/receiver_order_ckcars_model', 'next_model');
@@ -158,9 +159,9 @@ class Payment_service extends HD_Service{
$status = 1;
$this->load->model('receiver/order/receiver_order_loans_model', 'next_model');
}
- $res = $this->orders_model->update(['status' => $status], ['id' => $row['id']]);
- $this->order_signs_model->update(['status' => 2], ['o_id' => $row['id']]);
- if ($res) {
+ $next_row = $this->next_model->get(['o_id'=>$row['id']]);
+ $this->orders_model->update(['status' => $status], ['id' => $row['id']]);
+ if(!$next_row){
$add_data = [
'o_id' => $row['id'],
'c_time' => time()
diff --git a/sql/receiver/order.sql b/sql/receiver/order.sql
index 6984fa38..d9768c66 100644
--- a/sql/receiver/order.sql
+++ b/sql/receiver/order.sql
@@ -69,7 +69,7 @@ create table lc_receiver_order_contracts (
file varchar(255) not null default '' comment '合同文件地址',
imgs json default null comment '合同图片地址',
jsondata json default null comment '其他信息',
- type tinyint(1) not null default '0' comment '合同类型(0整车合同 1代理协议 2确定信息 3交接信息)',
+ type tinyint(1) not null default '0' comment '合同类型(0整车合同 1代理协议 2确定信息 3交接信息 4车辆买卖合同补充协议 5委托服务补充协议)',
status tinyint(1) not null default '0' comment '状态(0未签署 1已签署)',
sign_time timestamp not null default '0000-00-00 00:00:00' comment '签名时间',
c_time int(10) unsigned not null default '0' comment '创建时间',
@@ -127,13 +127,14 @@ create table lc_receiver_order_oplogs (
order_id int(10) unsigned not null comment '订单id',
uid int(10) unsigned not null comment '操作用户id',
uname varchar(32) not null default '' comment '用户名',
- type tinyint(1) not null default '0' comment '类型 0 普通 1短信 2电话',
+ type tinyint(1) not null default '0' comment '类型 0 普通 1短信 2电话 3修改订单信息',
log varchar(256) not null default '' comment '操作内容',
cf_platform varchar(10) not null default '' comment '来源平台',
c_time int(10) unsigned not null default '0' comment '创建时间',
u_time timestamp not null default current_timestamp on update current_timestamp,
primary key (id)
) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI COMMENT='订单操作日志表';
+alter table lc_receiver_order_oplogs add log_json json default null comment '修改json数据' after log;
-- ----------------------------
-- Title:订单合同签订