Files
liche/common/libraries/receiver/Orders_v2_entity.php
T
2022-08-08 17:44:30 +08:00

785 lines
36 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 $local_bill_citys = ['350200','350500','350100']; //厦门、泉州、福州 显示本地开票按钮
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'],$this->order_row['if_local_bill']);
$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
* @param $if_local_bill int 是否开具本地发票
* @return array ['company'=>[],'srv_company'=>[]]
*/
public function get_biz_mchid($biz_id,$car_brand_id=0,$if_local_bill=false){
$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';
$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 = [
"status" => 1,
"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];
}
$local_city = false;
if(in_array($biz['city_id'],$this->local_bill_citys) && $if_local_bill){ //是否开具本地发票且在指定城市用本地城市
$local_city = true;
}
if(!$company || $local_city){ //获取城市销售公司
$company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>1,'status'=>1],$filed);
}
if(!$srv_company || $local_city){ //获取城市服务公司
$srv_company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>0,'status'=>1],$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($car_brand_id==5){
$company = $this->ci->sys_company_model->get(['id'=>2],$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 返回数据格式
* @param $is_fines int(0否 1是) 是否包含精品选装
* @return int
*/
/**
* 获取订单服务费
* @param $oid int 订单id
* @param $res_type string 返回数据格式
* @param $is_fines int
* @return array|int|mixed
*/
public function order_srv_money($oid,$res_type = '',$is_fines=1){
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']],
'key' => $val['key'],
'money' => $money_json[$val['key']]
];
}
if($val['key']=='price_insure' && $res_type==1){
$list[] = [
'title' => $rows[$val['id']],
'key' => $val['key'],
'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' => '精品尊享包',
'key' => 'price_fine_discount',
'money' => $fine_price
];
}
if($is_fines){
$fines = json_decode($this->order_row['fines'],true);
if($fines){
$price_fine_select = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0;
$list[] = [
'title' => '精品选装',
'key' => 'price_fine_select',
'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'],$this->order_row['if_local_bill']);
$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'],$this->order_row['if_local_bill']);
$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]);
$srv_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>2,'o_id'=>$oid]);
if($last_order && $srv_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 int $oid 订单id
* @param string $money_json
* @return float
*/
public function total_price($oid,$money_json=''){
if(!$money_json){
$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);
}else{
$money_json = json_decode($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,$user_info=[]){
//更新购车订单车辆信息
$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])){ //不存在定金订单
$int_order = $this->ci->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>4,'status'=>1]); //意向金订单
$money_json = json_decode($new_data['money_json'],true);
if($int_order['pay_price']==$money_json['price_book']){ //意向金订单转支付订单、推送并且生成pfd
$this->ci->app_liche_orders_model->update(['type'=>1],['id'=>$int_order['id']]);
$this->ci->receiver_orders_v2_model->update(['order_time'=>date('Y-m-d H:i:s')],['id'=>$row['id']]);
//生成pdf
$this->create_pdf($row['id']);
$this->ci->load->library('qyrobot');
$this->ci->qyrobot->deposit_notify_v3($row['id']);
}else{
$this->add_book_order($row['id'],$userinfo['id']);
}
}
$this->add_order($row['id'],$userinfo['id']);
//合同重新生成
$need_del_con = false;
if($this->ci->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)'=>null])){
$need_del_con = true;
}
if($new_data['if_local_bill']!=$row['if_local_bill']){
$need_del_con = true;
}
if($need_del_con){
$this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (0,1)'=>null]);
}
$is_pay = $this->ci->app_liche_orders_model->count(['o_id'=>$row['id'],'type!='=>4,'status'=>1]);
if($is_pay &&
($new_data['brand_id']!=$row['brand_id'] || $new_data['s_id']!=$row['s_id'] || $new_data['v_id']!=$row['v_id']) ||
$new_data['cor_id']!=$row['cor_id'] || $new_data['incor_id'] != $row['incor_id']
){ //存在已支付订单并且修改车型 写日志
$where = [
"lc_auto_series.id in ({$new_data['s_id']},{$row['s_id']})" => null
];
$brand = $this->ci->auto_series_model->select_brand($where);
foreach ($brand as $key=>$value) {
$brand[$value['id']] = $value;
}
$ids = [$new_data['v_id'],$row['v_id'],$new_data['cor_id'],$row['cor_id'],$new_data['incor_id'],$new_data['incor_id']];
$ids_str = implode(',',$ids);
$where = [
"id in ({$ids_str})" => null
];
$attr = $this->ci->auto_attr_model->map('id','title',$where);
$old_title = "{$brand[$row['s_id']]['b_name']}-{$brand[$row['s_id']]['name']}-{$attr[$row['v_id']]}-{$attr[$row['cor_id']]}-{$attr[$row['incor_id']]}";
$new_title = "{$brand[$new_data['s_id']]['b_name']}-{$brand[$new_data['s_id']]['name']}-{$attr[$new_data['v_id']]}-{$attr[$new_data['cor_id']]}-{$attr[$row['incor_id']]}";
$content = "车型由 {$old_title} 变更为 {$new_title}";
$this->ci->load->library('receiver/orders_entity');
$this->ci->orders_entity->add_log($row['id'],$user_info['uid'],$user_info['uname'],$content);
//短信通知
$params = [
'sid' => $row['sid']."({$row['owner_name']})",
'car_a' => $old_title,
'car_b' => $new_title,
];
$this->send_msg('SMS_241355543',$params);
}
}
/**
* 生成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'=>'操作成功'];
}
$need_sign = true;
if($this->order_row['brand_id'] == 4){ //除宁德哪吒需要购车合同
$biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'city_id');
$need_sign = $biz['city_id'] == '350900' ? true : false;
}
$fill_info = $this->pdf_data($this->order_row);
$this->ci->load->library('pdftk');
if($need_sign) {
$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';
if ($fill_info['sa']) {
$fill_data['sa'] = $fill_info['sa'];
$pdf_path = 'pdf/car_sa_tpl.pdf';
}
$save_path = "pdf/{$this->order_row['sid']}/car.pdf";
$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){
//更新交付时间
$car_json = json_decode($this->order_row['car_json'],true);
$over_time = date('Y-m-d H:i:s',time()+$car_json['delivery_day']*24*60*60); //交付截止时间
$this->ci->receiver_orders_v2_model->update(['over_time'=>$over_time],['id'=> $this->order_row['id']]);
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 = [];
$biz = $this->ci->biz_model->get(['id'=>$row['biz_id']]);
//车辆信息
$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'],$row['if_local_bill']);
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;
}
$data['sa'] = '';
if($biz['type']==1){
$this->ci->load->model('receiver/order/receiver_order_datas_model');
$order_data = $this->ci->receiver_order_datas_model->get(['o_id'=>$row['id']]);
$order_data['sa'] && $data['sa'] = $order_data['sa'];
}
if(!$type){
$services = [];
$srv_arr = json_decode($row['srv_ids'],true);
if(is_array($srv_arr)){
$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 = $val['price']>0 ? number_format(floatval($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;
}
/**
* 订单改变发送消息
* @param $sid
* @param $info
* @return void
*/
public function send_msg($template,$params){
/**
* 模板内容 SMS_241360549
* 叮~小爱同学,订单 ${sid} 信息发生变化。车主信息由 ${owner_a} 变更为 ${owner_b},请知悉~
* 模板内容 SMS_241355543
* 叮~小爱同学,订单 ${sid} 信息发生变化。客户订购车型由 ${car_a} 变更为 ${car_b},请知悉~
*/
if(!template || !$params){
return '';
}
$mobile_lists = ['18950000118','13860199646'];
!is_product() && $mobile_lists = ['18350451617']; //测试
foreach ($mobile_lists as $val){
send_alisms(array('mobile' => $val, 'template' => $template, 'param' => $params));
}
}
}