265 lines
12 KiB
PHP
265 lines
12 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/06/25
|
|
* Time: 20:55
|
|
*/
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
class Order extends Wxapp{
|
|
private $type_array = [
|
|
3 => '定金',
|
|
4 => '定金',
|
|
5 => '委托服务费',
|
|
6 => '尾款',
|
|
];
|
|
public function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->uid = $this->session['uid'];
|
|
$this->load->model('apporder/order_purchase_model');
|
|
$this->load->model('receiver/order/receiver_orders_model');
|
|
$this->load->model('receiver/order/receiver_orders_v2_model');
|
|
$this->load->model('receiver/order/receiver_order_contracts_model');
|
|
$this->load->model('receiver/order/receiver_order_status_model');
|
|
$this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_model');
|
|
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
|
|
$this->load->model('app/liche/app_liche_orders_model');
|
|
$this->load->library('receiver/orders_v2_entity');
|
|
}
|
|
|
|
/**
|
|
* Notes:我的订单
|
|
*/
|
|
protected function get_mine(){
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
$type = $this->input_param('type');
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
$where = [
|
|
'app_id' => $this->app_id,
|
|
'app_uid' => $this->uid
|
|
];
|
|
if($type){
|
|
$where['status'] = $type;
|
|
$type == 1 && $where['status_detail'] = 11;
|
|
}
|
|
$fileds = 'id,sid,item_title,total_price,jsondata,status,status_detail,type';
|
|
$rows = $this->order_purchase_model->select($where,'id desc',$page,$size,$fileds);
|
|
$total = $this->order_purchase_model->count($where);
|
|
$list = [];
|
|
if($rows){
|
|
foreach($rows as $key=>$val){
|
|
$jsondata = json_decode($val['jsondata'],true);
|
|
$car = $jsondata['car'];
|
|
if($val['status']>1){ //已支付
|
|
$status = 2;
|
|
$btn = [
|
|
'text' => '已支付',
|
|
'color' => '#ccc'
|
|
];
|
|
}else{ //未支付
|
|
if($val['status']=1 && $val['status_detail']!=11){
|
|
$status = 2;
|
|
$btn = [
|
|
'text' => '已过期',
|
|
'color' => '#ccc'
|
|
];
|
|
}else{
|
|
$status = 1;
|
|
$btn = [
|
|
'text' => '去支付',
|
|
'color' => '#1a1a1a'
|
|
];
|
|
}
|
|
}
|
|
$type_name = '金额';
|
|
if($this->type_array[$val['type']]){
|
|
//if($val['type']==6){
|
|
// $r_order = $this->receiver_orders_model->get(['id'=>$cf_id],'payway');
|
|
// $type_name = $r_order['payway'] ? '尾款' : '首付';
|
|
//}else{
|
|
$type_name = $this->type_array[$val['type']];
|
|
//}
|
|
}
|
|
$list[] = [
|
|
'id' => $val['id'],
|
|
'sid' => $val['sid'],
|
|
'cover' => $jsondata['cover'] ? build_qiniu_image_url($jsondata['cover']) : '',
|
|
'type_name' => $type_name,
|
|
'title' => $val['item_title'],
|
|
'price' => $val['total_price'],
|
|
'color' => isset($car['color']['jsondata']['title']) ? $car['color']['jsondata']['title'] : "",
|
|
'version' => isset($car['version']['jsondata']['title']) ? $car['version']['jsondata']['title'] : "",
|
|
'status' => $status,
|
|
'btn' => $btn
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $list,
|
|
'total' => $total
|
|
];
|
|
if ($page == 1) {
|
|
$data['tab'] = [
|
|
["value" => 0, 'title' => '全部'],
|
|
["value" => 1, 'title' => '待支付'],
|
|
["value" => 2, 'title' => '进行中'],
|
|
["value" => 3, 'title' => '已完成'],
|
|
];
|
|
}
|
|
return $data;
|
|
}
|
|
//购车订单
|
|
protected function get_cars(){
|
|
$uid = $this->session['uid'];
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
$oid = $this->input_param('oid');
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
|
|
$list = [];
|
|
$where = [
|
|
"(uid = {$uid} or entrust_uid={$uid})" => null,
|
|
'pid' => 0,
|
|
'status>=' => 0,
|
|
'type <>' => 5
|
|
];
|
|
$oid && $where['o_id'] = $oid;
|
|
$total = $this->app_liche_orders_model->count($where);
|
|
if($total){
|
|
$fileds = 'id,o_id,sid,brand_id,s_id,v_id,cor_id,incor_id,c_time';
|
|
$rows = $this->app_liche_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');
|
|
//获取车辆属性
|
|
$v_id_arr = array_column($rows,'v_id');
|
|
$cor_id_arr = array_column($rows,'cor_id');
|
|
$incor_id_arr = array_column($rows,'incor_id');
|
|
$attr_id_arr = array_unique(array_merge($v_id_arr,$cor_id_arr,$incor_id_arr));
|
|
$attrs = $this->auto_attr_model->get_map_by_ids($attr_id_arr,'id,title,jsondata');
|
|
|
|
$type_arr = $this->app_liche_orders_model->get_type_arr();
|
|
$contract_type_arr = $this->receiver_order_contracts_model->get_types(1);
|
|
foreach($rows as $key=>$val){
|
|
$owner_name = '';
|
|
if($val['o_id']>=Orders_v2_entity::V2_START_ID){
|
|
$order = $this->receiver_orders_v2_model->get(['id'=>$val['o_id']],'owner_name,main_type,id,payway,brand_id,s_id,sid,v_id,cor_id,money_json,info_json');
|
|
$info_json = json_decode($order['info_json'],true);
|
|
$owner_name = $order['main_type'] ? $info_json['c_company'] : $order['owner_name'];
|
|
}else{
|
|
$order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'payway,price,brand_id,s_id,sid,v_id,cor_id,money_json');
|
|
}
|
|
$select_car = false;
|
|
if($order['brand_id'] && $order['s_id'] && $order['cor_id']){
|
|
$select_car = true;
|
|
}
|
|
$brand_name = $brands[$val['brand_id']] ? $brands[$val['brand_id']][0]['name'] : '';
|
|
$serie_name = $series[$val['s_id']] ? $series[$val['s_id']][0]['name'] : '';
|
|
$info['车辆级别'] = $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '';
|
|
$info['车身颜色'] = $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '';
|
|
$info['内饰颜色'] = $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'] : '';
|
|
$cover = '';
|
|
if($attrs[$val['cor_id']]){
|
|
$jsondata = json_decode($attrs[$val['cor_id']][0]['jsondata'],true);
|
|
$cover = build_qiniu_image_url($jsondata['img']);
|
|
}
|
|
//获取子订单
|
|
$sub_rows = $this->app_liche_orders_model->select(['pid'=>$val['id'],'status>='=>0],'id asc',0,0,'id,sid,total_price,pay_time,type,status');
|
|
$sub_order = [];
|
|
if($sub_rows){
|
|
foreach($sub_rows as $k => $v){
|
|
$setValue = [
|
|
'sid' => $v['sid'],
|
|
'price' => $v['total_price'],
|
|
'type_cn' => $type_arr[$v['type']],
|
|
'status' => $v['status'],
|
|
'type' => $v['type'],
|
|
];
|
|
$v['pay_time'] != '0000-00-00 00:00:00' && $setValue['pay_time'] = $v['pay_time'];
|
|
//尾款子订单
|
|
if($v['type']==3){
|
|
$last_orders = [];
|
|
$last_rows = $this->app_liche_orders_model->select(['pid'=>$v['id'],'status'=>1],'id asc',0,0,'total_price,pay_time');
|
|
$pay_price = 0; //已支付金额
|
|
foreach($last_rows as $v2){
|
|
$pay_price += $v2['total_price'];
|
|
$last_orders[] = [
|
|
'price' => $v2['total_price'],
|
|
'pay_time' => $v2['pay_time'],
|
|
'pay_cn' => '支付'
|
|
];
|
|
}
|
|
$setValue['no_pay_price'] = $v['total_price'] - $pay_price;
|
|
$setValue['sub_order'] = $last_orders;
|
|
}
|
|
$sub_order[] = $setValue;
|
|
}
|
|
}
|
|
$agree = $this->receiver_order_contracts_model->count(['o_id'=>$val['o_id'],'status'=>1]) ? true : false;
|
|
$contract_list = [];
|
|
if($agree){
|
|
$contracts = $this->receiver_order_contracts_model->select(['o_id'=>$val['o_id'],'status'=>1],'','','','id,type,file');
|
|
foreach ($contracts as $item) {
|
|
$contract_list[] = [
|
|
'title' => $contract_type_arr[$item['type']],
|
|
'url' => http_host_com('api').'/wxapp/licheb/protocol/pdf_img?id='.$item['id']
|
|
];
|
|
}
|
|
}
|
|
$ckcar_status = false;
|
|
$agent_ck = $this->receiver_order_status_model->count(['o_id'=>$val['o_id'],'status'=>1,'pid_status'=>4]);
|
|
$user_ck = $this->receiver_order_status_model->count(['o_id'=>$val['o_id'],'status'=>2,'pid_status'=>4]);
|
|
if($agent_ck && !$user_ck){
|
|
$ckcar_status = true;
|
|
}
|
|
//获取随车信息
|
|
$delivery = $this->order_deliverys_model->get(['o_id'=>$val['o_id']],'status,info,tool,remark');
|
|
$ckcar_data = [
|
|
'info' => $delivery['info'] ? explode(',',$delivery['info']) : [],
|
|
'tool' => $delivery['tool'] ? explode(',',$delivery['tool']) : [],
|
|
'remark' => $delivery['remark'] ? $delivery['remark'] : ''
|
|
];
|
|
$list[] = [
|
|
'oid' => $order['id'],
|
|
'title' => $brand_name.$serie_name,
|
|
'owner_name' => $owner_name,
|
|
'cover' => $cover,
|
|
'price' => $this->orders_v2_entity->total_price($order['id']),
|
|
'sid' => $order['sid'],
|
|
'payway' => $order['payway'],
|
|
'type' => $select_car,
|
|
'info' => $info,
|
|
'sub_order' => $sub_order,
|
|
'agree' => $agree,
|
|
'ckcar_status' => $ckcar_status, //是否显示确认车辆
|
|
'version' => $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '',
|
|
'color' => $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '',
|
|
'in_color' => $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'].'内饰' : '',
|
|
'contract_list' => $contract_list,
|
|
'ckcar_data' => $ckcar_data,
|
|
'c_time' => date('Y-m-d H:i:s',$val['c_time'])
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $list,
|
|
'total' => $total
|
|
];
|
|
return $data;
|
|
}
|
|
}
|