Files
liche/admin/controllers/receiver/orderv2/Orders.php
T
2022-06-21 15:57:10 +08:00

1187 lines
55 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Orders extends HD_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('receiver/order/receiver_orders_v2_model');
$this->load->model('receiver/order/receiver_order_status_model');
$this->load->model('receiver/order/receiver_order_datas_model');
$this->load->model('receiver/order/receiver_order_loans_model', 'order_loans_model');
$this->load->model('receiver/order/receiver_order_ckcars_model', 'order_ckcars_model');
$this->load->model('receiver/order/receiver_order_bills_model', 'order_bills_model');
$this->load->model('receiver/order/receiver_order_agents_model', 'order_agents_model');
$this->load->model('receiver/order/receiver_order_deliverys_model', 'order_deliverys_model');
$this->load->model('receiver/order/receiver_order_contracts_model', 'order_contracts_model');
$this->load->model('receiver/order/receiver_order_oplogs_model','order_oplogs_model');
$this->load->model('receiver/receiver_customers_model', 'customers_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('auto/auto_finance_model');
$this->load->model('sys/sys_finance_model');
$this->load->model('sys/sys_company_model');
$this->load->model("sys/sys_area_model");
$this->load->model('app/liche/app_liche_orders_model');
$this->load->model('app/liche/app_liche_users_model');
$this->load->model('app/app_checkdata_model');
$this->load->library('receiver/orders_entity');
$this->load->library('receiver/orders_v2_entity');
$this->load->library('receiver/orders_status_entity');
$this->load->library('receiver/order_datas_entity');
$this->load->library('Ordersv2List');
$this->load->library('qyrobot');
$this->load->library('TcOrc');
}
public function index()
{
$this->lists();
}
public function lists()
{
$old_oid = Orders_v2_entity::V2_START_ID;
$params = $this->input->get();
$statusAry = $this->receiver_order_status_model->statusAry();
$status_arr = array();
$t1 = 'lc_receiver_orders_v2';
$t2 = 'lc_receiver_order_status';
foreach ($statusAry as $key => $value) {
if (!$value['show']) {
continue;
}
$cate = $where = array();
$where["$t1.status<>"] = -1;
strlen($value['pid_status']) && $where["$t1.brand_id>"] = 0;
if(strlen($value['pid_status']) && $value['pid_status']){
$where["$t1.id>="] = $old_oid;
}
if(is_product()){
$where["{$t1}.brand_id<>3"] = null;//狸车品牌不显示
$where["{$t1}.biz_id<>1"] = null;//biz_id=1不显示
}
if ($value['list']) {
foreach ($value['list'] as $key2 => $value2) {
if($key2 && $key2<21){
$where_s = [];
$key==1 && $where_s["{$t1}.payway"] = 0;//分期
$where_s["{$t1}.status <>"] = 2; //滤退款
if($key==4){ //交付需要开票后才显示
$where_s["{$t1}.id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)"] = null;
}
if($key2){
$where_s["{$t2}.pid_status"] = $value['pid_status'];
$up_key = $key2+1;
$where_s["{$t2}.status in ({$key2},{$up_key})"] = null;
}
$where_s = array_merge($where,$where_s);
$having = 'total = 1';
if($key==0 && $key2==1){ //已付款
$having = 'total >= 1';
}
$count2 = $this->receiver_orders_v2_model->selectOrders($where_s,'','', '', 1,'',$having);
}else{
$where_s = [
"id not in (select o_id from lc_receiver_order_status where pid_status={$value['pid_status']} and status=1)" => null
];
$where_s["status <>"] = 2; //滤退款
$key==1 && $where_s['payway'] = 0;
$key==3 && $where_s['id in (select o_id from lc_receiver_order_status where pid_status=0 and status=2)'] = null;
if($key==4){ //交付需要开票后才显示
$where_s["{$t1}.id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)"] = null;
}
if($key2==21){
$where_s = [
"{$t1}.id in (select o_id from lc_receiver_order_status where pid_status=0 and status=1)" => null, //已付定金
"{$t1}.id not in (select o_id from lc_receiver_order_status where pid_status=0 and status=2)" => null //尾款未支付
];
}
$where_s = array_merge($where,$where_s);
$count2 = $this->receiver_orders_v2_model->count($where_s);
}
$cate[] = array("id" => $key2, "name" => $value2, "count" => $count2);
}
}
$status_arr[] = array("id" => $key, "name" => $value['name'], "cate" => $cate, "count" => 0);
}
$where = ["{$t1}.status<>" => -1];
if(is_product()){
$where["{$t1}.brand_id<>"] = 3;//狸车品牌不显示
$where["{$t1}.biz_id<>"] = 1;//biz_id=1不显示
}
$params['status_pid'] == 5 && $params['status'] = 1;
$params['count_all'] = $this->receiver_orders_v2_model->count($where);//全部
$params['list_type'] = 'all';
$result = $this->ordersv2list->lists($params['status_pid'], $params);
$this->data = $result;
$this->data['status_arr'] = $status_arr;
return $this->show_view($result['view'], true);
}
public function get()
{
$id = $this->input->get('id');
$row = $this->receiver_orders_v2_model->get(['id' => $id]);
$customers = $this->customers_model->get(['id' => $row['customer_id']]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '订单不存在!');
}
if ($customers['of_id']) {//客户来源
$of_ary = $this->customers_model->offlineSources($customers['of_id']);
$of_title = $of_ary['name'];
$customers['of2_id'] && $of_title .= '-' . $of_ary['list'][$customers['of2_id']];
$row['of_title'] = $of_title;
}
$money_json = json_decode($row['money_json'], true);
$deposit = $money_json['price_book'];
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : array();
$row['price_discount'] = $money_json['price_discount'];
//售价详细信息
$sale_detail = "指导价:".number_format($money_json['price_car'],2);
$money_json['price_discount'] && $sale_detail .= ',优惠金额:'.number_format($money_json['price_discount'],2);
$money_json['price_color'] && $sale_detail .= ',颜色加价:'.number_format($money_json['price_color'],2);
$money_json['price_coplus'] && $sale_detail .= ',公司加价:'.number_format($money_json['price_coplus'],2);
$row['sale_detail'] = $sale_detail;
$sale_price = $this->orders_v2_entity->total_price($row['id']);
$row['sale_price'] = number_format($sale_price, 2);
$row['info_json'] = json_decode($row['info_json'], true);
$row['status'] = intval($row['status']);
$row['price'] = number_format($money_json['price_car'], 2);
$row['deposit'] = number_format($deposit, 2);
$row['c_time'] = date('Y-m-d', $row['c_time']);
$row['payway'] = intval($row['payway']);
$row['item_id'] = intval($row['item_id']);
$row['cardid'] = $row['info_json']['c_cardid'] ? $row['info_json']['c_cardid'] :'';
$row['address'] = $row['info_json']['c_address'] ? $row['info_json']['c_address'] : '';
$row['owner_cardid'] = $row['info_json']['c_owner_cardid'] ? $row['info_json']['c_owner_cardid'] : '';
$row['credit'] = $row['info_json']['c_credit'] ? $row['info_json']['c_credit'] : '';
$row['company'] = $row['info_json']['c_company'] ? $row['info_json']['c_company'] : '';
$row['car_city_name'] = '';
if($row['info_json']['car_city_id']){
$city_row = $this->sys_area_model->get(['city_id'=>$row['info_json']['car_city_id']],'city_name');
$row['car_city_name'] = $city_row['city_name'];
}
$row['note'] = $jsondata['note'] ? $jsondata['note'] : '';
//获取车信息
$brand = $this->auto_brand_model->get(['id' => $row['brand_id']], 'name');
$serie = $this->auto_series_model->get(['id' => $row['s_id']], 'name');
$row['brand_name'] = $brand['name'];
$row['s_name'] = $serie['name'];
$attr_arr = [$row['v_id'], $row['cor_id'], $row['incor_id']];
$attr = $this->auto_attr_model->get_map_by_ids($attr_arr, 'id,title');
$row['v_name'] = isset($attr[$row['v_id']]) ? $attr[$row['v_id']][0]['title'] : '';
$row['cor_name'] = isset($attr[$row['cor_id']]) ? $attr[$row['cor_id']][0]['title'] : '';
$row['incor_name'] = isset($attr[$row['incor_id']]) ? $attr[$row['incor_id']][0]['title'] : '';
//获取选择车辆vin
if ($row['item_id']) {
$this->load->model('items/items_model', 'mdItems');
$row_goods = $this->mdItems->get(array('id' => $row['item_id']));
$row['vin'] = $row_goods['vin'];
}
$row['delry_time'] = $row['delry_time'] != '0000-00-00 00:00:00'
? str_replace(" 00:00:00", "", $row['delry_time']) : '';
//获取车辆服务费
$srv_info = $this->orders_v2_entity->order_srv_money($row['id'], 2);
$srv_info['total'] = number_format($srv_info['total'], 2);
$srv_detail = "";
if ($srv_info['list']) {
foreach ($srv_info['list'] as $key => $val) {
$d = $srv_detail ? ',' : '';
$srv_detail .= $d . $val['title'] . ":" . number_format(floatval($val['money']), 2);
}
}
$srv_info['detail'] = $srv_detail;
$row['srv_info'] = $srv_info;
//获取贷款信息
if (!$row['payway']) {
$loan = $this->order_loans_model->get(['o_id' => $row['id']]);
$loan['notify_file'] = $loan['notify_file'] ? build_qiniu_image_url($loan['notify_file']) : '';
$loan['notify_file_name'] = $loan['notify_file'] ? end(explode('/', $loan['notify_file'])) : '';
$loan['lend_file'] = $loan['lend_file'] ? build_qiniu_image_url($loan['lend_file']) : '';
$loan['lend_file_name'] = $loan['lend_file'] ? end(explode('/', $loan['lend_file'])) : '';
$loan['finance_rows'] = $this->sys_finance_model->select(['status' => 1], '', 0, 0, 'id,title');
$loan['price_loan'] = $money_json['price_loan'] ? $money_json['price_loan'] : '';
$loan['first_pay'] = 0;
if ($money_json['price_loan']) {
$loan['first_pay'] = $sale_price - $money_json['price_loan'];
}
!$loan['num'] && $loan['num'] = 12;
$loan['loan_time'] = $loan['loan_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($loan['loan_time'])) : '';
$status_array = $this->receiver_order_status_model->select(['o_id'=>$row['id'],'pid_status'=>1],'','','id,status');
$loan['status_array'] = array_column($status_array,'status');
$row['loan_info'] = $loan;
}
//获取审核资料信息
$img_data = $this->receiver_order_datas_model->get(['o_id'=>$row['id'],'status>='=>0]);
$row['imgs_status'] = $this->order_datas_entity->data_ckinfo($img_data,$row['main_type']);
//获取开票
$bill = $this->order_bills_model->get(['o_id' => $row['id']], 'status,file');
$bill_status = $this->receiver_order_status_model->get(['o_id'=>$row['id'],'pid_status'=>3,'status'=>1]); //是否已开票
$bill['file'] = $bill['file'] ? build_qiniu_image_url($bill['file']) : '';
$bill['file_type'] = $bill['file'] && strstr($bill['file'], '.pdf') ? 'pdf' : 'img';
$bill['cardidA'] = $img_data['cardida'];
$bill['cardidB'] = $img_data['cardidb'];
$bill['business_licence'] = $img_data['business_licence'];
$bill['status'] = $bill_status ? 1 : 0;
$row_goods['company_id'] && $item_company = $this->sys_company_model->get(['id'=>$row_goods['company_id']],'id,short');
if(!$item_company){
$item_html = '车辆归属<b>未选择</b>';
}else{
$item_html = "车辆公司归属<b>【{$item_company['short']}】</b>";
}
$pay_order = $this->app_liche_orders_model->get(['type'=>3,'status'=>1,'o_id'=>$row['id']],'mch_id');
$pay_order && $pay_compay = $this->sys_company_model->get(['wx_mchid' => $pay_order['mch_id']],'id,short');
$pay_html = '';
if($pay_compay){
$ck_html = $pay_compay['id'] == $item_company['id'] ? '<b class="am-text-success">一致</b>' : '<b class="am-text-warning">不一致</b>';
$pay_html = "与尾款收款公司<b>【{$pay_compay['short']}】</b> {$ck_html}";
}
$bill['warning'] = $item_html. $pay_html;
$row['bill'] = $bill;
//获取合同文件
$contracts = $this->order_contracts_model->select(['o_id' => $row['id'], 'status' => 1], '', '', '', 'id,type,file,status');
$contract_data = [];
if ($contracts) {
foreach ($contracts as $key => $val) {
$contract_data[$val['type']] = [
'type' => $val['type'],
'status' => $val['status'],
// 'src' => http_host_com('api').'/'.$val['file'],
'src' => http_host_com('api').'/wxapp/licheb/protocol/pdf_img?id='.$val['id'],
];
}
}
$row['contract_data'] = $contract_data;
//获取图片识别信息
$agent = $this->order_agents_model->get(['o_id' => $row['id']]);
$company = $ins_risk = $business_risk = '';
if ($agent) {
$agent['ins_time'] = $agent['ins_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($agent['ins_time'])) : '';
$agent_jsondata = $agent['jsondata'] ? json_decode($agent['jsondata'], true) : '';
if ($agent_jsondata) {
$company = $agent_jsondata['company'];
$ins_risk = $agent_jsondata['ins_risk'];
$business_risk = $agent_jsondata['business_risk'];
}
}
$agent['company'] = $company;
$agent['ins_risk'] = $ins_risk;
$agent['business_risk'] = $business_risk;
$row['agent'] = $agent;
//获取销售员
if ($row['sale_id']) {
$this->load->model('app/licheb/app_licheb_users_model', 'licheb_users_model');
$this->load->model("biz/biz_model");
$row_admin = $this->licheb_users_model->get(array('id' => $row['sale_id']));
$biz_id = $row_admin['biz_id'];
$row_biz = array();
if ($biz_id) {
$row_biz = $this->biz_model->get(array('id' => $biz_id));
}
$admin_name = $row_admin ? "{$row_biz['biz_name']} {$row_admin['uname']}" : "";
$row['admin_name'] = $admin_name;
}
//日志
$where = [
'order_id' => $row['id']
];
$logs = $this->order_oplogs_model->select($where,'id desc',1,30,'uname,log,c_time');
$row['is_admin'] = $this->role==SUPER_ADMIN ? true : false;
$info = $row;
$this->data['info'] = $info;
$this->data['logs'] = $logs;
$this->data['_title'] = '订单详情';
return $this->show_view('receiver/orderv2/get/index', true);
}
//添加单条数据
public function add()
{
}
//编辑单条数据
public function edit()
{
$params = $this->input->post();
if (!$params['id']) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$result = '';
if ($params['type'] == 1) {//修改备注
$re = $this->receiver_orders_v2_model->get(['id' => $params['id']]);
$jsondata = json_decode($re['jsondata'], true);
$jsondata['note'] = $params['note'];
$upd = array('jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE));
$result = $this->receiver_orders_v2_model->update($upd, ['id' => $params['id']]);
} else if ($params['type'] == 2) {//修改营业执照
if (!$params['business_licence']) {
return $this->show_json(SYS_CODE_FAIL, '请上传营业执照');
}
if (!$this->order_bills_model->get(['o_id' => $params['id']])) {
$this->order_bills_model->add(['o_id' => $params['id'], 'c_time' => time()]);
}
$result = $this->order_bills_model->update(array('business_licence' => $params['business_licence']), ['o_id' => $params['id']]);
}
if ($result) {
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
/**
* 更新身份证信息
* @return bool
*/
function edit_cardID()
{
$o_id = $this->input->post('o_id');
$cardidA = $this->input->post('cardidA');
$cardidB = $this->input->post('cardidB');
if (!$this->receiver_order_datas_model->get(['o_id' => $o_id])) {
$this->order_bills_model->add(['o_id' => $o_id, 'c_time' => time()]);
}
if (!$cardidA || !$cardidB) {
return $this->show_json(SYS_CODE_FAIL, '请上传身份证照片');
}
$cardidA_src = build_qiniu_image_url($cardidA);
$result = $this->tcorc->IdentityCard($cardidA_src);
if (!$result['code']) {
return $this->show_json(SYS_CODE_FAIL, '身份证校验不通过');
} else {
//校验姓名
$uname = $result['data']['Name'];
$idnum = $result['data']['IdNum'];
$row_order = $this->receiver_orders_v2_model->get(['id' => $o_id]);
$info_json = json_decode($row_order['info_json'],true);
if ($uname != $row_order['name']) {
return $this->show_json(SYS_CODE_FAIL, '身份证姓名与客户不一致');
}
if ($idnum != $info_json['c_owner_cardid']) {
return $this->show_json(SYS_CODE_FAIL, '身份证号码与客户不一致');
}
}
$upd = array(
'cardidA' => $cardidA,
'cardidB' => $cardidB,
'status' => 1
);
$result = $this->order_bills_model->update($upd, ['o_id' => $o_id]);
if ($result) {
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
$params = $this->input->get();
$params['page'] = 1;
$params['size'] = 10000;
$indexs = [];
$fieldAry = $this->ordersv2list->get_fields($params['status_pid'], 1);
foreach ($fieldAry as $key => $value) {
$indexs[$key] = $value['title'];
}
$result = $this->ordersv2list->lists($params['status_pid'], $params);
$fileName = $result['_title'];
foreach ($result['lists'] as $key => $value) {
$temp = array();
foreach ($fieldAry as $key2 => $value2) {
$temp[$key2] = $value[$key2];
}
$data[] = $temp;
}
array_unshift($data, $indexs);
$this->load->library('excel');
return $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
//修改分期
public function edit_loan()
{
$params = $this->input->post();
$info = $params['info'];
$oid = $params['id'] ? $params['id'] : $info['id'];
$file = $_FILES['file'];
$row = $this->order_loans_model->get(['o_id' => $oid]);
if (!$row) {
$this->order_loans_model->add(['o_id' => $oid, 'c_time' => time()]);
$row = $this->order_loans_model->get(['o_id' => $oid]);
}
$update = [];
if ($file) { //上传按揭通知函
$path = FCPATH . 'temp/';
if (!file_exists($path)) {
$oldumask = umask(0);
mkdir($path, 0777, true);
umask($oldumask);
}
$file_name = md5($file['name'] . uniqid()) . '.' . end(explode('.', $file['name']));
$tmp = $path . $file_name;
move_uploaded_file($file['tmp_name'], $tmp);
if (!filesize($tmp)) {
return $this->show_json(SYS_CODE_FAIL, '上传文件失败!');
}
$this->load->library('qiniu');
$res = $this->qiniu->save($file_name, file_get_contents($tmp));
unlink($tmp);
if (!$res) {
return $this->show_json(SYS_CODE_FAIL, '上传文件失败!');
}
if ($params['type']) {
$update['lend_file'] = $res['file'];
} else {
$update['notify_file'] = $res['file'];
}
$this->data['file_url'] = build_qiniu_image_url($res['file']);
}
strlen($params['status']) && $update['status'] = $params['status'];
if ($params['status'] == 1) { //等待放款
$finance_id = $info['finance_id'];
$price_loan = $info['loan_info']['price_loan'];
if (!$row['notify_file']) {
return $this->show_json(SYS_CODE_FAIL, '请先上传按揭通知函!');
}
if (!$finance_id || !$price_loan) {
return $this->show_json(SYS_CODE_FAIL, '请填写完整信息!');
}
$order_row = $this->receiver_orders_v2_model->get(['id' => $row['o_id']], 'id,mobile,money_json');
$money_json = json_decode($order_row['money_json'], true);
$money_json['price_loan'] = $price_loan;
$this->receiver_orders_v2_model->update(['finance_id' => $finance_id, 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE)], ['id' => $row['o_id']]);
//生成购车订单
$userinfo = $this->app_liche_users_model->get(['mobile'=>$order_row['mobile']]);
$this->orders_v2_entity->add_order($order_row['id'],$userinfo['id']);
$result = $this->orders_status_entity->set_status($oid,1,1);
}elseif($params['status'] == 2){ //完成按揭
$loan_time = $info['loan_info']['loan_time'];
if (!$loan_time) {
return $this->show_json(SYS_CODE_FAIL, '请选择放款时间!');
}
if (!$row['lend_file']) {
return $this->show_json(SYS_CODE_FAIL, '请先上传按揭放款函!');
}
$update['loan_time'] = date('Y-m-d H:i:s', strtotime($loan_time));
$result = $this->orders_status_entity->set_status($oid,1,2);
}
if($update){
$result = $this->order_loans_model->update($update, ['id' => $row['id']]);
}
return $result ? $this->show_json(SYS_CODE_SUCCESS, '保存成功') : $this->show_json(SYS_CODE_FAIL, '保存失败');
}
public function edit_item()
{
$this->load->model("items/items_model");
$id = $this->input->post('id');
$item_id = $this->input->post('item_id');
$row = $this->receiver_orders_v2_model->get(['id' => $id]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if (!$item_id) return $this->show_json(SYS_CODE_FAIL, '请选择车辆!');
// if ($this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1])) {
// return $this->show_json(SYS_CODE_FAIL, '已开票,不能修改!');
// }
$res = $this->receiver_orders_v2_model->update(['item_id' => $item_id], ['id' => $id]);
if (!$res) {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
if ($row['item_id'] && $row['item_id'] != $item_id) {
$this->items_model->update(['status' => 1], ['id' => $row['item_id']]);
}
$result = $this->items_model->update(['status' => 2], ['id' => $item_id]);
if ($result) {
$this->orders_status_entity->set_status($id,2,1);
}
if ($result) {
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
//查看发票信息
public function get_bill()
{
$oid = $this->input->get('oid');
$row = $this->receiver_orders_v2_model->get(['id' => $oid]);
$bill = $this->order_bills_model->get(['o_id' => $oid]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if (!$bill) {
$add_data = [
'o_id' => $row['id'],
'c_time' => time()
];
$bill['id'] = $this->order_bills_model->add($add_data);
}
$bill['src_file'] = $bill['file'] ? build_qiniu_image_url($bill['file']) : '';
$bill['bill_time'] = $row['bill_time'] != '0000-00-00 00:00:00' ? $row['bill_time'] : '';
$this->data['bill'] = $bill;
return $this->show_view('receiver/orderv2/get/get_bill');
}
//编辑发票信息
public function edit_bill()
{
$id = $this->input->post('id');
$file = $this->input->post('value');
$row_order = $this->receiver_orders_v2_model->get(array('id' => $id));
if(!$file || !$row_order){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$row = $this->order_bills_model->get(['o_id' => $row_order['id']]);
if(!$row){
$jsondata = [];
$this->order_bills_model->add(['c_time'=>time(),'o_id'=>$row_order['id']]);
}else{
$jsondata = json_decode($row['jsondata'],true);
}
//图片识别
$img_url = build_qiniu_image_url($file);
$orc_res = $this->tcorc->CarInvoiceInfos($img_url);
if (!$orc_res['code']) {
return $this->show_json(SYS_CODE_FAIL, $orc_res['msg']);
}
$bill_time = date('Y-m-d H:i:s');
$carinfo = $orc_res['data']['CarInvoiceInfos'];
if(is_array($carinfo)){
foreach($carinfo as $kye=>$val){
if($val['Name']=='开票日期'){
$bill_time = $val['Value'];
break;
}
}
}
$jsondata['infos'] = $carinfo;
$update['file'] = $file;
$update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
$result = $this->order_bills_model->update($update, ['o_id' => $row_order['id']]);
if ($result) {
//更新开票时间
$this->load->model('items/items_model');
$upd = array('bill_time' => $bill_time);
$where = array('id' => $row_order['item_id']);
$ret = $this->items_model->update($upd, $where);
if ($ret) { //添加开票日志
$this->load->library('entity/items_entity');
$re_i = $this->items_model->get(['id' => $row_order['item_id']]);
$params = array('item_id' => $row_order['item_id'], 'type' => 3, 'uid' => $this->uid, 'uname' => $this->username
, 'com_time' => $bill_time, 'biz_id' => $re_i['biz_id'], 'addr_id' => $re_i['addr_id']);
$this->items_entity->add_log($params);
}
$this->receiver_orders_v2_model->update(['bill_time' => $bill_time], ['id' => $row_order['id']]);
$this->orders_status_entity->set_status($row_order['id'],3,1);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
//确定交款
public function edit_jk()
{
$oid = $this->input->post('oid');
$row = $this->receiver_orders_v2_model->get(['id' => $oid]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$bill = $this->order_bills_model->get(['o_id' => $oid]);
if (!$bill['file'] || !$bill['money']) {
return $this->show_json(SYS_CODE_FAIL, '未上传开票文件或未填写到账金额!');
}
$where = [
'o_id' => $oid,
'status' => 1,
'pay_price>' => 0
];
$sum = $this->app_liche_orders_model->sum('total_price', $where); //已收金额
$need_price = $this->orders_v2_entity->recevable_price($oid); //应收金额
if ($sum['total_price'] < $need_price) {
return $this->show_json(SYS_CODE_FAIL, '修改失败,已收金额小于应收金额!');
}
$this->order_bills_model->update(['status' => 2], ['o_id' => $oid]);
$this->orders_status_entity->set_status($oid,3,1);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
//获取合同图片
public function get_cimgs()
{
$type = $this->input->get('type');
$oid = $this->input->get('oid');
$row = $this->order_contracts_model->get(['type' => $type, 'o_id' => $oid]);
$info['title'] = '相册标题';
$info['id'] = '222';
$info['start'] = 0;
$data = [];
if ($row) {
$imgs = json_decode($row['imgs'], true);
foreach ($imgs as $key => $val) {
$data[] = [
'alt' => '图片名',
'pid' => $key,
'src' => build_qiniu_image_url($val),
'thumb' => build_qiniu_image_url($val)
];
}
}
$info['data'] = $data;
$this->data['info'] = $info;
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
//支付列表
public function get_paylog()
{
$params = $this->input->get();
if ($params['d_type'] == 'ajax') {
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 10;
$list = [];
$where = [
'o_id' => $params['id'],
'status' => 1,
"id not in (select id from lc_app_liche_orders where (type=3 and o_id={$params['id']} and pay_price=0) or (o_id={$params['id']} and pid=0))" => null
];
$count = $this->app_liche_orders_model->count($where);
if ($count) {
$rows = $this->app_liche_orders_model->select($where, 'id desc', $page, $size, 'id,total_price,type,pay_time,mch_id,descrip,status,pid,img,admin_id');
$type_arr = $this->app_liche_orders_model->get_type_arr();
foreach ($rows as $item) {
$company = '';
if ($item['mch_id']) {
$company = $this->sys_company_model->get(['wx_mchid' => $item['mch_id']], 'short');
}
$opt_name = '用户';
if($item['admin_id']){
$admin_user = $this->sys_admin_model->get(array('id' => $item['admin_id']),'username');
$opt_name = $admin_user['username'];
}
$list[] = [
'id'=> $item['id'],
'money' => $item['total_price'],
'type_cn' => $type_arr[$item['type']],
'pay_time' => $item['pay_time'],
'company' => $company ? $company['short'] : '',
'opt_name' => $opt_name,
'descrip' => $item['descrip'],
'img' => $item['img'] ? build_qiniu_image_url($item['img']) : '',
];
}
}
$sum = $this->app_liche_orders_model->sum('total_price', ['o_id'=>$params['id'],'status'=>1,'pay_price <>'=>0]);
$this->data['pay_price'] = $sum['total_price'];
$this->data['need_price'] = $this->orders_v2_entity->recevable_price($params['id']);
$this->data['list'] = $list;
$hasNext = ceil($count / $size) > $page ? 1 : 0;
$this->data['commonPage'] = array('page' => $page, 'pageLimit' => $size, 'pageCount' => $count, 'hasNext' => $hasNext);
$car_info = [
'vin' => ''
];
$row = $this->receiver_orders_v2_model->get(['id' => $params['id']]);
$car_info['name'] = $row['owner_name'];
//获取车信息
$brand = $this->auto_brand_model->get(['id' => $row['brand_id']], 'name');
$serie = $this->auto_series_model->get(['id' => $row['s_id']], 'name');
$row['brand_name'] = $brand['name'];
$row['s_name'] = $serie['name'];
$attr_arr = [$row['v_id'], $row['cor_id'], $row['incor_id']];
$attr = $this->auto_attr_model->get_map_by_ids($attr_arr, 'id,title');
$row['v_name'] = isset($attr[$row['v_id']]) ? $attr[$row['v_id']][0]['title'] : '';
$row['cor_name'] = isset($attr[$row['cor_id']]) ? $attr[$row['cor_id']][0]['title'] : '';
$row['incor_name'] = isset($attr[$row['incor_id']]) ? $attr[$row['incor_id']][0]['title'] : '';
$car_info['car'] = "{$row['brand_name']}-{$row['s_name']}-{$row['v_name']}-{$row['incor_name']}";
//获取选择车辆vin
if ($row['item_id']) {
$this->load->model('items/items_model', 'mdItems');
$row_goods = $this->mdItems->get(array('id' => $row['item_id']));
$car_info['vin'] = $row_goods['vin'];
}
$this->data['car_info'] = $car_info;
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
$this->data['id'] = $this->input->get('id');
return $this->show_view('receiver/orderv2/get/paylog');
}
//添加支付日志
public function add_paylog()
{
$id = $this->input->get_post('id');
$row = $this->receiver_orders_v2_model->get(['id' => $id]);
$srv_price = $this->orders_v2_entity->order_srv_money($row['id']);
$need_price = $this->orders_v2_entity->recevable_price($row['id']);
$car_price = $need_price-$srv_price;
if ($this->input->method() == 'post') {
$money = $this->input->post('money');
$pay_time = $this->input->post('pay_time');
$wx_mchid = $this->input->post('wx_mchid');
$descrip = $this->input->post('descrip');
$type = $this->input->post('type');
$img = $this->input->post('img');
if (!$money || !$pay_time || !$row || !$wx_mchid) {
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$p_row = $this->app_liche_orders_model->get(['pid'=>0,'o_id'=>$row['id']]);
$last_p_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>3,'pid'=>$p_row['id'],'status>='=>0]); //尾款父订单
if($type==6){ //尾款
if($money>$car_price){
return $this->show_json(SYS_CODE_FAIL, '车款金额错误');
}
$this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id'],'status'=>0,'type'=>1]); //定金更新成无效订单
$money_json = json_decode($row['money_json'],true);
$last_pay_count = $this->app_liche_orders_model->count(['pid'=>$last_p_row['id'],'type'=>3,'status'=>1]);//尾款支付订单
$adimn_count = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>6,'status'=>1]);//车款订单
if(!$last_pay_count && ($money!=$money_json['price_book'] || $adimn_count)){ //若首笔金额 == 定金金额,尾款订单不要置为 -1若金额 > 定金金额 或者 非首笔,尾款订单置为 -1
$this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id'],'type'=>3]); //尾款更新成无效订单
}
}else{ //服务费
if($money>$srv_price){
return $this->show_json(SYS_CODE_FAIL, '服务费金额错误');
}
$this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id'],'type'=>2,'status'=>0]); //未支付更新成无效订单
}
$this->load->helper('order');
$sid = create_order_no(350200, 'liche', 1, $type);
$data = [
'o_id' => $row['id'],
'sid' => $sid,
'pid' => $p_row['id'],
'mch_id' => $wx_mchid,
'admin_id' => $this->uid,
'brand_id' => $row['brand_id'],
's_id' => $row['s_id'],
'v_id' => $row['v_id'],
'cor_id' => $row['cor_id'],
'incor_id' => $row['incor_id'],
'total_price' => $money,
'pay_price' => $money,
'type' => $type,
'status' => 1,
'pay_time' => date('Y-m-d H:i:s',strtotime($pay_time)),
'c_time' => time()
];
$p_row['uid'] && $data['uid'] = $p_row['uid'];
$p_row['entrust_uid'] && $data['entrust_uid'] = $p_row['entrust_uid'];
$img && $data['img'] = $img;
$descrip && $data['descrip'] = $descrip;
$this->app_liche_orders_model->add($data);
if($this->app_liche_orders_model->count(['status'=>1,'o_id'=>$row['id']])==1 && $money>=100){ //企业微信推送
$this->orders_status_entity->set_status($row['id'],0,1);
if(date('Y-m-d',strtotime($pay_time))==date('Y-m-d')){ //当天
$this->qyrobot->deposit_notify_v2($row['id']);
}else{
$this->qyrobot->deposit_notify_v2($row['id'],1,$data['pay_time']);
}
}
$where = [
'status'=>1,
'o_id'=>$row['id'],
'pid>'=>0
];
$last_p_row && $where['id <>'] = $last_p_row['id'];
$is_pay = $this->app_liche_orders_model->sum('total_price',$where); //已支付金额
if($need_price && $is_pay['total_price']>=$need_price){ //完成支付
$this->app_liche_orders_model->update(['status'=>1],['o_id'=>$row['id'],'pid'=>0]);//主订单设置成支付
$last_p_row && $this->app_liche_orders_model->update(['status'=>1],['id'=>$last_p_row['id']]);//完成未支付尾款
$this->orders_status_entity->set_status($row['id'],0,2);
}
if(!$this->order_contracts_model->count(['o_id'=>$row['id']])){ //生成合同
$url = http_host_com('api').'/pdfapi/add_pdf?oid='.$row['id'];
$pdf_res = file_get_contents($url);
}
if($row['order_time'] == '0000-00-00 00:00:00'){ //更新下定时间
$this->receiver_orders_v2_model->update(['order_time' => date('Y-m-d H:i:s',strtotime($pay_time))], ['id' => $row['id']]);
}
//更新客户为订单客户
$this->customers_model->update(['status'=>2],['id'=>$row['customer_id']]);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
$companys = $this->sys_company_model->select(['status' => 1, 'wx_mchid!=' => ''], 'id desc', '', '', 'id,wx_mchid,short');
$type = [];
$type[] = ['id'=>6,'name'=>'车款'];
$srv_price >0 && $type[] = ['id'=>2,'name'=>'服务费'];
$this->data['type'] = $type;
$this->data['companys'] = $companys;
$this->data['id'] = $this->input->get('id');
return $this->show_view('receiver/orderv2/get/add_paylog');
}
//取消配车
public function edit_ckcar(){
$this->load->model('items/items_model');
$id = $this->input->post('id');
$row = $this->receiver_orders_v2_model->get(['id'=>$id]);
if(!$row || !$row['item_id']){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
if ($this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1])) {
return $this->show_json(SYS_CODE_FAIL, '订单已开票,不能修改!');
}
$res = $this->receiver_orders_v2_model->update(['item_id'=>0],['id'=>$row['id']]);
if($res){
$this->items_model->update(['status' => 1,'bill_time'=>'0000-00-00 00:00:00'], ['id' => $row['item_id']]);
$this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>2,'status'=>1]);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
//修改图片
public function edit_imgs(){
$id = $this->input->post('id');
$field = $this->input->post('filed');
$value = $this->input->post('value');
$row = $this->receiver_orders_v2_model->get(['id'=>$id]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$re_data = $this->receiver_order_datas_model->get(['o_id'=>$id]);
if(!$re_data){
$re_data_id = $this->receiver_order_datas_model->add(['c_time'=>time(),'o_id'=>$id]);
}else{
$re_data_id = $re_data['id'];
}
if($field=='ins_img' || $field=='other_img'){
$val_arr = json_decode($row[$field],true);
$val_arr[] = $value;
$value = json_encode($val_arr,JSON_UNESCAPED_UNICODE);
}
$update = [
$field => $value
];
//识别行驶证
if($field=='car_img'){
$result = $this->tcorc->VehicleLicense(build_qiniu_image_url($value));
if (!$result['code']) {
return $this->show_json(SYS_CODE_FAIL, '图片识别失败,请重新上传');
}
$jsondata = json_decode($re_data['jsondata'],true);
$jsondata['car_info'] = $result['data']['FrontInfo'];
$update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
}
$res = $this->receiver_order_datas_model->update($update,['id'=>$re_data_id]);
if($res){
// $this->orders_status_entity->set_status($id,6,1);
if($field=='ins_img'){//保单识别图片保存数据
$this->order_datas_entity->orc_ins_img($id);
}
if($field=='car_img'){//更新车牌号
$this->order_datas_entity->up_car_num($id);
}
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
public function edit_ckimg(){
$type = $this->input->post('type');
$ifcheck = $this->input->post('ifcheck');
$o_id = $this->input->post('id');
$img_data = $this->receiver_order_datas_model->get(['o_id'=>$o_id]);
if(!$img_data){
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$ck_row = $this->app_checkdata_model->get(['cf_id'=>$img_data['id'],'app_id'=>2,'type'=>$type]);
if($ck_row){
$update = [
'ifcheck' => $ifcheck ? 1 : -1,
];
$res = $this->app_checkdata_model->update($update,['id'=>$ck_row['id']]);
}else{
$add_data = [
'cf_id' => $img_data['id'],
'app_id' => 2,
'type' => $type,
'datatype' => 'img',
'ifcheck' => $ifcheck ? 1 : -1,
'c_time' => time()
];
$res = $this->app_checkdata_model->add($add_data);
}
if($res){
$count = $this->app_checkdata_model->count(['ifcheck'=>1,'cf_id'=>$img_data['id'],'datatype'=>'img']);
// if($count==5){
// $this->orders_status_entity->set_status($img_data['o_id'],6,2);
// }
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
//修改资料信息
public function edit_agent(){
$params = $this->input->post();
$row = $this->receiver_orders_v2_model->get(['id' => $params['oid']]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$agent = $this->order_agents_model->get(['o_id' => $row['id']]);
$jsondata = json_decode($agent['jsondata'],true);
$update = [];
$update['car_num'] = $params['car_num'];
$update['ins_time'] = $params['ins_time'] ? date('Y-m-d H:i:s', strtotime($params['ins_time'])) : '0000-00-00 00:00:00';
$jsondata['company'] = $params['company'];
$jsondata['ins_risk'] = $params['ins_risk'];
$jsondata['business_risk'] = $params['business_risk'];
$update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
if ($agent) {
$result = $this->order_agents_model->update($update, ['id' => $agent['id']]);
} else {
$update['o_id'] = $row['id'];
$update['c_time'] = time();
$result = $this->order_agents_model->add($update);
}
if ($result) {
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
//修改支付订单状态
public function edit_status(){
if($this->input->method()=='post'){
$id = $this->input->post('id');
$row = $this->receiver_orders_v2_model->get(['id'=>$id]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '订单不存在');
}
$res = $this->receiver_orders_v2_model->update(['status'=>2,'refund_time'=>date('Y-m-d H:i:s')],['id'=>$id]);
if($res){
$this->app_liche_orders_model->update(['stat4us'=>-1],['o_id'=>$row['id']]);
return $this->show_json(SYS_CODE_SUCCESS, '修改成功');
}else{
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
return $this->show_view('receiver/orderv2/edit_status');
}
//下载pdf
public function get_down(){
require_once COMMPATH.'/third_party/TCPDF/tcpdf.php';
$id = $this->input->get('id');
$row = $this->receiver_orders_v2_model->get(['id'=>$id],'id,sid,owner_mobile,owner_name');
$contract = $this->order_contracts_model->get(['o_id'=>$row['id'],'type'=>0],'id,o_id,file,imgs,type');
if(!$row || !$contract){
return false;
}
$type_arr = [0=>'汽车购车协议',1=>'委托服务协议',2=>'车辆确定',3=>'车辆交付'];
$old_type_arr = [0=>'整车合同',1=>'委托服务协议',2=>'车辆确定',3=>'交车信息',4=>'车辆买卖合同补充协议',5=>'委托服务补充协议'];
$path = FCPATH."pdf/{$row['owner_name']}";
$row['owner_mobile'] && $path .= "({$row['owner_mobile']})";
if($contract['o_id']>=10000){
$file_name = $type_arr[$contract['type']] ? $type_arr[$contract['type']].'.pdf' : '其它_'.time().'.pdf';
}else{
$file_name = $old_type_arr[$contract['type']] ? $old_type_arr[$contract['type']].'.pdf' : '其它_'.time().'.pdf';
}
$file=$path.'/'.$file_name;
if(!file_exists($file)){
$imgs = json_decode($contract['imgs'],true);
if(!$imgs){
file_get_contents("https://api.liche.cn/wxapp/licheb/protocol/pdf_img?id={$contract['id']}");
$contract = $this->order_contracts_model->get(['o_id'=>$row['o_id'],'type'=>0],'id,o_id,file,imgs,type');
$imgs = json_decode($contract['imgs'],true);
}
if (!file_exists($path)) {
$oldumask = umask(0);
mkdir($path, 0777, true);
umask($oldumask);
}
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
//删除预定义的打印 页眉/页尾
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
//设置默认等宽字体
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('stsongstdlight', '', 20);
$pdf->AddPage();
$options = array(
// 解决SSL证书验证失败的问题
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
)
);
//设置文件信息
foreach ($imgs as $item) {
$img_url = build_qiniu_image_url($item);
$res = file_get_contents($img_url,false, stream_context_create($options));
$pdf->Ln();
$pdf->Image('@'.$res, '', '', '', '', '', $img_url,'' , false, 300, '', false, false, 0.05, false, false, false);
}
$pdf->Output( $file,'F');
}
ob_end_clean();
//检查文件是否存在于目录
if (!file_exists ($file)) {
header('HTTP/1.1 404 NOT FOUND');
} else {
ob_end_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
//请求范围的度量单位
Header ( "Accept-Ranges: bytes" );
//下载后的文件名称为$file_name
header('Content-Disposition: attachment; filename='.$file_name);
header('Content-Transfer-Encoding: binary');
#Expires:设置页面缓存时间
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: no cache');
//Content-Length是指定包含于请求或响应中数据的字节长度
header('Content-Length: ' . filesize($file));
ob_clean(); flush();
readfile($file);
ob_end_clean();
}
}
public function edit_price(){
$id = $this->input->get_post('id');
$row = $this->receiver_orders_v2_model->get(['id' => $id]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '订单不存在!');
}
$money_json = json_decode($row['money_json'],true);
if($this->input->method()=='post'){
$price_discount = $this->input->post('price_discount');
$money_json['price_discount'] = floatval($price_discount);
$updata = [
'money_json' => json_encode($money_json,JSON_UNESCAPED_UNICODE)
];
$res = $this->receiver_orders_v2_model->update($updata,['id'=>$id]);
if($res){
//更新尾款订单
if(!$this->app_liche_orders_model->count(['type'=>3,'status'=>1,'o_id'=>$id])){ //不存在支付尾款更新尾款
$this->app_liche_orders_model->update(['status'=>-1],['type'=>3,'o_id'=>$id,'status'=>0]);
//生成购车订单
$userinfo = $this->app_liche_users_model->get(['mobile'=>$row['mobile']]);
$this->orders_v2_entity->add_order($id,$userinfo['id']);
}
//重新生成合同
$this->order_contracts_model->delete(['o_id'=>$id]);
$this->orders_v2_entity->create_pdf($id);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功!');
}else{
return $this->show_json(SYS_CODE_FAIL, '保存失败!');
}
}
$this->data['price_discount'] = $money_json['price_discount'];
$this->data['id'] = $id;
return $this->show_view('receiver/orderv2/edit_price');
}
public function edit_srv(){
$this->load->model('receiver/receiver_services_model','services_model');
$id = $this->input->get_post('id');
$row = $this->receiver_orders_v2_model->get(['id' => $id]);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '订单不存在!');
}
$money_json = json_decode($row['money_json'],true);
$services = json_decode($row['srv_ids'],true);
if($this->input->method()=='post'){
$info = $this->input->post();
if(is_array($info['money'])){
foreach ($info['money'] as $key => $val) {
if($val['checkbox']){
$money_json[$key] = floatval($val['value']);
}else{
$money_json[$key] = 0;
foreach ($services as $k => $v) {
if($key==$v['key']){
unset($services[$k]);
break;
}
}
}
}
}
$updata = [
'srv_ids' => json_encode($services,JSON_UNESCAPED_UNICODE),
'money_json' => json_encode($money_json,JSON_UNESCAPED_UNICODE)
];
$res = $this->receiver_orders_v2_model->update($updata,['id'=>$id]);
if($res){
if(!$this->app_liche_orders_model->count(['type'=>2,'status'=>1,'o_id'=>$id])){ //不存在支付服务费
$this->app_liche_orders_model->update(['status'=>-1],['type'=>2,'o_id'=>$id,'status'=>0]);
//生成购车订单
$userinfo = $this->app_liche_users_model->get(['mobile'=>$row['mobile']]);
$this->orders_v2_entity->add_order($id,$userinfo['id']);
}
//重新生成合同
$this->order_contracts_model->delete(['o_id'=>$id]);
$this->orders_v2_entity->create_pdf($id);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功!');
}else{
return $this->show_json(SYS_CODE_FAIL, '保存失败!');
}
}
//获取车辆服务费
$lists = [];
if($services){
$srv_ids = array_column($services,'id');
$ids = implode(',',$srv_ids);
if($srv_ids){
$where["id in ($ids)"] = null;
$rows = $this->services_model->map('id','title',$where,'','','','id,title');
foreach($services as $key=>$val){
$lists[] = [
'title' => $rows[$val['id']],
'key' => $val['key'],
'money' => $money_json[$val['key']]
];
}
}
}
$this->data['srv_info'] = $lists;
$this->data['id'] = $id;
return $this->show_view('receiver/orderv2/edit_srv');
}
}