354 lines
18 KiB
PHP
354 lines
18 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/07/07
|
|
* Time: 14:08
|
|
*/
|
|
class Protocol extends CI_Controller{
|
|
|
|
private $folder;
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
$this->load->model('receiver/order/receiver_order_contracts_model','contracts_model');
|
|
$this->load->model('receiver/order/receiver_order_agents_model','agents_model');
|
|
$this->load->model('receiver/order/receiver_order_loans_model','loans_model');
|
|
$this->load->model('receiver/order/receiver_order_ckcars_model','ckcars_model');
|
|
$this->load->model('receiver/order/receiver_order_oplogs_model');
|
|
|
|
$this->load->model('receiver/receiver_fine_model');
|
|
$this->load->model('receiver/receiver_service_package_model','package_model');
|
|
$this->load->model('receiver/receiver_services_model','services_model');
|
|
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
|
|
$this->load->model("biz/biz_model");
|
|
$this->load->model('area_model');
|
|
$this->load->model("sys/sys_company_model");
|
|
$this->load->model("items/items_model");
|
|
$this->load->model('app/liche/app_liche_orders_model');
|
|
|
|
$wxapp = $this->input->get('wxapp');
|
|
$this->folder = $wxapp ? 'protocol' : 'html2pdf';
|
|
}
|
|
|
|
//整车合同
|
|
public function car(){
|
|
$id = $this->input->get('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>0]);
|
|
if($row){
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount'];
|
|
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title');
|
|
$color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title');
|
|
$incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title');
|
|
$row['version'] = $version['title'] ? $version['title'] : '';
|
|
$row['color'] = $color['title'] ? $color['title'] : '';
|
|
$row['incolor'] = $incolor['title'] ? $incolor['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'];
|
|
$row['brand_id'] == 4 && $biz['company_id'] = 1; //哪吒品牌 公司固定厦门狸车销售公司
|
|
|
|
$company = $this->sys_company_model->get(['id'=>$biz['company_id']]);
|
|
$row['company'] = $company;
|
|
//获取选择代办包
|
|
$srv_total = count(explode(',',$row['srv_ids']));
|
|
if($srv_total==4){
|
|
$row['give_time'] = 30;
|
|
}elseif($srv_total==3){
|
|
$row['give_time'] = 45;
|
|
}else{
|
|
$row['give_time'] = 60;
|
|
}
|
|
//获取精品
|
|
$fine_title = '无';
|
|
if($row['fine_ids']){
|
|
$fine_rows = $this->receiver_fine_model->select(["id in ({$row['fine_ids']})"=>null],'','','','title');
|
|
$fine_title = implode(',',array_column($fine_rows,'title'));
|
|
}
|
|
$row['fine_title'] = $fine_title;
|
|
}
|
|
$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",$row);
|
|
}
|
|
|
|
//代理合同
|
|
public function agent(){
|
|
$id = $this->input->get('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>1]);
|
|
$total_price = 0;
|
|
$services = [];
|
|
if($row){
|
|
$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]);
|
|
$is_insure = false;
|
|
if($row['srv_ids']){
|
|
$services = $this->services_model->select(["id in ({$row['srv_ids']})"=>null],'','','','title');
|
|
$srv_id_arr = explode(',',$row['srv_ids']);
|
|
$is_insure = in_array(1,$srv_id_arr) ? true : false;
|
|
}
|
|
$this->load->library('receiver/orders_entity');
|
|
$srv_price = $this->orders_entity->order_srv_money($row['id']);
|
|
$total_price = $srv_price;
|
|
$is_insure && $total_price = $total_price + $money_json['price_insure'];
|
|
}
|
|
$row['is_insure'] = $is_insure;
|
|
$row['services'] = $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",$row);
|
|
}
|
|
//车辆信息确认单
|
|
public function car_ck(){
|
|
$id = $this->input->get('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if($row){
|
|
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title');
|
|
$row['brand_name'] = $brand['name'].$series['name'].' '.$version['title'];
|
|
//获取门店信息
|
|
$biz = $this->biz_model->get(['id'=>$row['biz_id']]);
|
|
if($row['brand_id']==4){ //哪吒品牌 公司固定厦门狸车销售公司
|
|
$biz['company_id'] = 1;
|
|
}
|
|
$company = $this->sys_company_model->get(['id'=>$biz['company_id']]);
|
|
$row['company'] = $company;
|
|
}
|
|
$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>2]);
|
|
$items = $this->items_model->get(['id'=>$row['item_id']],'vin');
|
|
$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'];
|
|
$row['vin'] = $items['vin'];
|
|
$this->load->view("wxapp/licheb/{$this->folder}/car_ck",$row);
|
|
}
|
|
//车辆交接信息
|
|
public function car_fh(){
|
|
$this->load->model('app/licheb/app_licheb_users_model');
|
|
$id = $this->input->get('id');
|
|
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
$agent = $this->agents_model->get(['o_id'=>$id]);
|
|
$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>3]);
|
|
$items = $this->items_model->get(['id'=>$row['item_id']],'vin');
|
|
$total_price = 0;
|
|
if($row){
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount'];
|
|
//贷款
|
|
if(!$row['payway']){
|
|
$row['loan'] = $this->loans_model->get(['o_id'=>$id]);
|
|
}
|
|
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$row['info_json'] = $info_json = json_decode($row['info_json'],true);
|
|
$version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title');
|
|
$color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title');
|
|
$incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title');
|
|
$row['version'] = $version['title'] ? $version['title'] : '';
|
|
$row['color'] = $color['title'] ? $color['title'] : '';
|
|
$row['incolor'] = $incolor['title'] ? $incolor['title'] : '';
|
|
$row['brand_name'] = $brand['name'];
|
|
$row['series_name'] = $series['name'];
|
|
$row['cardid'] = $info_json['cardid'];
|
|
//获取门店信息
|
|
$biz = $this->biz_model->get(['id'=>$row['biz_id']]);
|
|
if($row['brand_id']==4){ //哪吒品牌 公司固定厦门狸车销售公司
|
|
$biz['company_id'] = 1;
|
|
}
|
|
$company = $this->sys_company_model->get(['id'=>$biz['company_id']]);
|
|
$row['company'] = $company;
|
|
$where = [
|
|
'o_id' => $row['id'],
|
|
'status' => 1,
|
|
'type in (1,2,4,5)' => null
|
|
];
|
|
$pay = $this->app_liche_orders_model->sum('total_price',$where);
|
|
//尾款
|
|
$p_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'pid'=>0,'status>='=>0],'id');
|
|
$where = [
|
|
'o_id' => $row['id'],
|
|
'status' => 1,
|
|
'type' => 3,
|
|
'pid!=' => $p_row['id']
|
|
];
|
|
$last_pay = $this->app_liche_orders_model->sum('total_price',$where);
|
|
$row['pay_price'] = $pay['total_price'] + $last_pay['total_price'];
|
|
$this->load->library('receiver/orders_entity');
|
|
$total_price = $this->orders_entity->order_srv_money($row['id']);
|
|
}
|
|
$row['total_price'] = $total_price;
|
|
$row['agent'] = $agent;
|
|
$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日');
|
|
$row['cid'] = $contract['cid'];
|
|
$row['vin'] = $items['vin'];
|
|
$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){
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount'];
|
|
|
|
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title');
|
|
$color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title');
|
|
$incolor = $this->auto_attr_model->get(['id'=>$row['incor_id']],'title');
|
|
$row['version'] = $version['title'] ? $version['title'] : '';
|
|
$row['color'] = $color['title'] ? $color['title'] : '';
|
|
$row['incolor'] = $incolor['title'] ? $incolor['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;
|
|
//获取选择代办包
|
|
$srv_total = count(explode(',',$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);
|
|
$opt_money_json = json_decode($opt_row['money_json'],true);
|
|
$opt_money_json['price_discount'] && $opt_row['price'] - $opt_money_json['price_discount'];
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$money_json['price_discount'] && $row['price'] - $money_json['price_discount'];
|
|
$b_price = num_to_rmb($row['price']);
|
|
$price = number_format($row['price'],2);
|
|
$logs = [];
|
|
if($opt_row){
|
|
$diff_key_arr = ['s_id','v_id','cor_id','incor_id'];
|
|
$diff_price = $diff_car = false;
|
|
foreach($diff_key_arr as $item){
|
|
if($opt_row[$item]!=$row[$item]){
|
|
$diff_price = $diff_car = true;
|
|
break;
|
|
}
|
|
}
|
|
if($money_json['price_discount']!=$opt_money_json['price_discount']){
|
|
$diff_price = true;
|
|
}
|
|
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'=>$opt_row['brand_id']],'name');
|
|
$old_series = $this->auto_series_model->get(['id'=>$opt_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}";
|
|
$logs[0] = "购买车型由 {$old_car} 变更为 {$new_car}
|
|
<div>车辆单价:{$price} 元 数量:1</div>
|
|
<div>车辆总价:{$price}元,{$b_price} </div>";
|
|
}
|
|
if($diff_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]);
|
|
$is_insure = false;
|
|
if($row['srv_ids']){
|
|
$service_rows = $this->services_model->select(["id in ({$row['srv_ids']})"=>null],'','','','title');
|
|
$services = implode(',',array_column($service_rows,'title'));
|
|
$srv_id_arr = explode(',',$row['srv_ids']);
|
|
$is_insure = in_array(1,$srv_id_arr) ? true : false;
|
|
}
|
|
if($opt_row['srv_ids']){
|
|
$service_rows = $this->services_model->select(["id in ({$opt_row['srv_ids']})"=>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;
|
|
$is_insure && $total_price = $total_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);
|
|
}
|
|
}
|