Files
liche/api/controllers/wxapp/liche/Order.php
T
2021-12-16 09:34:18 +08:00

218 lines
9.3 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('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');
}
/**
* 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';
$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();
foreach($rows as $key=>$val){
$order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'payway,price,brand_id,s_id,v_id,cor_id,money_json');
$money_json = json_decode($order['money_json'],true);
$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');
foreach($last_rows as $v2){
$last_orders[] = [
'price' => $v2['total_price'],
'pay_time' => $v2['pay_time'],
'pay_cn' => $v2['total_price'] == $v['total_price'] ? '全部支付' : '部分支付'
];
}
$is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'uid'=>$uid,'pid'=>$v['id']]); //已支付金额
$setValue['no_pay_price'] = $v['total_price'] - $is_pay['total_price'];
$setValue['sub_order'] = $last_orders;
}
$sub_order[] = $setValue;
}
}
$list[] = [
'title' => $brand_name.$serie_name,
'cover' => $cover,
'price' => $money_json['price_discount'] ? $money_json['price_car'] - $money_json['price_discount'] : $money_json['price_car'],
'sid' => $val['sid'],
'payway' => $order['payway'],
'type' => $select_car,
'info' => $info,
'sub_order' => $sub_order,
];
}
}
$data = [
'list' => $list,
'total' => $total
];
return $data;
}
}