272 lines
9.4 KiB
PHP
272 lines
9.4 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('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');
|
|
$v_id = $this->input_param('v_id');
|
|
$price = $this->input_param('price');
|
|
$deposit = $this->input_param('deposit');
|
|
$payway = $this->input_param('payway');
|
|
|
|
$order = $this->orders_model->get(['rid'=>$cus_id]);
|
|
if($order){
|
|
throw new Exception('该客户订单已存在', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
|
|
if(!$row || !$series_row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$where = [
|
|
"id in ($v_id,$color_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[$v_id]){
|
|
$version_row = $attr_row[$v_id][0];
|
|
$version_row['jsondata'] = json_decode($version_row['jsondata'],true);
|
|
}
|
|
$car_json = [
|
|
'c_id' => $color_id,
|
|
'v_id' => $v_id,
|
|
'color' => isset($color_row) ? $color_row : '',
|
|
'version' => isset($version_row) ? $version_row : ''
|
|
];
|
|
|
|
$data = [
|
|
'rid' => $cus_id,
|
|
'sid' => create_order_no(350200,$this->app_key),
|
|
'name' => $row['name'],
|
|
'mobile' => $row['mobile'],
|
|
'brand_id' => $series_row['brand_id'],
|
|
's_id' => $series_row['id'],
|
|
'v_id' => $v_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;
|
|
$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');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
throw new Exception('订单不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
$result = false;
|
|
$up_data = [];
|
|
|
|
if(strlen($payway)){
|
|
if($row['status']>0){
|
|
throw new Exception('修改失败,已签订合同', ERR_PARAMS_ERROR);
|
|
}
|
|
$up_data['payway'] = $payway;
|
|
}
|
|
|
|
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'];
|
|
$keyword = $this->input_param('keyword');
|
|
$status = $this->input_param('status');
|
|
|
|
if($group_id==3){ //掌柜
|
|
$where = [];
|
|
}elseif($group_id==2){ //店长
|
|
$sub_user = $this->app_user_model->select(['pid'=>$uid],'','','','id');
|
|
$ids_arr = array_column($sub_user,'id');
|
|
$ids_arr[] = $uid;
|
|
$ids = implode(',',$ids_arr);
|
|
$where = [
|
|
"admin_id in ($ids)" => null
|
|
];
|
|
}else{ //销售
|
|
$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,if_cnum,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'));
|
|
$brand_ids = implode(',',$brand_arr);
|
|
if($brand_ids){
|
|
$where = [
|
|
"id in ({$brand_ids})" => null
|
|
];
|
|
$brands = $this->auto_brand_model->map('id','',$where,'','','','id,name');
|
|
}
|
|
//车系车型
|
|
$series_arr = array_unique(array_column($rows,'s_id'));
|
|
$series_ids = implode(',',$series_arr);
|
|
if($series_ids){
|
|
$where = [
|
|
"id in ({$series_ids})" => null
|
|
];
|
|
$series = $this->auto_series_model->map('id','',$where,'','','','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['if_cnum']?'需要':'不需要',
|
|
'定金金额' => $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 = [];
|
|
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']]);
|
|
}
|
|
|
|
$car_data = [
|
|
'车辆名称' => $brand['name'].$series['name'],
|
|
'车辆级别' => $version,
|
|
'颜色' => $color,
|
|
'车辆指导价格' => $row['price'],
|
|
'定金' => $row['deposit']
|
|
];
|
|
$data = [
|
|
'id' => $id,
|
|
'name' => $row['name'],
|
|
'mobile' => mobile_asterisk($row['mobile']),
|
|
'payway' => $row['payway'],
|
|
'car_data' => $car_data,
|
|
'loan_data' => $loan_data
|
|
];
|
|
return $data;
|
|
}
|
|
}
|