667 lines
30 KiB
PHP
667 lines
30 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lcc
|
|
* Date: 2022/1/10
|
|
* Time: 16:11
|
|
*/
|
|
class Orders_v2_entity{
|
|
const MCH_ID = '1612325641'; //厦门狸车销售
|
|
const SRV_MCH_ID = '1612636924'; //收取服务费商户号 厦门狸车服务
|
|
const PRICE_FINANCE = 1000; //金融服务费写死
|
|
const PRICE_FINANCE_NZ = 2000; //哪吒金融服务费
|
|
const API_PAY_IMG = 'https://img.liche.cn/liche/2022/04/22ed0636993504bc/18ad8baab11b2891.png'; //api 跳转支付二维码
|
|
const V2_START_ID = 10000; //升级后订单开始
|
|
|
|
private $ci;
|
|
|
|
public function __construct(){
|
|
$this->ci = & get_instance();
|
|
$this->ci->load->model('receiver/receiver_customers_model','customers_model');
|
|
|
|
$this->ci->load->model('receiver/order/receiver_orders_v2_model');
|
|
$this->ci->load->model('receiver/order/receiver_order_signs_model','signs_model');
|
|
$this->ci->load->model('receiver/order/receiver_order_deliverys_model','deliverys_model');
|
|
$this->ci->load->model('receiver/order/receiver_order_contracts_model');
|
|
|
|
$this->ci->load->model('receiver/receiver_service_package_model','package_model');
|
|
$this->ci->load->model('receiver/receiver_services_model','services_model');
|
|
|
|
$this->ci->load->model('sys/sys_city_model');
|
|
$this->ci->load->model("sys/sys_company_model");
|
|
|
|
$this->ci->load->model('apporder/order_purchase_model');
|
|
$this->ci->load->model('auto/auto_brand_model');
|
|
$this->ci->load->model('auto/auto_series_model');
|
|
$this->ci->load->model('auto/auto_attr_model');
|
|
$this->ci->load->model("items/items_model");
|
|
|
|
$this->ci->load->model("biz/biz_model");
|
|
$this->ci->load->model('app/liche/app_liche_orders_model');
|
|
}
|
|
|
|
//创建意向金订单
|
|
public function c_intention($oid,$uid,$money){
|
|
$this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
if(!$this->order_row){
|
|
return false;
|
|
}
|
|
$p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'pid'=>0,'status>='=>0]);
|
|
$entrust_user = $this->entrust_user($oid);
|
|
if(!$p_row){
|
|
$sid = create_order_no(350200,'liche',1,0);
|
|
$add_data = [
|
|
'o_id' => $this->order_row['id'],
|
|
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
|
'sid' => $sid,
|
|
'pid' => 0,
|
|
'brand_id' => $this->order_row['brand_id'],
|
|
's_id' => $this->order_row['s_id'],
|
|
'v_id' => $this->order_row['v_id'],
|
|
'cor_id' => $this->order_row['cor_id'],
|
|
'incor_id' => $this->order_row['incor_id'],
|
|
'c_time' => time()
|
|
];
|
|
$uid && $add_data['uid'] = $uid;
|
|
$pid = $this->ci->app_liche_orders_model->add($add_data);
|
|
}else{
|
|
$pid = $p_row['id'];
|
|
}
|
|
$res = false;
|
|
$sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'type'=>4,'status>='=>0]);
|
|
if($pid && !$sub_row){
|
|
//获取微信商户号
|
|
$companys = $this->get_biz_mchid($this->order_row['biz_id'],$this->order_row['brand_id']);
|
|
$sid = create_order_no(350200,'liche',1,4);
|
|
$sub_data = [
|
|
'o_id' => $this->order_row['id'],
|
|
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
|
'sid' => $sid,
|
|
'mch_id' => $companys['company']['wx_mchid'],
|
|
'company_id' => $companys['company']['id'],
|
|
'pid' => $pid,
|
|
'type' => 4,
|
|
'brand_id' => $this->order_row['brand_id'],
|
|
's_id' => $this->order_row['s_id'],
|
|
'v_id' => $this->order_row['v_id'],
|
|
'cor_id' => $this->order_row['cor_id'],
|
|
'incor_id' => $this->order_row['incor_id'],
|
|
'total_price' => $money,
|
|
'c_time' => time()
|
|
];
|
|
$uid && $sub_data['uid'] = $uid;
|
|
$res = $this->ci->app_liche_orders_model->add($sub_data);
|
|
}
|
|
return $res;
|
|
}
|
|
/**
|
|
* 获取商家微信商户号
|
|
* @param $biz_id int 商家id
|
|
* @param $car_brand_id int 品牌id
|
|
* @return array ['company'=>[],'srv_company'=>[]]
|
|
*/
|
|
public function get_biz_mchid($biz_id,$car_brand_id=0){
|
|
$biz = $this->ci->biz_model->get(['id'=>$biz_id],'type,city_id,company_id,srv_company_id,car_brand_id');
|
|
$filed = 'id,wx_mchid,title,short,credit_code,wx_mchid,img_seal';
|
|
if(in_array($biz['type'],[1])){ //品牌店
|
|
$where = [
|
|
"id in ({$biz['company_id']},{$biz['srv_company_id']})" => null
|
|
];
|
|
$companys = $this->ci->sys_company_model->map('id','',$where,'','','',$filed);
|
|
$company = $companys[$biz['company_id']][0];
|
|
$srv_company = $companys[$biz['srv_company_id']][0];
|
|
}else{ //其它店铺
|
|
$brand_biz = $this->ci->biz_model->get(['city_id'=>$biz['city_id'],'type'=>1,'status'=>1,'car_brand_id'=>$car_brand_id],'type,city_id,company_id,srv_company_id');
|
|
if($brand_biz){
|
|
$where = [
|
|
"id in ({$brand_biz['company_id']},{$brand_biz['srv_company_id']})" => null
|
|
];
|
|
$companys = $this->ci->sys_company_model->map('id','',$where,'','','',$filed);
|
|
$company = $companys[$brand_biz['company_id']][0];
|
|
$srv_company = $companys[$brand_biz['srv_company_id']][0];
|
|
}
|
|
}
|
|
if(!$company){ //获取城市销售公司
|
|
$company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>1],$filed);
|
|
}
|
|
if(!$srv_company){ //获取城市服务公司
|
|
$srv_company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>0],$filed);
|
|
}
|
|
if(!$company){ //获取固定id销售公司
|
|
$company = $this->ci->sys_company_model->get(['id'=>1],$filed);
|
|
}
|
|
if(!$srv_company){ //获取固定id服务公司
|
|
$srv_company = $this->ci->sys_company_model->get(['id'=>4],$filed);
|
|
}
|
|
//特殊需求临死写死
|
|
//if($biz['id']!=20 && $biz['city_id']==350200){ //厦门狸车销售公司
|
|
// $company = $this->ci->sys_company_model->get(['id'=>1],$filed);
|
|
//}
|
|
$data = [
|
|
'company' => $company,
|
|
'srv_company' => $srv_company
|
|
];
|
|
return $data;
|
|
}
|
|
/**
|
|
* 获取代办人用户信息
|
|
* @param $oid int 订单id
|
|
* @return array
|
|
*/
|
|
public function entrust_user($oid){
|
|
$this->ci->load->model('app/liche/app_liche_users_model');
|
|
|
|
!$this->order_row && $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
if(!$this->order_row){
|
|
return [];
|
|
}
|
|
$user = $this->ci->app_liche_users_model->get(['mobile'=>$this->order_row['owner_mobile']]);
|
|
return $user;
|
|
}
|
|
/**
|
|
* 获取订单服务费
|
|
* @param $oid int 订单id
|
|
* @param $res_type string 返回数据格式
|
|
* @return int
|
|
*/
|
|
public function order_srv_money($oid,$res_type = ''){
|
|
if(!$this->order_row){
|
|
$this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
}
|
|
$money_json = json_decode($this->order_row['money_json'],true);
|
|
$srv_price = 0;
|
|
$list = []; //明细
|
|
$services = json_decode($this->order_row['srv_ids'],true);
|
|
|
|
if($services){
|
|
$srv_ids = array_column($services,'id');
|
|
$ids = implode(',',$srv_ids);
|
|
if($srv_ids){
|
|
$where["id in ($ids)"] = null;
|
|
$rows = $this->ci->services_model->map('id','title',$where,'','','','id,title');
|
|
}
|
|
foreach($services as $key=>$val){
|
|
if($val['key']!='price_insure'){ //保险费不收
|
|
$srv_price += $money_json[$val['key']];
|
|
$list[] = [
|
|
'title' => $rows[$val['id']],
|
|
'money' => $money_json[$val['key']]
|
|
];
|
|
}
|
|
if($val['key']=='price_insure' && $res_type==1){
|
|
$list[] = [
|
|
'title' => $rows[$val['id']],
|
|
'money' => '由保险公司收取'
|
|
];
|
|
}
|
|
}
|
|
}
|
|
if($this->order_row['if_fine']){ //选择精品包
|
|
$fine_price = $money_json['price_fine'];
|
|
if($money_json['price_fine_discount']){ //优惠精品价格
|
|
$fine_price = $fine_price - $money_json['price_fine_discount'];
|
|
}
|
|
$srv_price += $fine_price;
|
|
$list[] = [
|
|
'title' => '精品尊享包',
|
|
'money' => $fine_price
|
|
];
|
|
}
|
|
if($this->order_row['fines']){
|
|
$price_fine_select = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0;
|
|
$list[] = [
|
|
'title' => '精品选装',
|
|
'money' => $price_fine_select,
|
|
];
|
|
$srv_price += $price_fine_select;
|
|
}
|
|
$result['total'] = $srv_price;
|
|
$result['list'] = $list;
|
|
return $res_type ? $result:$srv_price;
|
|
}
|
|
|
|
/**
|
|
* 生成定金订单
|
|
* @param $oid int 订单id
|
|
* @param $uid int 小程序用户id
|
|
* @return bool
|
|
*/
|
|
public function add_book_order($oid,$uid){
|
|
$this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
if(!$this->order_row){
|
|
return false;
|
|
}
|
|
$pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'type'=>4,'status>='=>0]); //意向金订单
|
|
|
|
$money_json = json_decode($this->order_row['money_json'],true);
|
|
$deposit_count = $this->ci->app_liche_orders_model->count(['o_id'=>$oid,'type'=>1,'status'=>1]); //定金已支付
|
|
$need_pay_money = $money_json['price_book'] - $pay_money['total_price'];
|
|
$res = false;
|
|
if($need_pay_money > 0 && !$deposit_count){
|
|
$entrust_user = $this->entrust_user($this->order_row['id']);
|
|
$p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'pid'=>0,'status>='=>0]);
|
|
if(!$p_row){
|
|
$sid = create_order_no(350200,'liche',1,0);
|
|
$add_data = [
|
|
'o_id' => $this->order_row['id'],
|
|
'sid' => $sid,
|
|
'pid' => 0,
|
|
'brand_id' => $this->order_row['brand_id'],
|
|
's_id' => $this->order_row['s_id'],
|
|
'v_id' => $this->order_row['v_id'],
|
|
'cor_id' => $this->order_row['cor_id'],
|
|
'incor_id' => $this->order_row['incor_id'],
|
|
'c_time' => time()
|
|
];
|
|
$uid && $add_data['uid'] = $uid;
|
|
$entrust_user['id'] && $add_data['entrust_uid'] = $entrust_user['id'];
|
|
$pid = $this->ci->app_liche_orders_model->add($add_data);
|
|
}else{
|
|
$pid = $p_row['id'];
|
|
}
|
|
$sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'type'=>1,'status>='=>0]);
|
|
if($pid && !$sub_row){
|
|
//获取微信商户号
|
|
$companys = $this->get_biz_mchid($this->order_row['biz_id'],$this->order_row['brand_id']);
|
|
$sid = create_order_no(350200,'liche',1,1);
|
|
$sub_data = [
|
|
'o_id' => $this->order_row['id'],
|
|
'sid' => $sid,
|
|
'mch_id' => $companys['company']['wx_mchid'],
|
|
'company_id' => $companys['company']['id'],
|
|
'pid' => $pid,
|
|
'type' => 1,
|
|
'brand_id' => $this->order_row['brand_id'],
|
|
's_id' => $this->order_row['s_id'],
|
|
'v_id' => $this->order_row['v_id'],
|
|
'cor_id' => $this->order_row['cor_id'],
|
|
'incor_id' => $this->order_row['incor_id'],
|
|
'total_price' => $need_pay_money,
|
|
'c_time' => time()
|
|
];
|
|
$entrust_user['id'] && $sub_data['entrust_uid'] = $entrust_user['id'];
|
|
$uid && $sub_data['uid'] = $uid;
|
|
$res = $this->ci->app_liche_orders_model->add($sub_data);
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 创建服务费和尾款
|
|
* @param $oid
|
|
* @param $uid
|
|
* @return bool
|
|
*/
|
|
public function add_order($oid,$uid){
|
|
$this->ci->load->helper('order');
|
|
$this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
$p_row = $this->ci->app_liche_orders_model->get(['pid'=>0,'o_id'=>$oid,'status>='=>0],'id'); //父订单
|
|
if(!$this->order_row || !$p_row){
|
|
return false;
|
|
}
|
|
|
|
//获取微信商户号
|
|
$companys = $this->get_biz_mchid($this->order_row['biz_id'],$this->order_row['brand_id']);
|
|
|
|
$srv_money = $this->order_srv_money($oid); //服务费
|
|
$money_json = json_decode($this->order_row['money_json'],true);
|
|
$total_price = $this->total_price($oid);
|
|
if(!$this->order_row['payway'] && !$money_json['price_loan']){//贷款未填写首付
|
|
return false;
|
|
}
|
|
$to_srv_price = $srv_money;
|
|
if($this->order_row['payway']){ //全款
|
|
$to_com_price = $total_price - $money_json['price_book'];
|
|
}else{ //分期
|
|
$to_com_price = $total_price-$money_json['price_loan'] - $money_json['price_book'];
|
|
}
|
|
$to_com_price = $to_com_price>0 ? $to_com_price : 0;
|
|
$last_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>3,'o_id'=>$oid]);
|
|
if($last_order){ //存在尾款订单
|
|
if($last_order['total_price']!=$to_com_price && $to_com_price>0){
|
|
$this->ci->app_liche_orders_model->update(['total_price'=>$to_com_price,'status'=>0],['id'=>$last_order['id']]);
|
|
}
|
|
return true;
|
|
}
|
|
$add_data = [];
|
|
$entrust_user = $this->entrust_user($oid);
|
|
if($to_srv_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>2,'status>='=>0])){
|
|
$order_type = 2;
|
|
$sid = create_order_no(350200,'liche',1,$order_type);
|
|
$add_data[] = [
|
|
'o_id' => $this->order_row['id'],
|
|
'uid' => $uid ? $uid : 0,
|
|
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
|
'sid' => $sid,
|
|
'mch_id' => $companys['srv_company']['wx_mchid'],
|
|
'company_id' => $companys['srv_company']['id'],
|
|
'pid' => $p_row['id'],
|
|
'brand_id' => $this->order_row['brand_id'],
|
|
's_id' => $this->order_row['s_id'],
|
|
'v_id' => $this->order_row['v_id'],
|
|
'cor_id' => $this->order_row['cor_id'],
|
|
'incor_id' => $this->order_row['incor_id'],
|
|
'total_price' => $to_srv_price,
|
|
'type' => $order_type,
|
|
'c_time' => time()
|
|
];
|
|
}
|
|
if($to_com_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>3,'status>='=>0])){
|
|
$book_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>1,'o_id'=>$oid]);
|
|
$book_order['mch_id'] && $companys['company']['wx_mchid'] = $book_order['mch_id'];
|
|
$book_order['company_id'] && $companys['company']['id'] = $book_order['company_id'];
|
|
$order_type = 3;
|
|
$sid = create_order_no(350200,'liche',1,$order_type);
|
|
$add_data[] = [
|
|
'o_id' => $this->order_row['id'],
|
|
'uid' => $uid ? $uid : 0,
|
|
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
|
'sid' => $sid,
|
|
'mch_id' => $companys['company']['wx_mchid'],
|
|
'company_id' => $companys['company']['id'],
|
|
'pid' => $p_row['id'],
|
|
'brand_id' => $this->order_row['brand_id'],
|
|
's_id' => $this->order_row['s_id'],
|
|
'v_id' => $this->order_row['v_id'],
|
|
'cor_id' => $this->order_row['cor_id'],
|
|
'incor_id' => $this->order_row['incor_id'],
|
|
'total_price' => $to_com_price,
|
|
'type' => $order_type,
|
|
'c_time' => time()
|
|
];
|
|
}
|
|
$result = false;
|
|
if($add_data){
|
|
$result = $this->ci->app_liche_orders_model->add_batch($add_data);
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* 计算订单应收金额
|
|
* @param $oid int 订单id
|
|
* @param $srv_price boolean 是否包含服务费
|
|
* @return float
|
|
*/
|
|
public function recevable_price($oid,$srv_price=true){
|
|
$this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
if(!$this->order_row){
|
|
return false;
|
|
}
|
|
$money_json = json_decode($this->order_row['money_json'],true);
|
|
$total_price = $this->total_price($oid);
|
|
if($srv_price){
|
|
$srv_money = $this->order_srv_money($oid);
|
|
$recevable_price = $total_price + $srv_money;
|
|
}else{
|
|
$recevable_price = $total_price;
|
|
}
|
|
|
|
if(!$this->order_row['payway']){ //分期
|
|
$recevable_price -= $money_json['price_loan'];
|
|
}
|
|
return $recevable_price;
|
|
}
|
|
|
|
/**
|
|
* 计算订单总售价
|
|
* @param $oid int 订单id
|
|
* @return float
|
|
*/
|
|
public function total_price($oid){
|
|
$order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid],'money_json');
|
|
if(!$order_row){
|
|
return false;
|
|
}
|
|
$money_json = json_decode($order_row['money_json'],true);
|
|
$total_price = $money_json['price_car'];
|
|
if($money_json['price_discount']){
|
|
$total_price -= $money_json['price_discount'];
|
|
}
|
|
if($money_json['price_color']){
|
|
$total_price += $money_json['price_color'];
|
|
}
|
|
if($money_json['price_coplus']){
|
|
$total_price += $money_json['price_coplus'];
|
|
}
|
|
return $total_price ? $total_price : 0;
|
|
}
|
|
|
|
/**
|
|
* 修改完订单信息后操作
|
|
* @param array() $new_data 修改后的数据
|
|
* @param array() $row 修改前数据
|
|
*/
|
|
public function edit_order($new_data,$row){
|
|
//更新购车订单车辆信息
|
|
$up_data = [
|
|
'brand_id' => $new_data['brand_id'],
|
|
's_id' => $new_data['s_id'],
|
|
'v_id' => $new_data['v_id'],
|
|
'cor_id' => $new_data['cor_id'],
|
|
'incor_id' => $new_data['incor_id'],
|
|
];
|
|
$this->ci->app_liche_orders_model->update($up_data,['o_id'=>$row['id']]);
|
|
//删除未支付订单
|
|
$this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]);
|
|
$userinfo = $this->ci->app_liche_users_model->get(['mobile'=>$row['mobile']],'id');
|
|
if(!$this->ci->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>1,'status'=>1])){ //不存在订单订单
|
|
$this->add_book_order($row['id'],$userinfo['id']);
|
|
}
|
|
$this->add_order($row['id'],$userinfo['id']);
|
|
//合同重新生成
|
|
if($this->ci->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)'=>null])){
|
|
$this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (0,1)'=>null]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成pdf文件
|
|
* @param $oid
|
|
* @throws Exception
|
|
*/
|
|
public function create_pdf($oid){
|
|
$this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
|
|
if(!$this->order_row ){
|
|
return ['code'=>0,'msg'=>'参数错误'];
|
|
}
|
|
if($this->ci->receiver_order_contracts_model->count(['o_id'=>$oid,'status'=>1])){
|
|
return ['code'=>1,'msg'=>'操作成功'];
|
|
}
|
|
$fill_info = $this->pdf_data($this->order_row);
|
|
$fill_data = [
|
|
'sid' => $this->order_row['sid'],
|
|
'give_time' => $fill_info['give_time'],
|
|
'date' => $fill_info['now_day'],
|
|
'company' => $fill_info['companys']['company']['title'],
|
|
'name' => $fill_info['name'],
|
|
'owner_name' => $fill_info['owner_name'],
|
|
'owner_mobile' => $fill_info['owner_mobile'],
|
|
'identify_type' => $fill_info['identify_type'],
|
|
'identify' => $fill_info['identify'],
|
|
'address' => $fill_info['address'],
|
|
'version' => $fill_info['version'],
|
|
'color' => $fill_info['color'],
|
|
'incolor' => $fill_info['incolor'],
|
|
'price_car' => $fill_info['price_car'],
|
|
'price_discount' => $fill_info['price_discount'],
|
|
'price_finance' => $fill_info['price_finance'],
|
|
'recevable_price' => $fill_info['recevable_price'],
|
|
'price_book' => $fill_info['price_book'],
|
|
'last_price' => $fill_info['last_price'],
|
|
];
|
|
$pdf_path = 'pdf/car_tpl.pdf';
|
|
$save_path = "pdf/{$this->order_row['sid']}/car.pdf";
|
|
$this->ci->load->library('pdftk');
|
|
$req = $this->ci->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data);
|
|
if(!$req['code']){
|
|
return ['code'=>0,'msg'=>$req['msg']];
|
|
}
|
|
$add_data[] = [
|
|
'o_id' => $this->order_row['id'],
|
|
'cid' => 0,
|
|
'file' => $req['data']['file_path'] ? $req['data']['file_path'] : '',
|
|
'type' => 0,
|
|
'status' => 1,
|
|
'c_time' => time()
|
|
];
|
|
if($this->order_row['srv_ids']){
|
|
$fill_data = [
|
|
'sid' => $this->order_row['sid'],
|
|
'date' => $fill_info['now_day'],
|
|
'company' => $fill_info['companys']['srv_company']['title'],
|
|
'name' => $fill_info['name'],
|
|
'mobile' => $this->order_row['owner_mobile'],
|
|
'owner_name' => $fill_info['owner_name'],
|
|
'owner_mobile' => $fill_info['owner_mobile'],
|
|
'service_str' => implode('
|
|
',$fill_info['services']),
|
|
];
|
|
$pdf_path = 'pdf/agent_tpl.pdf';
|
|
$save_path = "pdf/{$this->order_row['sid']}/service.pdf";
|
|
$res = $this->ci->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data);
|
|
if($res['code']){
|
|
$add_data[] = [
|
|
'o_id' => $this->order_row['id'],
|
|
'cid' => 0,
|
|
'file' => $res['data']['file_path'] ? $res['data']['file_path'] : '',
|
|
'type' => 1,
|
|
'status' => 1,
|
|
'c_time' => time()
|
|
];
|
|
}
|
|
}
|
|
$res = $this->ci->receiver_order_contracts_model->add_batch($add_data);
|
|
if($res){
|
|
return ['code'=>1,'msg'=>'操作成功'];
|
|
}else{
|
|
return ['code'=>0,'msg'=>'操作失败'];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取填充内容
|
|
* @param $row
|
|
* @param $type
|
|
* @return mixed
|
|
*/
|
|
public function pdf_data($row,$type=0){
|
|
if(!$row){
|
|
return false;
|
|
}
|
|
$this->ci->load->model('auto/auto_business_model');
|
|
$info_json = json_decode($row['info_json'],true);
|
|
$business_id = $info_json['business_id'] ? $info_json['business_id'] : 0;
|
|
$data = [];
|
|
|
|
//车辆信息
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount'];
|
|
$brand = $this->ci->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->ci->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$version = $this->ci->auto_attr_model->get(['id'=>$row['v_id']],'title');
|
|
$color = $this->ci->auto_attr_model->get(['id'=>$row['cor_id']],'title');
|
|
$incolor = $this->ci->auto_attr_model->get(['id'=>$row['incor_id']],'title');
|
|
$_version = $version['title'] ? $version['title'] : '';
|
|
$data['version'] = "{$brand['name']} {$series['name']} $_version";
|
|
$data['color'] = $color['title'] ? $color['title'] : '';
|
|
$data['incolor'] = $incolor['title'] ? $incolor['title'] : '';
|
|
$business_row = $this->ci->auto_business_model->get(['id'=>$business_id]);
|
|
if($business_row){
|
|
$data['give_time'] = $business_row['delivery_day'];
|
|
}else{
|
|
if($row['s_id']==24) { //零跑T03
|
|
$data['give_time'] = 60;
|
|
}elseif($row['s_id']==25) { //零跑C11
|
|
$data['give_time'] = 120;
|
|
}else{ //其它车型
|
|
$data['give_time'] = 45;
|
|
}
|
|
}
|
|
$data['price_car'] = number_format($money_json['price_car']+$money_json['price_color']+$money_json['price_coplus'],2);
|
|
$data['price_discount'] = number_format($money_json['price_discount'],2);
|
|
$data['price_book'] = number_format($money_json['price_book'],2);
|
|
$data['recevable_price'] = number_format($this->total_price($row['id']),2);
|
|
$data['last_price'] = number_format($this->total_price($row['id']) - $money_json['price_book'],2);
|
|
$data['address'] = $info_json['c_address'] ? $info_json['c_address'] : '';
|
|
$data['name'] = $row['name'];
|
|
if($row['main_type']){
|
|
$data['identify_type'] = '营业执照' ;
|
|
$data['identify'] = $info_json['c_credit'];
|
|
$data['owner_name'] = $info_json['c_company'];
|
|
$data['owner_mobile'] = $row['mobile'];
|
|
}else{
|
|
$data['identify_type'] = '身份证';
|
|
$data['identify'] = $info_json['c_owner_cardid'];
|
|
$data['owner_name'] = $row['owner_name'];
|
|
$data['owner_mobile'] = $row['owner_mobile'];
|
|
}
|
|
|
|
$data['now_day'] = date('Y-m-d');
|
|
$data['companys'] = $this->get_biz_mchid($row['biz_id'],$row['brand_id']);
|
|
if($type==1){
|
|
$items = $this->ci->items_model->get(['id'=>$row['item_id']],'vin');
|
|
$delivery = $this->ci->deliverys_model->get(['o_id'=>$row['id']],'info,tool,remark');
|
|
$data['vin'] = $items['vin'];
|
|
$data['delivery'] = $delivery;
|
|
}
|
|
if(!$type){
|
|
$services = [];
|
|
$srv_arr = json_decode($row['srv_ids'],true);
|
|
$srv_ids = array_column($srv_arr,'id');
|
|
$srv_ids_str = implode(',',$srv_ids);
|
|
if($row['srv_ids'] && $srv_ids_str){
|
|
$service_rows = $this->ci->services_model->select(["id in ({$srv_ids_str})"=>null],'','','','id,title,field_name');
|
|
foreach($service_rows as $key=>$val){
|
|
$field_arr = explode('.',$val['field_name']);
|
|
if(isset($money_json[$field_arr[1]])){ //保险费不收
|
|
$money = $field_arr[1]=='price_insure' ? '由保险公司收取' : $money_json[$field_arr[1]];
|
|
is_numeric($money) && $money = number_format($money,2);
|
|
$services[] = $val['title'].': '.$money;
|
|
}
|
|
}
|
|
}
|
|
if($row['if_fine']){ //选择精品包
|
|
$fine_price = $money_json['price_fine_discount'] ? $money_json['price_fine'] - $money_json['price_fine_discount'] : $money_json['price_fine'];
|
|
$services[] = '精品尊享包: '.number_format($fine_price,2);
|
|
}
|
|
if($row['fines']){
|
|
$fines = json_decode($row['fines'],true);
|
|
$split = $fine_title_price = $fine_title = '';
|
|
foreach($fines as $key=>$val){
|
|
$fine_title = $fine_title.$split.$val['txt'].$split;
|
|
$price = number_format($val['price'],2);
|
|
$fine_title_price = $fine_title_price.$split."{$val['txt']}:{$price}";
|
|
$split = ' ';
|
|
}
|
|
$services[] = '精品选装: '.number_format($money_json['price_fine_select'],2)."($fine_title_price)";
|
|
}
|
|
$srv_price = $this->order_srv_money($row['id']);
|
|
$services[] = '实际支付(元): '.number_format($srv_price,2);
|
|
$data['services'] = $services;
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
//小程序支付图片
|
|
public function pay_img($oid){
|
|
$this->ci->load->model('app/app_model', 'mdApp');
|
|
$wxconfig = $this->ci->mdApp->appConfig()[1]['wx'];
|
|
$img = self::API_PAY_IMG;
|
|
if ($wxconfig) {
|
|
$this->ci->load->library("hd_wechat", $wxconfig);
|
|
$width = '430px';
|
|
$path = "pages/mine/carOrder/index";
|
|
$scene = $oid;
|
|
$filename = "{$this->ci->mdApp->appConfig()[1]['app_key']}/" . substr(md5($path.'?id='.$oid), 8, 16);
|
|
$result = $this->ci->hd_wechat->qrcode($filename,$scene,$path,$width);
|
|
if($result['url']){
|
|
$img = http_host_com('api').'/'.$result['url'];
|
|
}
|
|
}
|
|
return $img;
|
|
}
|
|
}
|