diff --git a/admin/controllers/receiver/Orders.php b/admin/controllers/receiver/Orders.php
new file mode 100644
index 00000000..3bc9d72c
--- /dev/null
+++ b/admin/controllers/receiver/Orders.php
@@ -0,0 +1,2202 @@
+load->model('receiver/order/receiver_orders_model');
+ $this->load->model('receiver/order/receiver_order_datas_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_cars_model');
+ $this->load->model("sys/sys_area_model");
+
+// $this->load->library('receiver/orders_entity');
+// $this->load->library('receiver/orders_v2_entity');
+// $this->load->library('receiver/orders_status_entity');
+ $this->load->library('OrdersList');
+ }
+
+ public function index()
+ {
+ $this->lists();
+ }
+
+ public function lists()
+ {
+ $params = $this->input->get();
+ $statusAry = $this->receiver_orders_model->get_status();
+ $status_arr = array();
+ foreach ($statusAry as $key => $value) {
+ $count = $this->receiver_orders_model->count(['status' => $key]);
+ $status_arr[] = array("id" => $key, "name" => $value, "cate" => [], "count" => $count);
+ }
+ $params['count_all'] = $this->receiver_orders_model->count();//全部
+ $params['list_type'] = 'all';
+ $result = $this->orderslist->lists($params['status_pid'], $params);
+ $this->data = $result;
+ $this->data['status_arr'] = $status_arr;
+ $this->data['_title'] = '订单列表';
+ return $this->show_view('receiver/order/lists', true);
+ }
+
+ public function lists_aggs()
+ {
+ # http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2021-12-01&today_end=2022-06-06&total_start=2021-12-01&title_today=start 2021-12-01&title_ding_today=当日订单&title_piao_today=当日开票
+ # http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2022-01-01&today_end=2022-07-01&total_start=2022-01-01&total_end=2023-01-01&title_today=start 2022-01~06&title_ding_today=上半年订单&title_ding=全年订单&title_piao_today=上半年开票&title_piao=全年开票
+ # http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2022-12-01&today_end=2023-01-01&total_start=2022-10-01&total_end=2023-01-01&title_today=start 2022-12&title_ding_today=12月订单&title_ding=季度订单&title_piao_today=12月开票&title_piao=季度开票
+ $today_start = date('Y-m-d 00:00:00');
+ $today_end = date('Y-m-d 00:00:00', strtotime('+1 day'));
+ $total_start = date('Y-m-01 00:00:00');
+ $total_end = date('Y-m-01 00:00:00', strtotime('+1 month'));
+ //$title_today = date('m月d日');
+ $title_today = '来源';
+ $title_ding_today = '当日订单';
+ $title_ding = '月累计订单';
+ $title_piao_today = '当日开票';
+ $title_piao = '月累计开票';
+
+ $params = $this->input->get();
+ $params['today_start'] && $today_start = $params['today_start'];
+ $params['today_end'] && $today_end = $params['today_end'];
+ $params['total_start'] && $total_start = $params['total_start'];
+ $params['total_end'] && $total_end = $params['total_end'];
+ $params['title_today'] && $title_today = $params['title_today'];
+ $params['title_ding_today'] && $title_ding_today = $params['title_ding_today'];
+ $params['title_ding'] && $title_ding = $params['title_ding'];
+ $params['title_piao_today'] && $title_piao_today = $params['title_piao_today'];
+ $params['title_piao'] && $title_piao = $params['title_piao'];
+
+ $data = $this->orders_v2_entity->aggs_biz_ding_piao_rpt($today_start, $today_end, $total_start, $total_end,
+ $title_today, $title_ding_today, $title_ding, $title_piao_today, $title_piao, $create_table_image = true);
+ $biz_aggs = $data['biz_aggs'];
+ $indexs = $data['indexs'];
+ $img_path = $data['img_path'] ? $data['img_path'] : '';
+ $img_path_ding = $data['img_path_ding'] ? $data['img_path_ding'] : '';
+ $img_path_piao = $data['img_path_piao'] ? $data['img_path_piao'] : '';
+
+ if ($export = $params['export']) {
+ if (!$biz_aggs) {
+ echo 'no data';
+ exit();
+ }
+ array_unshift($biz_aggs, $indexs);
+ $this->load->library('excel');
+ #$filename = "lists_aggs_" . date('YmdHis');
+ $filename = "lists_aggs";
+ if ($export == 'csv') {
+ return $this->excel->out_csv($biz_aggs, $indexs, $filename);
+ }
+ if ($export == 'image' || $export == 'img') {
+ if ($img_path) {
+ #$http = $_SERVER['HTTPS'] ? 'https://' : 'http://';
+ #$img_path = $http.$_SERVER['HTTP_HOST'].'/'.$img_path;
+ echo '
';
+ if ($img_path_ding) echo '
';
+ if ($img_path_piao) echo '
';
+ exit();
+ }
+ return $this->excel->out_csv($biz_aggs, $indexs, $filename);
+ }
+
+ if ($export == 'excel2') {
+ #var_dump($indexs);echo('
');var_dump($biz_aggs[0]);echo('
');var_dump($biz_aggs[1]);exit();
+
+ #生成品牌对应的系列数,用于表头合并列
+ $series_names = $data['series_names'];
+ $indexs_keys = array_keys($indexs);
+ $brand_series_nums = array();
+ foreach ($series_names as $k => $v) {
+ $nums = 0;
+ if (in_array($k . '_ding', $indexs_keys)) {
+ $nums++;
+ }
+ foreach ($v as $k2 => $v2) {
+ if (in_array($k . '_' . $v2 . '_ding', $indexs_keys)) {
+ $nums++;
+ }
+ }
+ $nums && $brand_series_nums[$k . '_ding'] = $nums;
+
+ $nums = 0;
+ if (in_array($k . '_piao', $indexs_keys)) {
+ $nums++;
+ }
+ foreach ($v as $k2 => $v2) {
+ if (in_array($k . '_' . $v2 . '_piao', $indexs_keys)) {
+ $nums++;
+ }
+ }
+ $nums && $brand_series_nums[$k . '_piao'] = $nums;
+ }
+ #var_dump($brand_series_nums);exit();
+
+ #require_once COMMPATH . 'third_party/PHPExcel.php';
+ set_time_limit(0); // 设置页面等待时间
+ ini_set('memory_limit', -1); // 不限制内存
+ $objPHPExcel = new PHPExcel();
+ #$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); // 单元格整体居右
+ $objPHPExcel->setActiveSheetIndex(0); // 选中默认的第一个sheet
+ $objPHPExcel->getActiveSheet()->setTitle('小狸播报'); // 给 Sheet 设置名字
+
+ # 先生成表头
+ $i = 0;
+ foreach ($indexs as $k => $v) {
+ $columnkey = PHPExcel_Cell::stringFromColumnIndex($i);
+ if ((strpos($k, '_ding') !== false || strpos($k, '_piao') !== false) && !in_array($k, array('doc_ding_today', 'doc_ding', 'doc_piao_today', 'doc_piao'))) {
+ if ($brand_series_nums[$k]) {
+ # 第一行需合并多列的列
+ $columnkey2 = PHPExcel_Cell::stringFromColumnIndex($i + $brand_series_nums[$k] - 1);
+ $pRange = $columnkey . '1:' . $columnkey2 . '1';
+ $pCoordinate = $columnkey . '1';
+ $objPHPExcel->getActiveSheet()->mergeCells($pRange);
+ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $v);
+
+ # PHPExcel常用属性使用 http://t.zoukankan.com/lglblogadd-p-7117486.html
+ # 水平居中
+ $objStyle = $objPHPExcel->getActiveSheet()->getStyle($pCoordinate); //获取要设置单元格的样式,括号里的内容也可是:('A1:E1')
+ $objAlign = $objStyle->getAlignment(); //用来设置对齐属性和单元格内文本换行的一个变量
+ $objAlign->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ }
+
+ # 第二行的列
+ $pCoordinate = $columnkey . '2';
+ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $v);
+ } else {
+ # 第一二行需合并的列
+ $pRange = $columnkey . '1:' . $columnkey . '2';
+ $pCoordinate = $columnkey . '1';
+ $objPHPExcel->getActiveSheet()->mergeCells($pRange);
+ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $v);
+
+ # 垂直居中
+ $objStyle = $objPHPExcel->getActiveSheet()->getStyle($pCoordinate);
+ $objAlign = $objStyle->getAlignment();
+ $objAlign->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ }
+ $i++;
+ }
+
+ # 再生成数据
+ $biz_aggs = array_slice($biz_aggs, 1);
+ $j = 3;
+ foreach ($biz_aggs as $val) {
+ $i = 0;
+ // 内循环产生每一行
+ foreach ($indexs as $k => $v) {
+ // 数字列转换为字母列 如:27变为AA
+ $objPHPExcel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($i) . $j, $val[$k]);
+ $i++;
+ }
+ $j++;
+ }
+
+ $filename = iconv('UTF-8', 'UTF-8', $filename) . '.xls';
+ header('Pragma: public');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header('Content-Type: application/force-download');
+ header('Content-Type: application/vnd.ms-execl');
+ header('Content-Type: application/octet-stream');
+ header('Content-Type: application/download');
+ header("Content-Disposition: attachment; filename=$filename");
+ header('Content-Transfer-Encoding: binary');
+ $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+ return $objWriter->save('php://output');
+ }
+
+ if (count($indexs) <= 26) {
+ return $this->excel->out($biz_aggs, $indexs, $filename);
+ }
+
+ $sheet['小狸播报'] = array();
+ foreach ($biz_aggs as $k => $v) {
+ $list[1] = array();
+ foreach ($indexs as $k2 => $v2) {
+ $list[1][] = $v[$k2];
+ }
+ $sheet['小狸播报'][] = $list[1];
+ }
+ return $this->excel->exportExcel($sheet, $filename);
+ }
+
+ #var_dump($indexs);var_dump($biz_aggs[0]);
+ $this->data['_title'] = '小狸播报';
+ $this->data['fieldAry'] = $indexs;
+ $this->data['lists'] = $biz_aggs;
+ $this->data['img_path'] = $img_path;
+ $this->data['img_path_ding'] = $img_path_ding;
+ $this->data['img_path_piao'] = $img_path_piao;
+ return $this->show_view('receiver/orderv2/lists_aggs', 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['if_usedcar_name'] = $row['if_usedcar'] ? ' (二手车)' : '';
+ $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);
+ $fine_title = '';
+ if ($row['fines']) {
+ $fines = json_decode($row['fines'], true);
+ $split = $fine_title = '';
+ foreach ($fines as $key => $val) {
+ $price = $val['price'] > 0 ? number_format(floatval($val['price']), 2) : '赠送';
+ $fine_title .= $split . "{$val['txt']}:{$price}";
+ $split = ' ';
+ }
+ }
+ $row['fine_title'] = $fine_title;
+ $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 ? ',' : '';
+ if ($val['key'] == 'price_fine_select' && $fine_title) {
+ #$srv_detail .= $d . $val['title'] . ":" . number_format(floatval($val['money']), 2)."[$fine_title]";
+ if ($val['money'] > 0) {
+ $srv_detail .= $d . $val['title'] . ":" . number_format(floatval($val['money']), 2) . "[$fine_title]";
+ } else {
+ $srv_detail .= $d . $val['title'] . "[$fine_title]";
+ }
+ } else {
+ $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']]);
+
+ $notify_file_list = [];
+ $file_list = $loan['notify_file'] ? explode(',', $loan['notify_file']) : array();
+ if ($file_list) {
+ foreach ($file_list as $item) {
+ $notify_file_list[] = build_qiniu_image_url($item);
+ }
+ }
+ $loan['notify_file_list'] = $notify_file_list;
+ //$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['finance_rows'] = $this->sys_supplier_model->select(['status' => 1, 'type' => 3], '', 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'];
+ $money_json['price_loan0'] && $loan['first_pay'] -= $money_json['price_loan0']; // 首付按揭
+ }
+ !$loan['num'] && $loan['num'] = 36;
+ $loan['is_tiexi'] = intval($loan['is_tiexi']);
+ $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;
+ }
+
+ //获取按揭信息-首付按揭
+ if (!$row['payway'] && $money_json['price_loan0']) {
+ $loan = $this->order_loans0_model->get(['o_id' => $row['id']]);
+
+ $notify_file_list = [];
+ $file_list = $loan['notify_file'] ? explode(',', $loan['notify_file']) : array();
+ if ($file_list) {
+ foreach ($file_list as $item) {
+ $notify_file_list[] = build_qiniu_image_url($item);
+ }
+ }
+ $loan['notify_file_list'] = $notify_file_list;
+ $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_supplier_model->select(['status' => 1, 'type' => 3], '', 0, 0, 'id,title');
+ $loan['price_loan'] = $money_json['price_loan0'] ? $money_json['price_loan0'] : '';
+ $loan['first_pay'] = 0; // 不需要计算改值
+ !$loan['num'] && $loan['num'] = 36;
+ $loan['is_tiexi'] = intval($loan['is_tiexi']);
+ $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');
+ $status_array = array();
+ $row['finance_id0'] && $loan['notify_file'] && $status_array[] = 1;
+ if ($this->app_liche_orders_model->get(['o_id' => $row['id'], 'type' => 8, 'status' => 1])) {
+ $status_array[] = 2;
+ }
+ $loan['status_array'] = $status_array;
+ $row['loan_info0'] = $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_ck_img = json_decode($img_data['bill_ck_img'], true);
+ if ($bill_ck_img) {
+ foreach ($bill_ck_img as $key => $value) {
+ $bill_ck_img[$key] = build_qiniu_image_url($value);
+ }
+ }
+ $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['bill_ck_img'] = $bill_ck_img;
+
+ $bill['status'] = $bill_status ? 1 : 0;
+ $companys = $this->sys_company_model->select(['status' => 1, 'wx_mchid!=' => ''], 'id desc', '', '', 'id,short');
+ $row['companys'] = $companys;
+ $row_goods['company_id'] && $item_company = $this->sys_company_model->get(['id' => $row_goods['company_id']], 'id,short');
+ if (!$item_company) {
+ $item_html = '车辆归属未选择';
+ } else {
+ $item_html = "车辆公司归属【{$item_company['short']}】";
+ }
+ $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_order) {
+ $ck_html = $pay_compay['id'] == $item_company['id'] ? '一致' : '不一致';
+ $pay_html = "与尾款收款公司【{$pay_compay['short']}】 {$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;
+ $insurance_img = json_decode($img_data['insurance_img'], true);
+ $business_img = json_decode($img_data['business_img'], true);
+ $accident_img = json_decode($img_data['accident_img'], true);
+ $agent['insurance_price'] = $insurance_img['price'] ? $insurance_img['price'] : '';
+ $agent['insurance_product'] = $insurance_img['product'] ? $insurance_img['product'] : '';
+ $agent['business_price'] = $business_img['price'] ? $business_img['price'] : '';
+ $agent['business_product'] = $business_img['product'] ? $business_img['product'] : '';
+ $agent['car_num'] = $agent['car_num'] ? $agent['car_num'] : '';
+ $agent['accident_price'] = $accident_img['price'] ? $accident_img['price'] : '';
+ $agent['accident_title'] = $accident_img['product'] ? $accident_img['product'] : '';
+ if (!$agent['ins_time'] && $business_img) {
+ $img_jsondata = json_decode($img_data['jsondata'], true);
+ $business_img_key = md5(build_qiniu_image_url($business_img['img']));
+ $business_img_orc = $img_jsondata['ins_info'][$business_img_key];
+ if ($business_img_orc['data']['投保日期']) {
+ $agent['business_time'] = $business_img_orc['data']['投保日期'];
+ } else {
+ $agent['business_time'] = $business_img_orc['data']['coverYears'];
+ }
+
+ }
+ $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");
+ $this->load->model("sys/sys_city_model", 'mdSysCity');
+ $row_admin = $this->licheb_users_model->get(array('id' => $row['sale_id']));
+ # 2023-03-20:如果 角色是 渠道经理 就显示 XX渠道 某某某, XX 取所在城市
+ if ($row_admin['group_id'] == 4) {
+ $row_city = $this->mdSysCity->get(['city_id' => $row_admin['city_id']]);
+ $city_name = $row_city['name'] ? str_replace('市', '', $row_city['name']) . '渠道 ' : '';
+ $admin_name = $row_admin ? "{$city_name}{$row_admin['uname']}" : "";
+ } else {
+ $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;
+ }
+ //订单状态
+ if ($id > Orders_v2_entity::V2_START_ID) {
+ $status_name = $this->orders_status_entity->last_status_cn($id);
+ !$status_name && $status_name = '未下定';
+ }
+ $row['status_name'] = $status_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;
+ $row['is_admin'] = ($this->role == SUPER_ADMIN || $this->role == 40) ? 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 = [];
+ $params['status_pid'] == 5 && $params['status'] = 1;
+ $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_loanfile()
+ {
+ $params = $this->input->post();
+ $oid = $params['id'];
+ $file = $params['value'];
+
+ $row_order = $this->receiver_orders_v2_model->get(array('id' => $oid));
+ if (!$file || !$row_order) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+
+ $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]);
+ }
+ $notify_file_list = $row['notify_file'] ? explode(',', $row['notify_file']) : [];
+ $update = [];
+ if ($file) { //上传按揭通知函
+ if ($params['type']) {
+ $update['lend_file'] = $file;
+ # 此处不检查load_time为空的情况,最后做“按揭完成”时也会检查
+ $loan_time = $params['loan_time'];
+ if ($loan_time) {
+ $update['loan_time'] = date('Y-m-d H:i:s', strtotime($loan_time));
+ }
+ } else {
+ $notify_file_list[] = $file;
+ $update['notify_file'] = implode(',', $notify_file_list);
+ }
+ $this->data['file_url'] = build_qiniu_image_url($file);
+ }
+ if ($update) {
+ $result = $this->order_loans_model->update($update, ['id' => $row['id']]);
+ }
+ $this->order_status_check_after_edit_loan($row_order);
+ return $result ? $this->show_json(SYS_CODE_SUCCESS, '保存成功') : $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+
+ //修改按揭图片-首付按揭
+ public function edit_loanfile0()
+ {
+ $params = $this->input->post();
+ $oid = $params['id'];
+ $file = $params['value'];
+
+ $row_order = $this->receiver_orders_v2_model->get(array('id' => $oid));
+ if (!$file || !$row_order) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+
+ $row = $this->order_loans0_model->get(['o_id' => $oid]);
+ if (!$row) {
+ $this->order_loans0_model->add(['o_id' => $oid, 'c_time' => time()]);
+ $row = $this->order_loans0_model->get(['o_id' => $oid]);
+ }
+ $notify_file_list = $row['notify_file'] ? explode(',', $row['notify_file']) : [];
+ $update = [];
+ if ($file) { //上传按揭通知函
+ if ($params['type']) {
+ $update['lend_file'] = $file;
+ # 此处不检查load_time为空的情况,最后做“按揭完成”时也会检查
+ $loan_time = $params['loan_time'];
+ if ($loan_time) {
+ $update['loan_time'] = date('Y-m-d H:i:s', strtotime($loan_time));
+ }
+ } else {
+ $notify_file_list[] = $file;
+ $update['notify_file'] = implode(',', $notify_file_list);
+ }
+ $this->data['file_url'] = build_qiniu_image_url($file);
+ }
+ if ($update) {
+ $result = $this->order_loans0_model->update($update, ['id' => $row['id']]);
+ }
+ $this->order_status_check_after_edit_loan($row_order);
+ return $result ? $this->show_json(SYS_CODE_SUCCESS, '保存成功') : $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+
+ //修改按揭
+ 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]);
+ }
+ $notify_file_list = $row['notify_file'] ? explode(',', $row['notify_file']) : [];
+ $update = [];
+ $update['company_id'] = $info['loan_info']['company_id'];
+ $update['num'] = $info['loan_info']['num'];
+ $price_loan = $info['loan_info']['price_loan'];
+ 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 {
+ $notify_file_list[] = $res['file'];
+ $update['notify_file'] = implode(',', $notify_file_list);
+ }
+ $this->data['file_url'] = build_qiniu_image_url($res['file']);
+ }
+ strlen($params['status']) && $update['status'] = $params['status'];
+ $finance_id = $info['finance_id'];
+ if (!$finance_id || !$price_loan) {
+ return $this->show_json(SYS_CODE_FAIL, '请填写完整信息!');
+ }
+ if ($params['status'] == 1) { //等待放款
+ if (!$row['notify_file']) {
+ 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));
+
+ $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);
+ // 不考虑-首付按揭要先完成才能 set_status($oid,1,2)
+ /* if ($money_json['price_loan0']){
+ if(!$this->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>8,'status'=>1])){
+ return $this->show_json(SYS_CODE_FAIL, '请先完成首付按揭!');
+ }
+ }*/
+ // 防止此页面有修改,同时更新price_loan与finance_id
+ $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']]);
+ $result = $this->orders_status_entity->set_status($oid, 1, 2);
+ //添加按揭收款记录
+ if (!$this->app_liche_orders_model->get(['o_id' => $row['o_id'], 'type' => 7])) {
+ $p_row = $this->app_liche_orders_model->get(['o_id' => $row['o_id'], 'pid' => 0, 'status>=' => 0]);
+ $order_row = $this->receiver_orders_v2_model->get(['id' => $row['o_id']]);
+ $this->load->helper('order');
+ $sid = create_order_no(350200, 'liche');
+ $pay_log = [
+ 'o_id' => $order_row['id'],
+ 'sid' => $sid,
+ 'pid' => $p_row['id'],
+ 'admin_id' => $this->uid,
+ 'brand_id' => $order_row['brand_id'],
+ 'company_id' => $info['loan_info']['company_id'],
+ 's_id' => $order_row['s_id'],
+ 'v_id' => $order_row['v_id'],
+ 'cor_id' => $order_row['cor_id'],
+ 'incor_id' => $order_row['incor_id'],
+ 'total_price' => $price_loan,
+ 'pay_price' => $price_loan,
+ 'type' => 7,
+ 'status' => 1,
+ 'pay_time' => date('Y-m-d H:i:s'),
+ 'c_time' => time()
+ ];
+ $p_row['uid'] && $pay_log['uid'] = $p_row['uid'];
+ $p_row['entrust_uid'] && $pay_log['entrust_uid'] = $p_row['entrust_uid'];
+ $this->app_liche_orders_model->add($pay_log);
+ }
+ }
+ 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_loan0()
+ {
+ $params = $this->input->post();
+ $info = $params['info'];
+ $oid = $params['id'] ? $params['id'] : $info['id'];
+ $file = $_FILES['file'];
+ $row = $this->order_loans0_model->get(['o_id' => $oid]);
+ if (!$row) {
+ $this->order_loans0_model->add(['o_id' => $oid, 'c_time' => time()]);
+ $row = $this->order_loans0_model->get(['o_id' => $oid]);
+ }
+ $notify_file_list = $row['notify_file'] ? explode(',', $row['notify_file']) : [];
+ $update = [];
+ $update['company_id'] = $info['loan_info0']['company_id'];
+ $update['num'] = $info['loan_info0']['num'];
+ $price_loan = $info['loan_info0']['price_loan'];
+ 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 {
+ $notify_file_list[] = $res['file'];
+ $update['notify_file'] = implode(',', $notify_file_list);
+ }
+ $this->data['file_url'] = build_qiniu_image_url($res['file']);
+ }
+ strlen($params['status']) && $update['status'] = $params['status'];
+ $finance_id = $info['finance_id0'];
+ if (!$finance_id || !$price_loan) {
+ return $this->show_json(SYS_CODE_FAIL, '请填写完整信息!');
+ }
+ if ($params['status'] == 1) { //等待放款
+ if (!$row['notify_file']) {
+ 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_loan0'] = $price_loan;
+ $this->receiver_orders_v2_model->update(['finance_id0' => $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); // 首付按揭不改订单状态
+ $result = true;
+ } elseif ($params['status'] == 2) { //完成按揭
+ $loan_time = $info['loan_info0']['loan_time'];
+ if (!$loan_time) {
+ return $this->show_json(SYS_CODE_FAIL, '请选择放款时间!');
+ }
+ if (!$row['notify_file']) {
+ 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));
+ $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_loan0'] = $price_loan;
+ $this->receiver_orders_v2_model->update(['finance_id0' => $finance_id, 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE)], ['id' => $row['o_id']]);
+ //$result = $this->orders_status_entity->set_status($oid,1,2); // 首付按揭不改订单状态
+ //添加按揭收款记录
+ if (!$this->app_liche_orders_model->get(['o_id' => $row['o_id'], 'type' => 8])) {
+ $p_row = $this->app_liche_orders_model->get(['o_id' => $row['o_id'], 'pid' => 0, 'status>=' => 0]);
+ $order_row = $this->receiver_orders_v2_model->get(['id' => $row['o_id']]);
+ $this->load->helper('order');
+ $sid = create_order_no(350200, 'liche');
+ $pay_log = [
+ 'o_id' => $order_row['id'],
+ 'sid' => $sid,
+ 'pid' => $p_row['id'],
+ 'admin_id' => $this->uid,
+ 'brand_id' => $order_row['brand_id'],
+ 'company_id' => $info['loan_info0']['company_id'],
+ 's_id' => $order_row['s_id'],
+ 'v_id' => $order_row['v_id'],
+ 'cor_id' => $order_row['cor_id'],
+ 'incor_id' => $order_row['incor_id'],
+ 'total_price' => $price_loan,
+ 'pay_price' => $price_loan,
+ 'type' => 8,
+ 'status' => 1,
+ 'pay_time' => date('Y-m-d H:i:s'),
+ 'c_time' => time()
+ ];
+ $p_row['uid'] && $pay_log['uid'] = $p_row['uid'];
+ $p_row['entrust_uid'] && $pay_log['entrust_uid'] = $p_row['entrust_uid'];
+ $this->app_liche_orders_model->add($pay_log);
+ }
+ }
+ if ($update) {
+ $result = $this->order_loans0_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']]);
+ }
+ $update = [
+ 'status' => 2,
+ ];
+ if ($row['bill_time'] != '0000-00-00 00:00:00') {
+ $update['bill_time'] = $row['bill_time'];
+ }
+ $buy_price = $this->input->post('buy_price');
+ $buy_price_origin = $this->input->post('buy_price_origin');
+ $estimated_rebate = $this->input->post('estimated_rebate');
+ $estimated_rebate_origin = $this->input->post('estimated_rebate_origin');
+ $buy_price != $buy_price_origin && $update['buy_price'] = $buy_price;
+ $estimated_rebate != $estimated_rebate_origin && $update['estimated_rebate'] = $estimated_rebate;
+ $result = $this->items_model->update($update, ['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');
+ $if_usedcar = $this->input->post('if_usedcar');
+ $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);
+ }
+
+ $bill_time = date('Y-m-d H:i:s'); # 2023-03-02 $if_usedcar或识别图片开票时间失败,强制开票时间为当前时间
+ if (!$if_usedcar) {
+ //图片识别
+ $img_url = build_qiniu_image_url($file);
+ $orc_res = $this->tcorc->CarInvoiceInfos($img_url);
+ if (!$orc_res['code']) {
+ return $this->show_json(2, $orc_res['msg']);
+ }
+ $carinfo = $orc_res['data']['CarInvoiceInfos'];
+ $bill_name = '';
+ if (is_array($carinfo)) {
+ foreach ($carinfo as $kye => $val) {
+ if ($val['Name'] == '发票名称') {
+ $bill_name = $val['Value'];
+ }
+ if ($val['Name'] == '开票日期') {
+ $bill_time = $val['Value'];
+ }
+ }
+ }
+
+ # 发票名称为空, 按增值税发票处理
+ if (!$bill_name) {
+ $orc_res = $this->tcorc->VatInvoice($img_url);
+ if (!$orc_res['code']) {
+ return $this->show_json(3, $orc_res['msg']);
+ }
+ $carinfo = $orc_res['data']['VatInvoiceInfos'];
+ if (is_array($carinfo)) {
+ foreach ($carinfo as $kye => $val) {
+ if ($val['Name'] == '发票名称') {
+ $bill_name = $val['Value'];
+ }
+ if ($val['Name'] == '开票日期') {
+ # 开票日期:2023年04月27日
+ $tmp_value = $val['Value'];
+ $tmp_value = str_replace("年", "-", $tmp_value);
+ $tmp_value = str_replace("月", "-", $tmp_value);
+ $tmp_value = str_replace("日", "", $tmp_value);
+ $bill_time = $tmp_value;
+ }
+ }
+ }
+ # 发票名称为空,可能是保单等图片
+ if (!$bill_name) {
+ return $this->show_json(4, "识别失败");
+ }
+ }
+
+ $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);
+ }
+ $update = ['bill_time' => $bill_time];
+ $if_usedcar && $update['if_usedcar'] = 1;
+ $this->receiver_orders_v2_model->update($update, ['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,
+ 'type!=' => 7
+ ];
+ $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,company_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');
+ }
+ if ($item['company_id']) {
+ $company = $this->sys_company_model->get(['id' => $item['company_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,
+ 'show_img' => 0,
+ 'descrip' => $item['descrip'],
+ 'img' => $item['img'] ? build_qiniu_image_url($item['img']) : '',
+ 'admin_id' => $item['admin_id'],
+ ];
+ }
+ }
+ $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'] ? $sum['total_price'] : 0;
+ $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']]);
+ $money_json = json_decode($row['money_json'], true);
+ if (!$row['payway']) { //贷款
+ $this->data['need_price'] += $money_json['price_loan'];
+ $this->data['price_loan'] = $money_json['price_loan'];
+
+ // 首付按揭
+ if ($money_json['price_loan0']) {
+ $this->data['need_price'] += $money_json['price_loan0'];
+ $this->data['price_loan0'] = $money_json['price_loan0'];
+ }
+ }
+ $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');
+ $log_id = $this->input->get_post('log_id');
+ $row = $this->receiver_orders_v2_model->get(['id' => $id]);
+ $order_row = $this->app_liche_orders_model->get(['id' => $log_id, 'o_id' => $row['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');
+ !$pay_time && $pay_time = date('Y-m-d H:i:s');
+ $wx_mchid = $this->input->post('wx_mchid');
+ $descrip = $this->input->post('descrip');
+ $type = $this->input->post('type');
+ $img = $this->input->post('img');
+ if (!$money || !$row || !$wx_mchid) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+ $company_id = 0;
+ $notify = true; # 0614 防止修改唯一已支付记录时,重发订单通知
+ if ($order_row["id"]) { //修改订单更新旧订单为无效订单
+ $this->app_liche_orders_model->update(['status' => -1], ['id' => $order_row['id']]);
+ if ($order_row['pay_price'] >= 100 || $order_row['descrip'] == 1 && $order_row['descrip'] == '零首付') {
+ $notify = false;
+ }
+ # 修改时此3项保持一致
+ $company_id = $order_row['company_id'];
+ $pay_time = $order_row['pay_time'];
+ $type = $order_row['type'];
+ }
+ $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 {
+ $last_noppay_row = $this->app_liche_orders_model->get(['o_id' => $row['id'], 'type' => 3, 'status' => 0]);//未支付尾款订单
+ $pay_ck = $this->app_liche_orders_model->sum('pay_price', ['o_id' => $row['id'], 'type in (1,6)' => null, 'status' => 1]);//已支付车款
+ if ($last_noppay_row) {
+ $cj_money = $car_price - ($money + $pay_ck['pay_price']);
+ $this->app_liche_orders_model->update(['total_price' => $cj_money], ['id' => $last_noppay_row['id']]);
+ }
+ }
+ } 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');
+ $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'],
+ 'company_id' => $company_id,
+ 'total_price' => $money,
+ 'pay_price' => $money,
+ 'type' => $type,
+ 'status' => 1,
+ 'pay_time' => $pay_time ? date('Y-m-d H:i:s', strtotime($pay_time)) : date('Y-m-d H:i:s'),
+ '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 && $notify) { //企业微信推送
+ $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_v3($row['id']);
+ } else {
+ if (strtotime($data['pay_time']) >= strtotime(date('Y-m-01 00:00:00'))) { //直播报本月补缴订单
+ $this->qyrobot->deposit_notify_v3($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');
+ $this->data['order_row'] = $order_row;
+ 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');
+ $save_value = $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($re_data[$field], true);
+ $val_arr[] = $value;
+ $save_value = json_encode($val_arr, JSON_UNESCAPED_UNICODE);
+ }
+ $update = [
+ $field => $save_value
+ ];
+ if ($field == 'insurance_img' || $field == 'business_img' || $field == 'accident_img') {
+ $jsondata = json_decode($re_data['jsondata'], true);
+ $img_url = build_qiniu_image_url($value);
+// $result = $this->qiniuorc->car_insure($img_url);
+ $result = $this->tcmarket->autoInsurance($img_url);
+ if (!$result['code'] && $field != 'accident_img') { //意外险不强制识别成功
+ return $this->show_json(SYS_CODE_FAIL, '图片识别失败,请重新上传');
+ }
+// $img_jsondata = [
+// 'img' => $value,
+// 'date' => $result['data']['投保确认时间'],
+// 'price' => floatval($result['data']['合计保费']),
+// 'product' => $result['data']['保险公司']
+// ];
+ $img_jsondata = [
+ 'img' => $value,
+ 'date' => $result['data']['policyStartDate'],
+ 'price' => floatval($result['data']['premium']),
+ 'product' => $result['data']['companyName'] ? $result['data']['companyName'] : $result['data']['department']
+ ];
+
+ # 0612各保单支持返点系数, 保留系数
+ if ($re_data) {
+ $insurance_img = json_decode($re_data['insurance_img'], true);
+ $business_img = json_decode($re_data['business_img'], true);
+ $accident_img = json_decode($re_data['accident_img'], true);
+ if ($field == 'insurance_img' && $insurance_img['rebate']) {
+ $img_jsondata['rebate'] = $insurance_img['rebate'];
+ } elseif ($field == 'business_img' && $business_img['rebate']) {
+ $img_jsondata['rebate'] = $business_img['rebate'];
+ } elseif ($field == 'accident_img' && $accident_img['rebate']) {
+ $img_jsondata['rebate'] = $accident_img['rebate'];
+ }
+ }
+
+ $jsondata['ins_info'][md5($img_url)] = $result;
+ $update[$field] = json_encode($img_jsondata, JSON_UNESCAPED_UNICODE);
+ $update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
+ }
+ //识别行驶证
+ 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) {
+ 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']]);
+ $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';
+
+ 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) {
+ $img_data = $this->receiver_order_datas_model->get(['o_id' => $row['id']]);
+ $insurance_img = json_decode($img_data['insurance_img'], true);
+ $business_img = json_decode($img_data['business_img'], true);
+ $accident_img = json_decode($img_data['accident_img'], true);
+ $insurance_img['product'] = $params['insurance_product'];
+ $insurance_img['price'] = $params['insurance_price'];
+ $business_img['product'] = $params['business_product'];
+ $business_img['price'] = $params['business_price'];
+ $accident_img['product'] = $params['accident_title'];
+ $accident_img['price'] = $params['accident_price'];
+
+ # 23-04-03: close accident_title, accident_price
+ /*$img_data_jsondata = json_decode($img_data['jsondata'],true);
+ $img_data_jsondata['accident_title'] = $params['accident_title'];
+ $img_data_jsondata['accident_price'] = $params['accident_price'];*/
+
+ $up_data = [
+ 'insurance_img' => json_encode($insurance_img, JSON_UNESCAPED_UNICODE),
+ 'business_img' => json_encode($business_img, JSON_UNESCAPED_UNICODE),
+ 'accident_img' => json_encode($accident_img, JSON_UNESCAPED_UNICODE),
+ #'jsondata' => json_encode($img_data_jsondata,JSON_UNESCAPED_UNICODE)
+ ];
+ $this->receiver_order_datas_model->update($up_data, ['o_id' => $row['id']]);
+ 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');
+ $sid = $this->input->post('sid');
+ if (!$id && !$sid) {
+ return $this->show_json(SYS_CODE_FAIL, '订单id 与 订单号,必须填写一个');
+ }
+ $row = array();
+ if ($id && $sid) {
+ $row = $this->receiver_orders_v2_model->get(['id' => $id, 'sid' => $sid]);
+ } else {
+ $id && $row = $this->receiver_orders_v2_model->get(['id' => $id]);
+ $sid && $row = $this->receiver_orders_v2_model->get(['sid' => $sid]);
+ }
+ 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' => $row['id']]);
+ if ($res) {
+ $this->app_liche_orders_model->update(['status' => -1], ['o_id' => $row['id'], 'pid' => 0]);
+ return $this->show_json(SYS_CODE_SUCCESS, '修改成功');
+ } else {
+ return $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+ }
+ return $this->show_view('receiver/orderv2/edit_status');
+ }
+
+ //修改支付订单状态-一键完成
+ public function edit_finished()
+ {
+ if ($this->input->method() == 'post') {
+ $id = $this->input->post('id');
+ if (!$id) {
+ return $this->show_json(SYS_CODE_FAIL, '订单id必须填写');
+ }
+
+ $row = $this->receiver_orders_v2_model->get(['id' => $id]);
+ if (!$row) {
+ return $this->show_json(SYS_CODE_FAIL, '订单不存在');
+ }
+ if ($row['status']) {
+ return $this->show_json(SYS_CODE_FAIL, '订单无法操作');
+ }
+
+ $now_time = date('Y-m-d H:i:s');
+ $jsondata = array();
+ $res_order = $this->receiver_orders_v2_model->update(['status' => 1, 'ck_time' => $now_time], ['id' => $id]);
+ !is_bool($res_order) && $res_order && $jsondata['order.status'] = "{$row['status']}->1";
+ $res = $this->receiver_orders_v2_model->update(['order_time' => $now_time], ['id' => $id, 'order_time' => '0000-00-00 00:00:00']);
+ !is_bool($res) && $res && $jsondata['order.order_time'] = "{$row['order_time']}";
+ $res = $this->receiver_orders_v2_model->update(['bill_time' => $now_time], ['id' => $id, 'bill_time' => '0000-00-00 00:00:00']);
+ !is_bool($res) && $res && $jsondata['order.bill_time'] = "{$row['bill_time']}";
+
+ $res = $this->orders_status_entity->set_status($id, 0, 1);
+ $res && $jsondata['set_status_0_1'] = $res;
+
+ $res = $this->orders_status_entity->set_status($id, 0, 2);
+ $res && $jsondata['set_status_0_2'] = $res;
+
+ if (!$row['payway']) {
+ $res = $this->orders_status_entity->set_status($id, 1, 1);
+ $res && $jsondata['set_status_1_1'] = $res;
+ $res = $this->orders_status_entity->set_status($id, 1, 2);
+ $res && $jsondata['set_status_1_2'] = $res;
+ }
+
+ $res = $this->orders_status_entity->set_status($id, 2, 1);
+ $res && $jsondata['set_status_2_1'] = $res;
+
+ $res = $this->orders_status_entity->set_status($id, 3, 1);
+ $res && $jsondata['set_status_3_1'] = $res;
+
+ $res = $this->orders_status_entity->set_status($id, 4, 1);
+ $res && $jsondata['set_status_4_1'] = $res;
+
+ $res = $this->orders_status_entity->set_status($id, 4, 2);
+ $res && $jsondata['set_status_4_2'] = $res;
+
+ $res = $this->orders_status_entity->set_status($id, 5, 1);
+ $res && $jsondata['set_status_5_1'] = $res;
+
+ $cus_id = $row['customer_id'];
+ $cus = $this->customers_model->get(['id' => $cus_id]);
+ $res = $this->customers_model->update(['status' => 2, 'order_time' => $now_time], ['id' => $cus_id]);
+ !is_bool($res) && $res && $jsondata['customer.status'] = "{$cus['status']}->2";
+ $res = $this->customers_model->update(['order_time' => $now_time], ['id' => $cus_id, 'order_time' => '0000-00-00 00:00:00']);
+ !is_bool($res) && $res && $jsondata['customer.order_time'] = "{$cus['order_time']}";
+ $res && $jsondata['customer.order_time2'] = "{$cus['order_time']}, {$res}";
+
+ $content = '后台一键完成';
+ $cf_platform = 'pc_admin';
+ $this->orders_entity->add_log($id, $this->uid, $this->username, $content, 0, $cf_platform, $jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE));
+
+ if ($res_order) {
+ return $this->show_json(SYS_CODE_SUCCESS, '修改成功');
+ } else {
+ return $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+ }
+ return $this->show_json(SYS_CODE_FAIL, '提交失败');
+ }
+
+ //下载pdf
+ public function get_down()
+ {
+ require_once COMMPATH . '/third_party/TCPDF/tcpdf.php';
+ $id = $this->input->get('id');
+ $type = intval($this->input->get('type'));
+ $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' => $type], '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' => $type], '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();
+ }
+ }
+
+ //2022.12.19, 修改订单的优惠金额/服务费,判断是否到开票
+ private function order_status_check_after_adjust_fee($id)
+ {
+ if (!$id) {
+ return false;
+ }
+ $where = [
+ 'o_id' => $id,
+ 'status' => 1,
+ 'pay_price>' => 0,
+ 'type not in (7, 8)', // 'type!=' => 7 // 8为首付按揭
+ ];
+ $sum = $this->app_liche_orders_model->sum('total_price', $where); //已收金额
+ $total_price = $sum['total_price'];
+ $need_price = $this->orders_v2_entity->recevable_price($id); //应收金额
+ if ($total_price >= $need_price) {
+ $this->orders_status_entity->set_status($id, 0, 2);
+ } else {
+ $fee_status = $this->receiver_order_status_model->get(['o_id' => $id, 'pid_status' => 0, 'status' => 2]); //是否已付款
+ $fee_status && $this->receiver_order_status_model->delete(['o_id' => $id, 'pid_status' => 0, 'status' => 2]);
+ //$bill_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1]); //是否已开票
+ //$bill_status && $this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>3,'status'=>1]);
+ }
+
+ //是否已配车
+ /*$car_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>2,'status'=>1]);
+ if (!$car_status){
+ $row = $this->receiver_orders_v2_model->get(['id'=>$id]);
+ $row && $row['item_id'] && $this->orders_status_entity->set_status($id,2,1);
+ }*/
+ }
+
+ // 0首付下状态处理:非首付按揭有通知函 / 首付按揭时两个按揭的通知函都有,就可以设置 pid_status = 0 status = 2
+ private function order_status_check_after_edit_loan($order_row)
+ {
+ if (!$order_row) {
+ return false;
+ }
+
+ $money_json = json_decode($order_row['money_json'], true);
+ $payway = $order_row['payway'];
+ $deposit = $money_json['price_book'];
+ $if_zero_firstpay = $payway == 0 && !$deposit ? 1 : 0;
+ if (!$if_zero_firstpay) {
+ return false;
+ }
+
+ $oid = $order_row['id'];
+
+ $row = $this->order_loans_model->get(['o_id' => $oid]);
+ $if_loans_notify_file = $row && $row['notify_file'] ? 1 : 0;
+
+ if ($money_json['price_loan0']) {
+ $row0 = $this->order_loans0_model->get(['o_id' => $oid]);
+ $if_loans0_notify_file = $row0 && $row0['notify_file'] ? 1 : 0;
+ } else {
+ $if_loans0_notify_file = 1;
+ }
+
+ if ($if_loans_notify_file && $if_loans0_notify_file) {
+ $this->orders_status_entity->set_status($oid, 0, 2);
+ return true;
+ }
+ return false;
+ }
+
+ 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_status_check_after_adjust_fee($id);
+ //重新生成合同
+ $this->order_contracts_model->delete(['o_id' => $id]);
+ $url = http_host_com('api') . "/wxapp/licheb/protocol/create_pdf?id={$id}";
+ file_get_contents($url);
+// $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_price_car()
+ {
+ $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_car = $this->input->post('price_car');
+ if ($money_json['price_car'] > floatval($price_car)) {
+ return $this->show_json(SYS_CODE_FAIL, '售价不能下调!');
+ }
+ $money_json['price_car'] = floatval($price_car);
+ $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_status_check_after_adjust_fee($id);
+ //重新生成合同
+ $this->order_contracts_model->delete(['o_id' => $id]);
+ $url = http_host_com('api') . "/wxapp/licheb/protocol/create_pdf?id={$id}";
+ file_get_contents($url);
+// $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_car'] = $money_json['price_car'];
+ $this->data['id'] = $id;
+ return $this->show_view('receiver/orderv2/edit_price_car');
+ }
+
+ 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') {
+ $new_services = [];
+ $info = $this->input->post();
+ if (is_array($info['money'])) {
+ foreach ($info['money'] as $key => $val) {
+ if ($val['checkbox']) {
+ unset($val['checkbox']);
+ $new_services[] = $val;
+ $money_json[$val['key']] = floatval($val['price']);
+ } else {
+ $money_json[$val['key']] = 0;
+ }
+ # form改用vue后
+ if (in_array('checked', array_keys($val))) {
+ $val['price'] = $val['money'];
+ $checked = $val['checked'] == 'true' ? true : false;#var_dump($checked);
+ unset($val['checked']);
+ unset($val['title']);
+ unset($val['money']);
+ $checked && $new_services[] = $val;
+ $money_json[$val['key']] = $checked ? floatval($val['price']) : 0;
+ }
+ }
+ }#var_dump($new_services);exit();
+
+ # form改用vue后 增加精品选装
+ $price_fine_select = 0;
+ $fines = [];
+ if (is_array($info['fines'])) {
+ $fines = $info['fines'] ? $info['fines'] : [];
+ foreach ($fines as $key => $val) {
+ if ($val['id'] == -1 && intval($val['price']) == 0) {
+ unset($fines[$key]);
+ continue;
+ }
+ if ($val['txt'] == '' && intval($val['price']) == 0) {
+ unset($fines[$key]);
+ continue;
+ }
+ $price_fine_select += intval($val['price']);
+ }
+ }
+ $money_json['price_fine_select'] = $price_fine_select;
+
+ $srv_ids = is_array($new_services) ? array_column($new_services, 'id') : [];
+ $updata = [
+ 'if_insure' => in_array(1, $srv_ids) ? 1 : 0,
+ 'if_num' => in_array(2, $srv_ids) ? 1 : 0,
+ 'srv_ids' => json_encode($new_services, JSON_UNESCAPED_UNICODE),
+ 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE),
+ 'fines' => json_encode($fines, 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_status_check_after_adjust_fee($id);
+ //重新生成合同
+ $this->order_contracts_model->delete(['o_id' => $id]);
+ $url = http_host_com('api') . "/wxapp/licheb/protocol/create_pdf?id={$id}";
+ file_get_contents($url);
+// $this->orders_v2_entity->create_pdf($id);
+ return $this->show_json(SYS_CODE_SUCCESS, '保存成功!');
+ } else {
+ return $this->show_json(SYS_CODE_FAIL, '保存失败!');
+ }
+ }
+ //获取车辆服务费
+ $lists = [
+ ['id' => 1, 'key' => 'price_insure', 'title' => '代办保险'],
+ ['id' => 2, 'key' => 'fee_carno', 'title' => '代办上牌']
+ ];
+ !$row['payway'] && $lists[] = ['id' => 4, 'key' => 'price_finance', 'title' => '代办按揭'];
+ $srv_ids = is_array($services) ? array_column($services, 'id') : [];
+ foreach ($lists as $key => $val) {
+ $lists[$key]['money'] = $money_json[$val['key']] ? $money_json[$val['key']] : 0;
+ //$lists[$key]['checked'] = in_array($val['id'],$srv_ids) ? 'checked' : '';
+ $lists[$key]['checked'] = in_array($val['id'], $srv_ids) ? true : false; // form 改 vue
+ }
+ $this->data['srv_info'] = $lists;
+ $this->data['id'] = $id;
+
+ // 0522增加精品选装(biz_type==1后台手工添加的均为自定义,biz_type!=1只能修改price)
+ /*$this->load->model('receiver/receiver_fine_model');
+ $where = [
+ 'status' => 1
+ ];
+ $where['biz_id'] = $row['biz_id'];
+ $fines_list = $this->receiver_fine_model->select($where,'id desc',0,0,'id,title,price');
+ $this->data['fines_list'] = $fines_list;*/
+ $biz = $this->biz_model->get(['id' => $row['biz_id']], 'id,city_id,type');
+ $this->data['biz_type'] = $biz['type'];
+ $this->data['fines'] = $row['fines'] ? json_decode($row['fines'], true) : [];
+ if (!$this->data['fines']) {
+ if ($biz['type'] != 1) {
+ $this->data['fines'] = [array("id" => "-1", "txt" => "服务费", "price" => "0")];
+ }
+ }
+ $this->data['price_fine_select'] = sprintf("%.2f", $money_json['price_fine_select']);
+
+ return $this->show_view('receiver/orderv2/edit_srv');
+ }
+
+ public function edit_bill_img()
+ {
+ $id = $this->input->post('id');
+ $file = $this->input->post('value');
+ if (!$file || !$id) {
+ $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+ $re_data = $this->receiver_order_datas_model->get(['o_id' => $id]);
+ $bill_ck_img = [];
+ 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'];
+ #$bill_ck_img = json_decode($re_data['bill_ck_img'],true); # 2022-12-07 都改成覆盖
+ }
+
+ if (strpos($file, '.pdf') !== false) {
+ $this->load->library('pdf');
+ $pdf_url = build_qiniu_image_url($file);
+ $pdf_imgs = $this->pdf->pdf2img($pdf_url);
+ if ($pdf_imgs) {
+ $bill_ck_img = $this->up_qiniu($pdf_imgs);
+ } else {
+ return $this->show_json(SYS_CODE_FAIL, 'pdf识别失败');
+ }
+ } else {
+ $bill_ck_img[] = $file;
+ }
+ $update = [
+ 'bill_ck_img' => json_encode($bill_ck_img, JSON_UNESCAPED_UNICODE)
+ ];
+ $res = $this->receiver_order_datas_model->update($update, ['id' => $re_data_id]);
+ if ($res) {
+ return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
+ } else {
+ return $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+ }
+
+ //图片上传七牛
+ private function up_qiniu($imgs)
+ {
+ $this->load->library('qiniu');
+ //上传七牛并保存
+ foreach ($imgs as $key => $val) {
+ $file_name = date('Ym') . "/" . md5($val) . '.jpg';
+ $result = $this->qiniu->fetch($val, $file_name);
+ if ($result) {
+ $imgs[$key] = $result['file'];
+ }
+ }
+ return $imgs;
+ }
+
+ public function del_img()
+ {
+ $info = $this->input->post();
+ if (!$info['type'] || !$info['field']) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+ $res = false;
+ if ($info['type'] == 'data') {
+ $row = $this->receiver_order_datas_model->get(['o_id' => $info['id']]);
+ if (!$row) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+ if ($info['field'] == 'ins_img' || $info['field'] == 'other_img') {
+ $jsondata = json_decode($row[$info['field']], true);
+ $new_jsondata = [];
+ foreach ($jsondata as $item) {
+ if (strpos($info['value'], $item) !== false) {
+ } else {
+ $new_jsondata[] = $item;
+ }
+ }
+ $update = [
+ $info['field'] => json_encode($new_jsondata, JSON_UNESCAPED_UNICODE)
+ ];
+ } elseif ($info['field'] == 'insurance_img' || $info['field'] == 'business_img' || $info['field'] == 'accident_img' || $info['field'] == 'bill_ck_img') {
+ $update = [
+ $info['field'] => json_encode([])
+ ];
+
+ # 0612各保单支持返点系数, 保留系数
+ $insurance_img = json_decode($row['insurance_img'], true);
+ $business_img = json_decode($row['business_img'], true);
+ $accident_img = json_decode($row['accident_img'], true);
+ if ($info['field'] == 'insurance_img' && $insurance_img['rebate']) {
+ $update = [
+ $info['field'] => json_encode(['rebate' => $insurance_img['rebate']])
+ ];
+ } elseif ($info['field'] == 'business_img' && $business_img['rebate']) {
+ $update = [
+ $info['field'] => json_encode(['rebate' => $business_img['rebate']])
+ ];
+ } elseif ($info['field'] == 'accident_img' && $accident_img['rebate']) {
+ $update = [
+ $info['field'] => json_encode(['rebate' => $accident_img['rebate']])
+ ];
+ }
+ } else {
+ $update = [
+ $info['field'] => ''
+ ];
+ }
+ $res = $this->receiver_order_datas_model->update($update, ['o_id' => $info['id']]);
+ } elseif ($info['type'] == 'load_info') {
+ $row = $this->order_loans_model->get(['o_id' => $info['id']]);
+ if (!$row) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+ if ($info['field'] == 'notify_file') {
+ $notify_file_lists = explode(',', $row['notify_file']);
+ unset($notify_file_lists[$info['value']]);
+ $update = [
+ $info['field'] => implode(',', $notify_file_lists)
+ ];
+ } else {
+ $update = [
+ $info['field'] => ''
+ ];
+ }
+ $res = $this->order_loans_model->update($update, ['o_id' => $info['id']]);
+ } elseif ($info['type'] == 'load_info0') {
+ // 首付按揭
+ $row = $this->order_loans0_model->get(['o_id' => $info['id']]);
+ if (!$row) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误');
+ }
+ if ($info['field'] == 'notify_file') {
+ $notify_file_lists = explode(',', $row['notify_file']);
+ unset($notify_file_lists[$info['value']]);
+ $update = [
+ $info['field'] => implode(',', $notify_file_lists)
+ ];
+ } else {
+ $update = [
+ $info['field'] => ''
+ ];
+ }
+ $res = $this->order_loans0_model->update($update, ['o_id' => $info['id']]);
+ }
+
+ if ($res) {
+ return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
+ } else {
+ return $this->show_json(SYS_CODE_FAIL, '保存失败');
+ }
+ }
+}
diff --git a/admin/libraries/OrdersList.php b/admin/libraries/OrdersList.php
new file mode 100644
index 00000000..81f14d39
--- /dev/null
+++ b/admin/libraries/OrdersList.php
@@ -0,0 +1,592 @@
+ '客户姓名', 'mobile' => '客户手机号', 'sid' => '订单号');
+ private $paywayAry = array(0 => '按揭', 1 => '全款');
+ private $overAry = array(0 => '7天内', 1 => '14天内', 2 => '30天内', 3 => '大于30天');
+
+ public function __construct()
+ {
+ $this->ci = &get_instance();
+ $this->ci->load->model('receiver/order/receiver_orders_model', 'mdOrders');
+ $this->ci->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers');
+ $this->ci->load->model('app/licheb/app_licheb_channel_biz_model');
+ $this->ci->load->model('receiver/receiver_customers_model', 'mdCustomers');
+ $this->ci->load->model('receiver/receiver_clues_cfrom_model', 'mdCluesCfrom');
+ $this->ci->load->model('auto/auto_series_model');
+ $this->ci->load->model('auto/auto_brand_model');
+ $this->ci->load->model('auto/auto_cars_model');
+ $this->ci->load->model('area_model');
+ $this->ci->load->model("biz/biz_model");
+
+ }
+
+ public function lists($status_pid, $params = array())
+ {
+ !$params['qdjl_id'] && $params['qdjl_id'] = '';
+ !$params['of_id'] && $params['of_id'] = '';
+ !$params['of2_id'] && $params['of2_id'] = '';
+ !strlen($params['payway']) && $params['payway'] = '';
+ !$params['biz_type'] && $params['biz_type'] = '';
+ !strlen($params['over_id']) && $params['over_id'] = '';
+ !strlen($params['is_bill']) && $params['is_bill'] = '';
+ $fieldAry = $this->get_fields($status_pid, 0, $params['status']);
+ $show_info['offlineSourcesAry'] = $this->ci->mdCustomers->offlineSources_search();
+ $show_info['paywayAry'] = $this->paywayAry;//付款方式
+ //渠道经理
+ $show_info['qdjl_lists'] = $this->ci->mdLichebUsers->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0')
+ , 'id desc', 0, 0, 'id,uname as name');
+ $result = $this->orders($params);
+ $result['show_info'] = $show_info;
+ $result['fieldAry'] = $fieldAry;
+ return $result;
+ }
+
+ /**
+ * Notes:全部订单
+ * Created on: 2021/9/18 15:13
+ * Created by: dengbw
+ * @param array $params
+ * @return array
+ */
+ private function orders($params = array())
+ {
+ $page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
+ $size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
+ $order_status_cn = $this->ci->mdOrders->get_status();
+ $view_type = 'orders';
+ $where = [
+ "status>=" => 0,
+ ];
+ $_title = '全部订单';
+ $view = 'receiver/orderv2/lists';
+ $params['status_pid'] == 1 && $where["payway"] = 0;
+ if (is_product()) {
+ $where["biz_id<>"] = 1;
+ }
+ if ($_SESSION['admin_info']['biz_id']) {
+ $biz_ids = implode(',', $_SESSION['admin_info']['biz_id']);
+ $where["biz_id in ($biz_ids)"] = null;
+ }
+ if ($params['biz_type']) {
+ $where["biz_id in (select id from lc_biz where type = " . $params['biz_type'] . ')'] = null;
+ }
+ if ($params['of_id'] || $params['of2_id']) {
+ $where_c = 'status>=0';
+ $params['of_id'] && $where_c .= ' and of_id = ' . $params['of_id'];
+ $params['of2_id'] && $where_c .= ' and of2_id = ' . $params['of2_id'];
+ $where["customer_id in (select id from lc_receiver_customers where " . $where_c . ')'] = null;
+ }
+ if (strlen($params['payway'])) {
+ $where["payway"] = $params['payway'];
+ }
+ if ($params['qdjl_id']) {//渠道经理
+ $where["biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null;
+ }
+ if ($params['title']) {
+ $where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
+ }
+ //创建时间
+ if ($params['c_time']) {
+ $c_time = explode(' ~ ', $params['c_time']);
+ if ($c_time[0]) {
+ $where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
+ }
+ if ($c_time[1]) {
+ $where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
+ }
+ }
+ //下定时间
+ if ($params['order_time']) {
+ $order_time = explode(' ~ ', $params['order_time']);
+ if ($order_time[0]) {
+ $where["order_time >="] = $order_time[0] . ' 00:00:00';
+ }
+ if ($order_time[1]) {
+ $where["order_time <="] = $order_time[1] . ' 23:59:59';
+ }
+ }
+ //开票时间
+ if ($params['bill_time']) {
+ $bill_time = explode(' ~ ', $params['bill_time']);
+ if ($bill_time[0]) {
+ $where["bill_time >="] = $bill_time[0] . ' 00:00:00';
+ }
+ if ($bill_time[1]) {
+ $where["bill_time <="] = $bill_time[1] . ' 23:59:59';
+ }
+ }
+ //交付时间
+ if ($params['ck_time']) {
+ $ck_time = explode(' ~ ', $params['ck_time']);
+ if ($ck_time[0]) {
+ $where["ck_time >="] = $ck_time[0] . ' 00:00:00';
+ }
+ if ($ck_time[1]) {
+ $where["ck_time <="] = $ck_time[1] . ' 23:59:59';
+ }
+ }
+ if (strlen($params['is_bill'])) {
+ if ($params['is_bill']) {
+ $where["bill_time <> '0000-00-00 00:00:00'"] = null;
+ } else {
+ $where["bill_time"] = '0000-00-00 00:00:00';
+ }
+ }
+ //交付时长
+ if (strlen($params['over_id'])) {
+ if ($params['over_id'] == 3) {
+ $where["over_time>"] = date('Y-m-d', time() + 30 * 24 * 60 * 60);
+ } else {
+ if ($params['over_id'] == 1) {
+ $e_day = 14;
+ } elseif ($params['over_id'] == 2) {
+ $e_day = 30;
+ } else {
+ $e_day = 7;
+ }
+ $where["over_time<="] = date('Y-m-d', time() + $e_day * 24 * 60 * 60);
+ }
+ }
+ if ($params['brand_id']) {//品牌
+ $where["brand_id"] = $params['brand_id'];
+ } else {
+ $params['brand_id'] = '';
+ }
+ if ($params['series_id']) {//车系
+ $where["series_id"] = $params['series_id'];
+ } else {
+ $params['series_id'] = '';
+ }
+ if ($params['v_id']) {//车型
+ $where["v_id"] = $params['v_id'];
+ } else {
+ $params['v_id'] = '';
+ }
+ if ($params['cor_id']) {//车身颜色
+ $where["cor_id"] = $params['cor_id'];
+ } else {
+ $params['cor_id'] = '';
+ }
+ //销售员筛选
+ if ($params['admin_id']) {
+ $where["sale_id"] = $params['admin_id'];
+ } else {
+ if ($params['biz_id_admin']) {//指定店铺所有销售员
+ $where["biz_id"] = $params['biz_id_admin'];
+ } else {
+ //指定城市的所有门店
+ $where_biz = array();
+ if ($params['county_id_admin']) {
+ $where_biz['county_id'] = $params['county_id_admin'];
+ } else if ($params['city_id_admin']) {
+ $where_biz['city_id'] = $params['city_id_admin'];
+ }
+ if ($where_biz) {
+ $where_biz['status>-1'] = null;
+ $rows_biz = $this->ci->biz_model->select($where_biz, 'id desc', 0, 0, 'id');
+ if ($rows_biz) {
+ $str_ids = implode(',', array_column($rows_biz, 'id'));
+ $where["biz_id in({$str_ids})"] = null;
+ } else {
+ $where["biz_id"] = -1;
+ }
+ }
+ }
+ !$params['city_id_admin'] && $params['city_id_admin'] = '';
+ !$params['county_id_admin'] && $params['county_id_admin'] = '';
+ !$params['biz_id_admin'] && $params['biz_id_admin'] = '';
+ $params['admin_id'] = '';
+ }
+ if (strlen($params['status_pid'])) {
+ $where["brand_id>"] = 0;
+ }
+ if (strlen($params['status_pid']) && $params['status_pid'] != 21) { //付款-已下定
+ $where["status <> 2"] = null;
+ }
+ if ($params['status_pid'] == 4) { //交付需要开票后才显示
+ $where["id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)"] = null;
+ }
+ if (strlen($params['status_pid']) && !$params['status_pid']) { //付款列表 下定时间排序
+ $orderby = "order_time desc";
+ } elseif ($params['status_pid'] == 3) { // 开票列表 开票时间排序
+ $orderby = "bill_time desc";
+ } elseif ($params['status_pid'] == 21) { //退款时间排序
+ $orderby = "refund_time desc";
+ } elseif ($params['status_pid'] == 5 || ($params['status'] == 2 && $params['status_pid'] == 4)) { //交付时间排序
+ $orderby = "ck_time desc,c_time desc";
+ } else {
+ $orderby = "c_time desc";
+ }
+ $count = $this->ci->mdOrders->count($where);
+ $rows = $this->ci->mdOrders->select($where, $orderby, $page, $size);
+ $lists = [];
+ if ($count) {
+ //客户来源
+ $str_rids = implode(',', array_unique(array_column($rows, 'customer_id')));
+ !$str_rids && $str_rids = 0;
+ $customers = $this->ci->mdCustomers->map('id', 'of_id,of2_id', array("id in({$str_rids})" => null));
+ $offlineSources = $this->ci->mdCustomers->offlineSources();
+ //门店
+ $str_biz_ids = implode(',', array_unique(array_column($rows, 'biz_id')));
+ !$str_biz_ids && $str_biz_ids = 0;
+ $bizs_rows = $this->ci->biz_model->select(array("id in({$str_biz_ids})" => null), '', '', '', 'id,biz_name,city_id,county_id,type');
+ $bizs = [];
+ if ($bizs_rows) { //获取城市
+ $ids = array_unique(array_column($bizs_rows, 'county_id'));
+ $city_rows = $this->ci->area_model->get_map_by_county_ids($ids, 'id,city_name,city_id', 'city_id');
+ foreach ($bizs_rows as $val) {
+ $val['city_name'] = $city_rows[$val['city_id']] ? $city_rows[$val['city_id']][0]['city_name'] : '';
+ $bizs[$val['id']] = $val;
+ }
+ }
+
+ //品牌车型
+ $brand_arr = array_unique(array_column($rows, 'brand_id'));
+ $brands = $this->ci->auto_brand_model->get_map_by_ids($brand_arr, 'id,name');
+ //车系车型
+ $series_arr = array_unique(array_column($rows, 'series_id'));
+ $series = $this->ci->auto_series_model->get_map_by_ids($series_arr, 'id,name');
+ //车系车型
+ $car_arr = array_unique(array_column($rows, 'car_id'));
+ $cars = $this->ci->auto_cars_model->get_map_by_ids($car_arr, 'id,name');
+
+ $admin_ids = array_unique(array_column($rows, 'admin_id'));
+ $admin_ids_str = implode(',', $admin_ids);
+ $admins = [];
+ if ($admin_ids_str) {
+ $where = ["id in ($admin_ids_str)" => null];
+ $admins = $this->ci->mdLichebUsers->map('id', 'uname', $where, 'id desc', 0, 0, 'id,uname'); //顾问
+ }
+ foreach ($rows as $key => $val) {
+ $info_json = json_decode($val['info_json'], true);
+ $fields = array();
+ $brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
+ $series_name = isset($series[$val['series_id']]) ? $series[$val['series_id']][0]['name'] : '';
+ $car_name = isset($cars[$val['car_id']]) ? $cars[$val['car_id']][0]['name'] : '';
+ $money_json = json_decode($val['money_json'], true);
+ $fields['o_id'] = $val['id'];
+ $name = $val['name'];
+ $mobile = $val['mobile'];
+ $open_url = '/receiver/orderv2/orders/get?id=';
+ $id_card_append = $info_json['c_owner_cardid'] ? '
' . $info_json['c_owner_cardid'] : '';
+ $id_card = $info_json['c_owner_cardid'] ? '="' . $info_json['c_owner_cardid'] . '"' : '';
+ $fields['name'] = $size > 1000 ? $name
+ : '' . $name . '
' . $mobile . $id_card_append . '';
+ $fields['id_card'] = $id_card;
+ $fields['mobile'] = $size > 1000 ? '="' . $mobile . '"' : $mobile;
+ $fields['car_name'] = "{$brand_name}-{$series_name}-{$car_name}";
+ $fields['price_car'] = 0;
+ $fields['payway_name'] = $this->paywayAry[$val['payway']];
+ $fields['price'] = $fields['payway_name'] . "
" . $fields['price_car'];
+ $fields['brand_name'] = $brand_name;
+ $fields['series_name'] = $series_name;
+ $status_name = $order_status_cn[$val['status']];
+ $fields['status_name'] = $status_name;
+ $fields['biz_name'] = $bizs[$val['biz_id']] ? $bizs[$val['biz_id']]['biz_name'] . '
' . $admins[$val['admin_id']] : '';
+ $size > 1000 && $fields['biz_name'] = $bizs[$val['biz_id']] ? $bizs[$val['biz_id']]['biz_name'] : '';
+ $fields['c_time'] = date('Y-m-d H:i:s', $val['c_time']);
+ $of_title = '-';
+ $of_title_1 = $of_title_2 = '';
+ $of_id = $customers[$val['customer_id']]['of_id'];
+ if ($of_id) {
+ $of_ary = $offlineSources[$of_id];
+ $of_title = $of_ary['name'];
+ $of_ary['name'] && $of_title_1 = $of_ary['name'];
+ $of2_id = $customers[$val['customer_id']]['of2_id'];
+ $of2_id && $of_title .= '-' . $of_ary['list'][$of2_id];
+ $of2_id && $of_ary['list'][$of2_id] && $of_title_2 = $of_ary['list'][$of2_id];
+ }
+ $fields['of_title'] = $of_title;
+ $fields['of_title_1'] = $of_title_1;
+ $fields['of_title_2'] = $of_title_2;
+ $fields['order_time'] = $val['order_time'] != '0000-00-00 00:00:00' ? $val['order_time'] : '';
+ $fields['bill_time'] = $val['bill_time'] != '0000-00-00 00:00:00' ? $val['bill_time'] : '';
+ $fields['over_time'] = $val['over_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($val['over_time'])) : '';
+ $fields['refund_time'] = $val['refund_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($val['refund_time'])) : '';
+ $fields['ck_time'] = $val['ck_time'];
+
+ if ($size > 1000) {
+ $user_info = '';
+ if ($bizs[$val['biz_id']]['type'] == 3) { //代理店显示渠道经理的姓名
+ $channel_users = $this->ci->app_licheb_channel_biz_model->select(['biz_id' => $val['biz_id']], '', '', '', 'uid');
+ $user_ids = array_column($channel_users, 'uid');
+ $user_ids_str = implode(',', $user_ids);
+ if ($user_ids_str && $user_ids) {
+ $where = [
+ 'group_id' => 4,
+ 'status' => 1,
+ "id in ($user_ids_str)" => null
+ ];
+ $users = $this->ci->mdLichebUsers->select($where, 'id desc', 1, 10, 'uname,biz_id'); //渠道经理
+ $users && $user_info = implode(' ', array_column($users, 'uname'));
+ }
+ $fields['admin_name'] = $user_info;
+ }
+ if (!$user_info) {
+ $sale = $this->ci->mdLichebUsers->get(['id' => $val['sale_id']], 'uname');
+ $fields['admin_name'] = $sale['uname'];
+ }
+ $fields['address'] = $info_json['c_address'];
+ }
+ if (!$val['payway']) { //按揭
+ $fields['pro_loan'] = '';
+ $fields['price_loan'] = $money_json['price_loan'];
+ $fields['is_sure'] = '';
+ $fields['is_tiexi'] = '是';
+ // 首付按揭
+ $fields['pro_loan0'] = '222';
+ $fields['price_loan0'] = 10;
+ $fields['is_sure0'] = '是';
+ $fields['is_tiexi'] = '是';
+ }
+ $srv_info = [];
+ $fields['srv_info_total'] = $srv_info['total'] > 0 ? $srv_info['total'] : '';
+ $fields['srv_info_fee_carno'] = $srv_info['fee_carno'] ? $srv_info['fee_carno'] : '';
+ $fields['srv_info_price_finance'] = $srv_info['price_finance'] ? $srv_info['price_finance'] : '';
+ $fields['srv_info_price_fine_select'] = $srv_info['price_fine_select'] ? $srv_info['price_fine_select'] : '';
+ $fields['srv_info_price_fine_select_detail'] = $srv_info['price_fine_select_detail'] ? $srv_info['price_fine_select_detail'] : '';
+ $lists[] = $fields;
+ }
+ }
+ $pager = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
+ $_title = $size > 1000 ? $_title : $_title . '列表';
+ $view_type != 'orders' && $status_arr = [];
+ return array('lists' => $lists, 'pager' => $pager, 'params' => $params, 'status_arr' => $status_arr
+ , 'searchTpAry' => $this->searchTpAry, 'view' => $view, 'view_type' => $view_type, '_title' => $_title);
+ }
+
+ /**
+ * Notes:意向金订单
+ * @param array $params
+ * @return array
+ */
+ private function inten_orders($params = array())
+ {
+ $page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
+ $size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
+ $status_arr = $this->ci->receiver_order_status_model->statusAry();
+ $view_type = 'orders';
+ $where = [
+ "status" => 0,
+ "id>=" => 10000,
+ "brand_id" => 0
+ ];
+ $_title = '全部订单';
+ $view = 'receiver/orderv2/lists';
+ $params['status_pid'] == 1 && $where["payway"] = 0;
+ if (is_product()) {
+ $where["biz_id<>"] = 1;
+ }
+ if ($_SESSION['admin_info']['biz_id']) {
+ $biz_ids = implode(',', $_SESSION['admin_info']['biz_id']);
+ $where["biz_id in ($biz_ids)"] = null;
+ }
+ if ($params['of_id'] || $params['of2_id']) {
+ $where_c = 'status>=0';
+ $params['of_id'] && $where_c .= ' and of_id = ' . $params['of_id'];
+ $params['of2_id'] && $where_c .= ' and of2_id = ' . $params['of2_id'];
+ $where["customer_id in (select id from lc_receiver_customers where " . $where_c . ')'] = null;
+ }
+ if ($params['qdjl_id']) {//渠道经理
+ $where["biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null;
+ }
+ if ($params['title']) {
+ $where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
+ }
+ //创建时间
+ if ($params['c_time']) {
+ $c_time = explode(' ~ ', $params['c_time']);
+ if ($c_time[0]) {
+ $where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
+ }
+ if ($c_time[1]) {
+ $where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
+ }
+ }
+ //销售员筛选
+ if ($params['admin_id']) {
+ $where["sale_id"] = $params['admin_id'];
+ } else {
+ if ($params['biz_id_admin']) {//指定店铺所有销售员
+ $where["biz_id"] = $params['biz_id_admin'];
+ } else {
+ //指定城市的所有门店
+ $where_biz = array();
+ if ($params['county_id_admin']) {
+ $where_biz['county_id'] = $params['county_id_admin'];
+ } else if ($params['city_id_admin']) {
+ $where_biz['city_id'] = $params['city_id_admin'];
+ }
+ if ($where_biz) {
+ $where_biz['status>-1'] = null;
+ $rows_biz = $this->ci->biz_model->select($where_biz, 'id desc', 0, 0, 'id');
+ if ($rows_biz) {
+ $str_ids = implode(',', array_column($rows_biz, 'id'));
+ $where["biz_id in({$str_ids})"] = null;
+ } else {
+ $where["biz_id"] = -1;
+ }
+ }
+ }
+ !$params['city_id_admin'] && $params['city_id_admin'] = '';
+ !$params['county_id_admin'] && $params['county_id_admin'] = '';
+ !$params['biz_id_admin'] && $params['biz_id_admin'] = '';
+ $params['admin_id'] = '';
+ }
+ $where["id in(select o_id from lc_app_liche_orders where type=4 and status=1 and o_id>=10000)"] = null;
+
+ $fileds = "id,name,mobile,brand_id,series_id,v_id,
+ cor_id,incor_id,money_json,payway,status,c_time,
+ biz_id,bill_time,customer_id,owner_name,owner_mobile,main_type,info_json,
+ order_time,bill_time,item_id,over_time";
+
+ $count = $this->ci->mdOrders->count($where);
+ $rows = $this->ci->mdOrders->select($where, 'c_time desc', $page, $size, $fileds);
+ $lists = [];
+ if ($count) {
+ //客户来源
+ $str_rids = implode(',', array_unique(array_column($rows, 'customer_id')));
+ !$str_rids && $str_rids = 0;
+ $customers = $this->ci->mdCustomers->map('id', 'of_id,of2_id', array("id in({$str_rids})" => null));
+ $offlineSources = $this->ci->mdCustomers->offlineSources();
+ //门店
+ $str_biz_ids = implode(',', array_unique(array_column($rows, 'biz_id')));
+ !$str_biz_ids && $str_biz_ids = 0;
+ $bizs = $this->ci->biz_model->map('id', 'biz_name', array("id in({$str_biz_ids})" => null));
+ foreach ($rows as $key => $val) {
+ $info_json = json_decode($val['info_json'], true);
+ $fields = array();
+ $fields['o_id'] = $val['id'];
+ if ($val['main_type']) {
+ $name = $info_json['c_company'];
+ $mobile = $val['mobile'];
+ } else {
+ $name = $val['owner_name'];
+ $mobile = $val['owner_mobile'];
+ }
+ $open_url = '/receiver/orderv2/orders/get?id=';
+ $id_card_append = $info_json['c_owner_cardid'] ? '
' . $info_json['c_owner_cardid'] : '';
+ $fields['name'] = $size > 1000 ? $name
+ : '' . $name . '
' . $mobile . $id_card_append . '';
+ $fields['id_card'] = $info_json['c_owner_cardid'] ? '="' . $info_json['c_owner_cardid'] . '"' : '';
+ $fields['mobile'] = $size > 1000 ? '="' . $mobile . '"' : $mobile;
+ $fields['biz_name'] = $bizs[$val['biz_id']];
+ $fields['c_time'] = date('Y-m-d H:i:s', $val['c_time']);
+ $of_title = '-';
+ $of_title_1 = $of_title_2 = '';
+ $of_id = $customers[$val['customer_id']]['of_id'];
+ if ($of_id) {
+ $of_ary = $offlineSources[$of_id];
+ $of_title = $of_ary['name'];
+ $of_ary['name'] && $of_title_1 = $of_ary['name'];
+ $of2_id = $customers[$val['customer_id']]['of2_id'];
+ $of2_id && $of_title .= '-' . $of_ary['list'][$of2_id];
+ $of2_id && $of_ary['list'][$of2_id] && $of_title_2 = $of_ary['list'][$of2_id];
+ }
+ $fields['of_title'] = $of_title;
+ $fields['of_title_1'] = $of_title_1;
+ $fields['of_title_2'] = $of_title_2;
+ $lists[] = $fields;
+ }
+ }
+ $pager = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
+ $_title = $size > 1000 ? $_title : $_title . '列表';
+ $view_type != 'orders' && $status_arr = [];
+ return array('lists' => $lists, 'pager' => $pager, 'params' => $params, 'status_arr' => $status_arr
+ , 'searchTpAry' => $this->searchTpAry, 'view' => $view, 'view_type' => $view_type, '_title' => $_title);
+ }
+
+ /**
+ * Notes:获取字段
+ * Created on: 2021/10/29 15:38
+ * Created by: dengbw
+ * @param $status_pid
+ * @param int $export
+ * @return array
+ */
+ public function get_fields($status_pid, $export = 0, $status)
+ {
+ $fields1 = $fields2 = [];
+ if ($export) {
+ $fields1['name'] = ['title' => '客户姓名'];
+ $fields1['mobile'] = ['title' => '客户电话'];
+ $fields1['id_card'] = ['title' => '证件号码'];
+ $fields1['brand_name'] = ['title' => '品牌'];
+ $fields1['series_name'] = ['title' => '车系'];
+ $fields1['v_name'] = ['title' => '车型'];
+ $fields1['cor_name'] = ['title' => '车身颜色'];
+ $fields1['city_name'] = ['title' => '城市'];
+ $fields1['biz_type'] = ['title' => '门店类型'];
+ $fields1['biz_name'] = ['title' => '门店'];
+ $fields1['admin_name'] = ['title' => '销售人员'];
+ $fields1['of_title_1'] = ['title' => '来源1'];
+ $fields1['of_title_2'] = ['title' => '来源2'];
+ } else {
+ $fields1['name'] = ['title' => '客户', 'width' => '14%'];
+ }
+ if (!strlen($status_pid)) {
+ $fields2 = [
+ 'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
+ 'price' => ['title' => '最终售价', 'width' => '9%'],
+ 'of_title' => ['title' => '客户来源', 'width' => '10%'], 'status_name' => ['title' => '状态', 'width' => '9%'],
+ 'c_time' => ['title' => '订单时间', 'width' => '9%'
+ ]
+ ];
+ } elseif ($status_pid == 3) {
+ $fields2 = [
+ 'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
+ 'price' => ['title' => '最终售价', 'width' => '9%'],
+// 'payway_name' => ['title' => '付款方式', 'width' => '8%'],
+ 'of_title' => ['title' => '客户来源', 'width' => '10%'], 'status_name' => ['title' => '状态', 'width' => '9%'],
+ 'bill_time' => ['title' => '开票时间', 'width' => '9%']
+ ];
+ } else {
+ $fields2 = [
+ 'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
+ 'price' => ['title' => '最终售价', 'width' => '9%'],
+ 'of_title' => ['title' => '客户来源', 'width' => '10%'], 'status_name' => ['title' => '状态', 'width' => '9%'],
+ 'order_time' => ['title' => '下定时间', 'width' => '9%'], 'over_time' => ['title' => '交付截止', 'width' => '9%']
+ ];
+ if ($status_pid == 21) {
+ unset($fields2['over_time']);
+ $fields2['refund_time'] = ['title' => '退款时间', 'width' => '9%'];
+ }
+ if ($status_pid == 5 || ($status_pid == 4 && $status == 2)) {
+ unset($fields2['over_time']);
+ $fields2['ck_time'] = ['title' => '交付时间', 'width' => '9%'];
+ }
+ }
+ $fields = array_merge($fields1, $fields2);
+ if ($export) {
+ unset($fields['price'], $fields['c_time'], $fields['car_name'], $fields['of_title']);
+ $fields['payway_name'] = ['title' => '付款方式'];
+ $fields['pro_loan0'] = ['title' => '首付按揭-金融机构'];
+ $fields['price_loan0'] = ['title' => '首付按揭-金额'];
+ $fields['is_sure0'] = ['title' => '首付按揭-确认到款(是/否)'];
+ $fields['pro_loan'] = ['title' => '金融机构'];
+ $fields['is_tiexi'] = ['title' => '贴息'];
+ $fields['price_loan'] = ['title' => '按揭金额'];
+ $fields['is_sure'] = ['title' => '确认到款(是/否)'];
+ $fields['price_car'] = ['title' => '最终售价'];
+ $fields['srv_info_total'] = ['title' => '手续费'];
+ $fields['srv_info_fee_carno'] = ['title' => '手续费-上牌'];
+ $fields['srv_info_price_finance'] = ['title' => '手续费-按揭'];
+ $fields['srv_info_price_fine_select'] = ['title' => '手续费-精品选装'];
+ $fields['srv_info_price_fine_select_detail'] = ['title' => '精品选装内容'];
+ !$fields['c_time'] && $fields['c_time'] = ['title' => '订单时间'];
+ !$fields['over_time'] && $fields['over_time'] = ['title' => '止交付时间'];
+ !$fields['order_time'] && $fields['order_time'] = ['title' => '下定时间'];
+ !$fields['bill_time'] && $fields['bill_time'] = ['title' => '开票时间'];
+ $fields['address'] = ['title' => '联系人地址'];
+ }
+ return $fields;
+ }
+}
+
+?>
diff --git a/admin/views/receiver/order/lists.php b/admin/views/receiver/order/lists.php
new file mode 100644
index 00000000..cc18169e
--- /dev/null
+++ b/admin/views/receiver/order/lists.php
@@ -0,0 +1,531 @@
+
+
| = $v['title'] ?> | + } ?> +
|---|
| = $v[$key] ?> | + } ?> +