370 lines
14 KiB
PHP
370 lines
14 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/07/09
|
|
* Time: 14:08
|
|
*/
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
class Cusorder extends Wxapp{
|
|
|
|
function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg =array();//授权微信信息
|
|
|
|
$this->load->model('receiver/receiver_customers_model','customers_model');
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
$this->load->model('receiver/order/receiver_order_signs_model','order_signs_model');
|
|
$this->load->model('receiver/order/receiver_order_bills_model','order_bills_model');
|
|
$this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_model');
|
|
|
|
$this->load->model('receiver/receiver_services_model','services_model');
|
|
$this->load->model('receiver/receiver_service_package_model','package_model');
|
|
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
}
|
|
|
|
protected function get(){
|
|
$id = $this->input_param('id');
|
|
if($id){
|
|
return $this->detail($id);
|
|
}else{
|
|
return $this->lists();
|
|
}
|
|
}
|
|
|
|
//创建订单
|
|
protected function post(){
|
|
$cus_id = $this->input_param('cus_id');
|
|
$car_id = $this->input_param('car_id');
|
|
$color_id = $this->input_param('color_id');
|
|
$incolor_id = $this->input_param('incolor_id');
|
|
$v_id = $this->input_param('v_id');
|
|
$price = $this->input_param('price');
|
|
$deposit = $this->input_param('deposit');
|
|
$payway = $this->input_param('payway');
|
|
$pack_id = $this->input_param('pack_id');
|
|
$main_type = $this->input_param('main_type');
|
|
$ifentrust = $this->input_param('ifentrust');
|
|
$entrust_name = $this->input_param('entrust_name');
|
|
$entrust_idcard = $this->input_param('entrust_idcard');
|
|
$name = $this->input_param('name');
|
|
$mobile = $this->input_param('mobile');
|
|
$address = $this->input_param('address');
|
|
$cardid = $this->input_param('cardid');
|
|
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
|
|
if(!$row || !$series_row || !$cardid || !$address){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
//判断是否存在未完成流程
|
|
if($this->orders_model->get_step($row['mobile'])){
|
|
throw new Exception('该手机号用户存在未完成订单', API_CODE_FAIL);
|
|
}
|
|
$where = [
|
|
"id in ($v_id,$color_id,$incolor_id)" => null
|
|
];
|
|
$attr_row = $this->auto_attr_model->map('id','',$where);
|
|
if($attr_row[$color_id]){
|
|
$color_row = $attr_row[$color_id][0];
|
|
$color_row['jsondata'] = json_decode($color_row['jsondata'],true);
|
|
}
|
|
if($attr_row[$incolor_id]){
|
|
$incolor_row = $attr_row[$incolor_id][0];
|
|
$incolor_row['jsondata'] = json_decode($incolor_row['jsondata'],true);
|
|
}
|
|
if($attr_row[$v_id]){
|
|
$version_row = $attr_row[$v_id][0];
|
|
$version_row['jsondata'] = json_decode($version_row['jsondata'],true);
|
|
}
|
|
$car_json = [
|
|
'c_id' => $color_id,
|
|
'inc_id' => $incolor_id,
|
|
'v_id' => $v_id,
|
|
'color' => isset($color_row) ? $color_row : '',
|
|
'incolor' => isset($incolor_row) ? $incolor_row : '',
|
|
'version' => isset($version_row) ? $version_row : ''
|
|
];
|
|
|
|
$data = [
|
|
'rid' => $cus_id,
|
|
'sid' => create_order_no(350200,$this->app_key),
|
|
'name' => $name ? $name : $row['name'],
|
|
'mobile' => $mobile ? $mobile : $row['mobile'],
|
|
'biz_id' => $this->session['biz_id'],
|
|
'brand_id' => $series_row['brand_id'],
|
|
's_id' => $series_row['id'],
|
|
'v_id' => $v_id,
|
|
'cor_id' => $color_id,
|
|
'incor_id' => $incolor_id,
|
|
'admin_id' => $this->session['uid'],
|
|
'car_json' => json_encode($car_json,JSON_UNESCAPED_UNICODE),
|
|
'price' => $price,
|
|
'deposit' => $deposit,
|
|
'c_time' => time()
|
|
];
|
|
$payway && $data['payway'] = 1;
|
|
$pack_id && $data['pack_id'] = $pack_id;
|
|
$main_type && $data['main_type'] = 1;
|
|
$info_json = [];
|
|
if($ifentrust){
|
|
$data['ifentrust'] = 1;
|
|
$info_json['entrust_name'] = $entrust_name;
|
|
$info_json['entrust_idcard'] = $entrust_idcard;
|
|
}
|
|
$cardid && $info_json['c_cardid'] = $cardid;
|
|
$address && $info_json['c_address'] = $address;
|
|
$info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE);
|
|
$o_id = $this->orders_model->add($data);
|
|
if($o_id){
|
|
$sign_data = [
|
|
'o_id' => $o_id,
|
|
'c_time' => time()
|
|
];
|
|
$this->order_signs_model->add($sign_data);
|
|
return ['id'=>$o_id];
|
|
}else{
|
|
throw new Exception('创建失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
//修改订单信息
|
|
protected function put(){
|
|
$id = $this->input_param('id');
|
|
$payway = $this->input_param('payway');
|
|
$pack_id = $this->input_param('pack_id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
throw new Exception('订单不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
$result = false;
|
|
$up_data = [];
|
|
|
|
if(strlen($payway)|| $pack_id){
|
|
if($row['status']>0){
|
|
throw new Exception('修改失败,已签订合同', ERR_PARAMS_ERROR);
|
|
}
|
|
strlen($payway) && $up_data['payway'] = $payway;
|
|
$pack_id && $up_data['pack_id'] = $pack_id;
|
|
}
|
|
if($up_data){
|
|
$result = $this->orders_model->update($up_data,['id'=>$id]);
|
|
}
|
|
|
|
if($result){
|
|
throw new Exception('修改成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('修改失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
//订单列表头部
|
|
protected function get_tabs(){
|
|
$rows = $this->orders_model->get_status();
|
|
$lists = [];
|
|
if($rows){
|
|
foreach($rows as $key=>$val){
|
|
$lists[] = [
|
|
'key' => $key,
|
|
'name' => $val
|
|
];
|
|
}
|
|
}
|
|
return $lists;
|
|
}
|
|
|
|
|
|
|
|
//订单列表
|
|
private function lists(){
|
|
$group_id = $this->session['group_id'];
|
|
$uid = $this->session['uid'];
|
|
$biz_id = $this->session['biz_id'];
|
|
$keyword = $this->input_param('keyword');
|
|
$status = $this->input_param('status');
|
|
$ismy = $this->input_param('ismy'); //是否只显示自己
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
|
|
$where = [
|
|
'biz_id' => $biz_id
|
|
];
|
|
|
|
if($group_id==1 || $ismy){ //销售
|
|
$where ["admin_id"] = $uid;
|
|
}
|
|
|
|
if($keyword){
|
|
$where["(name='{$keyword}' or mobile='{$keyword}')"] = null;
|
|
}
|
|
strlen($status) && $where['status'] = $status;
|
|
$fileds = 'id,name,mobile,car_json,brand_id,s_id,deposit,payway,status,c_time';
|
|
$count = $this->orders_model->count($where);
|
|
$lists = [];
|
|
if($count){
|
|
$rows = $this->orders_model->select($where,'id desc',$page,$size,$fileds);
|
|
|
|
//品牌车型
|
|
$brand_arr = array_unique(array_column($rows,'brand_id'));
|
|
$brands = $this->auto_brand_model->get_map_by_ids($brand_arr,'id,name');
|
|
//车系车型
|
|
$series_arr = array_unique(array_column($rows,'s_id'));
|
|
$series = $this->auto_series_model->get_map_by_ids($series_arr,'id,name');
|
|
|
|
$status_arr = $this->orders_model->get_status();
|
|
foreach($rows as $key=>$val){
|
|
|
|
$car_json = json_decode($val['car_json'],true);
|
|
$color = isset($car_json['color']) ? $car_json['color']['title'] : '';
|
|
$version = isset($car_json['version']) ? $car_json['version']['title'] : '';
|
|
|
|
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
|
|
$serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
|
|
|
|
$other_data = [
|
|
'品牌车型' => "{$brand_name}{$serie_name}-{$color}-{$version}",
|
|
'付款方式' => $val['payway']?'全款':'分期',
|
|
'代办车牌' => '需要',
|
|
'定金金额' => $val['deposit'],
|
|
'订单日期' => date('Y-m-d',$val['c_time']),
|
|
];
|
|
$lists[] = [
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'mobile' => mobile_asterisk($val['mobile']),
|
|
'status_name' => $status_arr[$val['status']],
|
|
'other_data' => $other_data,
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
//订单详情
|
|
private function detail($id){
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
throw new Exception('订单不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$car_json = json_decode($row['car_json'],true);
|
|
$color = isset($car_json['color']) ? $car_json['color']['title'] : '';
|
|
$version = isset($car_json['version']) ? $car_json['version']['title'] : '';
|
|
|
|
//贷款信息
|
|
$loan_data = [];
|
|
$loan_status = 0;
|
|
if(!$row['payway'] && $row['status']>=1){
|
|
$this->load->model('receiver/order/receiver_order_loans_model','order_loans_model');
|
|
$loan = $this->order_loans_model->get(['o_id'=>$row['id']]);
|
|
if($loan){
|
|
$loan_data = [
|
|
'id' => $loan['id'],
|
|
'bank' => $loan['title'],
|
|
'year' => $loan['year'],
|
|
'money' => $loan['first_price']
|
|
];
|
|
}
|
|
$loan_status = $loan['status']>0 ? 2 : 1;
|
|
}
|
|
$pack_title = '';
|
|
if($row['pack_id']){
|
|
$pack_row = $this->package_model->get(['id'=>$row['pack_id']]);
|
|
$srv_rows = '';
|
|
$pack_row['srv_ids'] && $srv_rows = $this->services_model->select(["id in ({$pack_row['srv_ids']})"=>null],'','','','title');
|
|
$srv_rows && $pack_title = implode('+',array_column($srv_rows,'title'));
|
|
}
|
|
$car_data = [
|
|
'车辆名称' => $brand['name'].$series['name'],
|
|
'车辆级别' => $version,
|
|
'颜色' => $color,
|
|
'车辆合同售价' => $row['price'],
|
|
'定金' => $row['deposit'],
|
|
'代办包' => $pack_title,
|
|
'购车主体' => $row['main_type'] ? '公司' : '个人',
|
|
'是否委托' => $row['ifentrust'] ? '是' : '否',
|
|
];
|
|
$info_json = json_decode($row['info_json'],true);
|
|
if($row['ifentrust']){
|
|
$car_data['委托人姓名'] = $info_json['entrust_name'] ? $info_json['entrust_name'] : '';
|
|
$car_data['委托人身份证'] = $info_json['entrust_idcard'] ? $info_json['entrust_idcard'] : '';
|
|
}
|
|
$info_json['c_address'] && $car_data['地址'] = $info_json['c_address'];
|
|
$info_json['c_cardid'] && $car_data['身份证号'] = $info_json['c_cardid'];
|
|
//开票信息
|
|
$bill_status = 0;
|
|
$bill_data = [];
|
|
if($row['status']>=3){
|
|
$bill = $this->order_bills_model->get(['o_id'=>$row['id']]);
|
|
if($bill){
|
|
$bill_data = [
|
|
'id' => $bill['id'],
|
|
'carid_a' => $bill['cardidA'] ? build_qiniu_image_url($bill['cardidA']) : '',
|
|
'carid_a_path' => $bill['cardidA'] ? $bill['cardidA'] : '',
|
|
'carid_b' => $bill['cardidB'] ? build_qiniu_image_url($bill['cardidB']) : '',
|
|
'carid_b_path' => $bill['cardidB'] ? $bill['cardidB'] : '',
|
|
'bill_img' => $bill['file'] ? build_qiniu_image_url($bill['file']) : ''
|
|
];
|
|
}
|
|
$bill_status = $bill['status'] ? 2 : 1;
|
|
}
|
|
//确认车辆状态
|
|
$delivery = $this->order_deliverys_model->get(['o_id'=>$row['id']],'status');
|
|
$ckcar_status = 0;
|
|
if($row['status']==5&&$delivery['status']==1){
|
|
$ckcar_status = 1;
|
|
}
|
|
$data = [
|
|
'id' => $id,
|
|
'name' => $row['name'],
|
|
'mobile' => mobile_asterisk($row['mobile']),
|
|
'admin_img' => 'https://img.liche.cn/liche/2021/08/7725fc9ab0dc0ba1/f3c84cf3b805bac4.png',
|
|
'payway' => $row['payway'],
|
|
'car_data' => $car_data,
|
|
'loan_status' => $loan_status,
|
|
'loan_data' => $loan_data,
|
|
'bill_status' => $bill_status,
|
|
'bill_data' => $bill_data,
|
|
'ckcar_status' => $ckcar_status,
|
|
'pack_id' => $row['pack_id']
|
|
];
|
|
return $data;
|
|
}
|
|
//确认交付
|
|
protected function put_ckcar(){
|
|
$id = $this->input_param('id');
|
|
$row = $this->order_deliverys_model->get(['o_id'=>$id]);
|
|
if($row['status']!=1){
|
|
throw new Exception('当前不可修改', ERR_PARAMS_ERROR);
|
|
}
|
|
$result = $this->order_deliverys_model->update(['status'=>2],['id'=>$row['id']]);
|
|
if($result){
|
|
$this->orders_model->update(['status'=>6],['id'=>$row['o_id']]);
|
|
//完成支付订单
|
|
$this->load->library('receiver/orders_entity');
|
|
$this->orders_entity->finish_after($row['o_id'],1);
|
|
throw new Exception('修改成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('修改失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
}
|