774 lines
39 KiB
PHP
774 lines
39 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 CusorderV2 extends Wxapp{
|
|
|
|
private $biz_id = '';
|
|
|
|
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');
|
|
$this->load->model('receiver/order/receiver_orders_v2_model','orders_model');
|
|
$this->load->model('receiver/order/receiver_order_datas_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('receiver/order/receiver_order_loans_model', 'order_loans_model');
|
|
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
$this->load->model('auto/auto_cars_model');
|
|
$this->load->model('auto/auto_business_model');
|
|
|
|
$this->load->model("biz/biz_model");
|
|
$this->load->model('sys/sys_finance_model');
|
|
$this->load->model('sys/sys_city_model');
|
|
|
|
$this->load->model('app/liche/app_liche_users_model');
|
|
$this->load->model('app/liche/app_liche_orders_model');
|
|
|
|
$this->load->library('receiver/orders_entity');
|
|
$this->load->library('receiver/orders_v2_entity');
|
|
$this->load->library('receiver/customers_entity');
|
|
$this->load->library('receiver/order_datas_entity');
|
|
$this->load->library('receiver/orders_status_entity');
|
|
$this->biz_id = $this->get_biz_id();
|
|
}
|
|
|
|
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');
|
|
$deposit = $this->input_param('deposit');
|
|
$payway = $this->input_param('payway');
|
|
$main_type = $this->input_param('main_type');
|
|
$name = trim($this->input_param('name'));
|
|
$mobile = trim($this->input_param('mobile'));
|
|
$cardid = trim($this->input_param('cardid'));
|
|
$owner_name = trim($this->input_param('owner_name'));
|
|
$owner_mobile = trim($this->input_param('owner_mobile'));
|
|
$owner_cardid = trim($this->input_param('owner_cardid'));
|
|
$company = $this->input_param('company');
|
|
$c_credit = $this->input_param('credit');
|
|
$delry_time = $this->input_param('delry_time');
|
|
$finance_id = $this->input_param('finance_id');
|
|
$inten_money = floatval($this->input_param('inten_money'));//意向金
|
|
$disc_money = floatval($this->input_param('disc_money'));//优惠金额
|
|
$disc_fine_money = floatval($this->input_param('disc_fine_money'));//精品优惠金额
|
|
$if_fine = $this->input_param('if_fine');
|
|
$srv_arr = $this->input_param('srv_arr');
|
|
$fines = $this->input_param('fines');
|
|
$address = $this->input_param('address');
|
|
$business_id = $this->input_param('business_id'); //商务政策id
|
|
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
|
|
$business_row = $this->auto_business_model->get(['id'=>$business_id]);
|
|
if(!$row || !$series_row ||!$delry_time || !$name || !$mobile || !$business_row || !$deposit){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if($main_type){//公司
|
|
if(!$company || !$c_credit){
|
|
throw new Exception('请填写公司信息', ERR_PARAMS_ERROR);
|
|
}
|
|
}else{ //个人
|
|
if(!$cardid || !$owner_name || !$owner_mobile || !$owner_cardid){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
if($deposit<2000){
|
|
throw new Exception('定金不得少于2000', ERR_PARAMS_ERROR);
|
|
}
|
|
if($inten_money > $deposit){
|
|
throw new Exception('意向金不得高于定金', ERR_PARAMS_ERROR);
|
|
}
|
|
$biz = $this->biz_model->get(['id'=>$row['biz_id']],'city_id,type');
|
|
|
|
$car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id],'',$biz['city_id']);
|
|
if(!$car_row){
|
|
throw new Exception('参数错误', API_CODE_FAIL);
|
|
}
|
|
$can_dis_money = $business_row['price_car'] - $business_row['price_floor']; //可优惠金额
|
|
if($can_dis_money>0){
|
|
if($disc_money && $business_row['price_floor'] > $business_row['price_car']-$disc_money){
|
|
throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL);
|
|
}
|
|
}else{
|
|
if($disc_money) throw new Exception('当前车型没有优惠额度', API_CODE_FAIL);
|
|
}
|
|
if(!$payway && $finance_id){ //分期
|
|
$finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]);
|
|
if(!$finance_row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'clue_id' => $cus_id,
|
|
'sid' => create_order_no(350200,$this->app_key),
|
|
'customer_id' => $row['id'],
|
|
'name' => $name ? $name : $row['name'],
|
|
'mobile' => $mobile ? $mobile : $row['mobile'],
|
|
'biz_id' => $this->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,
|
|
'sale_id' => $this->session['uid'],
|
|
'c_time' => time()
|
|
];
|
|
$owner_name && $data['owner_name'] = $owner_name;
|
|
$owner_mobile && $data['owner_mobile'] = $owner_mobile;
|
|
$row['rid'] && $data['clue_id'] = $row['rid'];
|
|
$payway && $data['payway'] = 1;
|
|
$if_fine && $data['if_fine'] = 1;
|
|
$main_type && $data['main_type'] = 1;
|
|
$delry_time && $data['delry_time'] = $delry_time;
|
|
$fines && $data['fines'] = json_encode($fines,JSON_UNESCAPED_UNICODE);
|
|
$info_json = [];
|
|
$address && $info_json['c_address'] = $address;
|
|
$cardid && $info_json['c_cardid'] = $cardid;
|
|
$owner_cardid && $info_json['c_owner_cardid'] = $owner_cardid;
|
|
$c_credit && $info_json['c_credit'] = $c_credit;
|
|
$company && $info_json['c_company'] = $company;
|
|
$business_id && $info_json['business_id'] = $business_id;
|
|
$info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE);
|
|
$finance_row && $data['finance_id'] = $finance_row['id'];
|
|
|
|
//获取金额json数据
|
|
$orders_entity = new orders_v2_entity();
|
|
$color_arr = json_decode($business_row['colors'],true);
|
|
$price_color = in_array($color_id,$color_arr) ? $business_row['price_color'] : 0;
|
|
$price_coplus = $main_type ? $business_row['price_coplus'] : 0;
|
|
|
|
$money_json = [
|
|
'price_car' => $business_row['price_car'],
|
|
'price_book' => $deposit ? $deposit : 0,
|
|
'price_insure' => $car_row['price_insure'],
|
|
'price_fine' => $car_row['price_fine'],
|
|
'price_discount' =>$disc_money ? $disc_money : 0,
|
|
'price_intention' => $inten_money ? $inten_money : 0,
|
|
'price_finance' => $series_row['brand_id'] == 4 ? $orders_entity::PRICE_FINANCE_NZ : $orders_entity::PRICE_FINANCE,
|
|
'price_fine_discount' => $disc_fine_money ? $disc_fine_money : 0,
|
|
'price_fine_select' => 0,
|
|
'price_color' => $price_color,
|
|
'price_coplus' => $price_coplus,
|
|
];
|
|
if($srv_arr){
|
|
foreach ($srv_arr as $item) {
|
|
$money_json[$item['key']] = $item['price'];
|
|
$item['id'] == 1 && $data['if_insure'] = 1;
|
|
$item['id'] == 2 && $data['if_num'] = 1;
|
|
}
|
|
}
|
|
$data['srv_ids'] = $srv_arr ? json_encode($srv_arr,JSON_UNESCAPED_UNICODE) : "";
|
|
if($fines){
|
|
foreach ($fines as $item) {
|
|
if($item['price']){
|
|
$money_json['price_fine_select'] += $item['price'];
|
|
}
|
|
}
|
|
}
|
|
$data['car_json'] = $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
|
|
$o_id = $this->orders_model->add($data);
|
|
if($o_id){
|
|
//意向金订单
|
|
$userinfo = $this->app_liche_users_model->get(['mobile'=>$mobile],'id');
|
|
if($inten_money){
|
|
$this->orders_v2_entity->c_intention($o_id,$userinfo['id'],$inten_money);
|
|
}
|
|
$this->orders_v2_entity->add_book_order($o_id,$userinfo['id']);
|
|
if($payway){ //全款服务费和尾款订单
|
|
$this->orders_v2_entity->add_order($o_id,$userinfo['id']);
|
|
}
|
|
//更新客户下单时间
|
|
$this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]);
|
|
$this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单");
|
|
|
|
return ['id'=>$o_id,'pay_img'=>$orders_entity::API_PAY_IMG];
|
|
}else{
|
|
throw new Exception('创建失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
//创建意向金订单
|
|
protected function post_inten(){
|
|
$cus_id = $this->input_param('cus_id');
|
|
$name = $this->input_param('name');
|
|
$mobile = $this->input_param('mobile');
|
|
$cardid = $this->input_param('cardid');
|
|
$owner_name = $this->input_param('owner_name');
|
|
$owner_mobile = $this->input_param('owner_mobile');
|
|
$owner_cardid = $this->input_param('owner_cardid');
|
|
$main_type = $this->input_param('main_type');
|
|
$company = $this->input_param('company');
|
|
$c_credit = $this->input_param('credit');
|
|
|
|
$inten_money = floatval($this->input_param('inten_money'));//意向金
|
|
|
|
if(!$name || !$mobile|| !$inten_money){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if($main_type){
|
|
if(!$company || !$c_credit){
|
|
throw new Exception('请填写公司信息', ERR_PARAMS_ERROR);
|
|
}
|
|
}else{
|
|
if( !$cardid || !$owner_name || !$owner_mobile || !$owner_cardid){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
if($inten_money > 2000){
|
|
throw new Exception('意向金不得高于2000', ERR_PARAMS_ERROR);
|
|
}
|
|
$data = [
|
|
'customer_id' => $cus_id,
|
|
'sid' => create_order_no(350200,$this->app_key),
|
|
'name' => $name ? $name : $row['name'],
|
|
'mobile' => $mobile ? $mobile : $row['mobile'],
|
|
'biz_id' => $this->biz_id,
|
|
'sale_id' => $this->session['uid'],
|
|
'c_time' => time()
|
|
];
|
|
$main_type && $data['main_type'] = 1;
|
|
$owner_name && $data['owner_name'] = $owner_name;
|
|
$owner_mobile && $data['owner_mobile'] = $owner_mobile;
|
|
$info_json = [];
|
|
$cardid && $info_json['c_cardid'] = $cardid;
|
|
$owner_cardid && $info_json['c_owner_cardid'] = $owner_cardid;
|
|
$company && $info_json['c_company'] = $company;
|
|
$c_credit && $info_json['c_credit'] = $c_credit;
|
|
$info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE);
|
|
//获取挂牌价
|
|
$biz = $this->biz_model->get(['id'=>$row['biz_id']],'city_id');
|
|
|
|
$city = $this->sys_city_model->get(['city_id'=>$biz['city_id']],'fee_carno');
|
|
$money_json['fee_carno'] = $city['fee_carno'];
|
|
$money_json['price_intention'] = $inten_money ? $inten_money : 0;
|
|
$data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
|
|
|
|
$row['rid'] && $data['clue_id'] = $row['rid'];
|
|
$o_id = $this->orders_model->add($data);
|
|
if(!$o_id){
|
|
throw new Exception('创建失败', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
//更新客户下单时间
|
|
$this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]);
|
|
$this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单");
|
|
|
|
//意向金订单
|
|
$orders_entity = new orders_v2_entity();
|
|
if($inten_money){
|
|
$userinfo = $this->app_liche_users_model->get(['mobile'=>$data['mobile']],'id');
|
|
$orders_entity->c_intention($o_id,$userinfo['id'],$inten_money);
|
|
}
|
|
return ['id'=>$o_id,'pay_img'=>$orders_entity::API_PAY_IMG];
|
|
}
|
|
|
|
//修改订单信息
|
|
protected function put(){
|
|
$id = $this->input_param('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');
|
|
$payway = $this->input_param('payway');
|
|
$main_type = $this->input_param('main_type');
|
|
$delry_time = $this->input_param('delry_time');
|
|
$finance_id = $this->input_param('finance_id');
|
|
$deposit = $this->input_param('deposit');
|
|
$disc_money = floatval($this->input_param('disc_money'));//优惠金额
|
|
$disc_fine_money = floatval($this->input_param('disc_fine_money'));//精品优惠金额
|
|
$if_fine = $this->input_param('if_fine');
|
|
$srv_arr = $this->input_param('srv_arr');
|
|
$fines = $this->input_param('fines');
|
|
$business_id = $this->input_param('business_id'); //商务政策id
|
|
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
|
|
$biz = $this->biz_model->get(['id'=>$row['biz_id']],'type,city_id');
|
|
$car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id],'',$biz['city_id']);
|
|
$business_row = $this->auto_business_model->get(['id'=>$business_id]);
|
|
if(!$row || !$series_row || !$car_row || !$business_row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if($deposit<2000){
|
|
throw new Exception('定金不得少于2000', ERR_PARAMS_ERROR);
|
|
}
|
|
$can_dis_money = $car_row['price_car'] - $car_row['price_floor']; //可优惠金额
|
|
if($can_dis_money>0){
|
|
if($disc_money && $car_row['price_floor'] > $car_row['price_car']-$disc_money){
|
|
throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL);
|
|
}
|
|
}else{
|
|
if($disc_money) throw new Exception('当前车型没有优惠额度', API_CODE_FAIL);
|
|
}
|
|
if(!$payway && $finance_id){ //分期
|
|
$finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]);
|
|
if(!$finance_row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'brand_id' => $series_row['brand_id'],
|
|
's_id' => $series_row['id'],
|
|
'v_id' => $v_id,
|
|
'cor_id' => $color_id,
|
|
'incor_id' => $incolor_id,
|
|
'payway' => $payway ? 1 : 0,
|
|
'srv_ids' => json_encode($srv_arr,JSON_UNESCAPED_UNICODE),
|
|
'if_insure' => 0,
|
|
'if_num' => 0
|
|
];
|
|
$main_type && $data['main_type'] = 1;
|
|
$delry_time && $data['delry_time'] = $delry_time;
|
|
$finance_row && $data['finance_id'] = $finance_row['id'];
|
|
$data['if_fine'] = $if_fine ? 1:0;
|
|
$fines && $data['fines'] = json_encode($fines,JSON_UNESCAPED_UNICODE);
|
|
|
|
$color_arr = json_decode($business_row['colors'],true);
|
|
//获取金额json数据
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$data['car_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
|
|
$money_json['price_car'] = $car_row['price_car'];
|
|
$money_json['price_book'] = $deposit;
|
|
$money_json['price_insure'] = $car_row['price_insure'];
|
|
$money_json['price_fine'] = $car_row['price_fine'];
|
|
$money_json['price_discount'] = $disc_money;
|
|
$money_json['price_fine_discount'] = $disc_fine_money;
|
|
$money_json['price_finance'] = $series_row['brand_id'] == 4 ? Orders_v2_entity::PRICE_FINANCE_NZ : Orders_v2_entity::PRICE_FINANCE;
|
|
$money_json['price_color'] = in_array($color_id,$color_arr) ? $business_row['price_color'] : 0;
|
|
$money_json['price_coplus'] = $main_type ? $business_row['price_coplus'] : 0;
|
|
//获取挂牌价
|
|
if($srv_arr){
|
|
foreach ($srv_arr as $item) {
|
|
$money_json[$item['key']] = $item['price'];
|
|
$item['id'] == 1 && $data['if_insure'] = 1;
|
|
$item['id'] == 2 && $data['if_num'] = 1;
|
|
}
|
|
}
|
|
$data['srv_ids'] = $srv_arr ? json_encode($srv_arr,JSON_UNESCAPED_UNICODE) : "";
|
|
if($fines){
|
|
$money_json['price_fine_select'] = 0;
|
|
foreach ($fines as $item) {
|
|
if($item['price']){
|
|
$money_json['price_fine_select'] += $item['price'];
|
|
}
|
|
}
|
|
}
|
|
$data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
|
|
$info_json = json_decode($row['info_json'],true);
|
|
$info_json['business_id'] = $business_id;
|
|
$data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE);
|
|
$result = $this->orders_model->update($data,['id'=>$row['id']]);
|
|
if($result){
|
|
$this->orders_v2_entity->edit_order($data,$row);
|
|
throw new Exception('修改成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('修改失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
private function detail($id){
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
throw new Exception('订单不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$orders_entity = new Orders_v2_entity();
|
|
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$info_json = json_decode($row['info_json'],true);
|
|
|
|
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
|
|
$series = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
|
|
$color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title');
|
|
$version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title');
|
|
$color = $color ? $color['title'] : '';
|
|
$version = $version ? $version['title'] : '';
|
|
|
|
$car_data = [];
|
|
if($row['brand_id'] && $row['s_id'] && $row['v_id']){
|
|
$car_data['车辆名称'] = $brand['name'].$series['name'];
|
|
$car_data['车辆名称'] = $brand['name'].$series['name'];
|
|
$car_data['车辆级别'] = $version;
|
|
$car_data['车身颜色'] = $color;
|
|
$car_data['平台售价'] = $money_json['price_car'];
|
|
$money_json['price_coplus'] && $car_data['公司加价'] = $money_json['price_coplus'];
|
|
$money_json['price_color'] && $car_data['颜色加价'] = $money_json['price_color'];
|
|
$car_data['定金'] = $money_json['price_book'];
|
|
$car_price_list = [];
|
|
$money_json['price_discount'] && $car_price_list['优惠'] = $money_json['price_discount'];
|
|
$car_data['最终售价'] =[
|
|
'list' => $car_price_list,
|
|
'value' => $orders_entity->total_price($row['id'])
|
|
];
|
|
//服务费
|
|
$srv_data = $orders_entity->order_srv_money($row['id'],1);
|
|
if($srv_data['total']>0){
|
|
$car_data['委托代办']['value'] = $srv_data['total'];
|
|
foreach($srv_data['list'] as $val){
|
|
$car_data['委托代办']['list'][$val['title']] = $val['money'];
|
|
}
|
|
if($row['fines']){
|
|
$fines = json_decode($row['fines'],true);
|
|
$fines_list = [];
|
|
foreach ($fines as $item) {
|
|
$fines_list['list'][$item['txt']] = $item['price'];
|
|
}
|
|
$fines_list['value'] = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0.00;
|
|
$car_data['委托代办']['list']['精品选装'] = $fines_list;
|
|
}
|
|
}
|
|
}
|
|
if(!$row['payway'] && $row['brand_id']){
|
|
$finance_row = $this->sys_finance_model->get(['id'=>$row['finance_id']],'title');
|
|
$car_data['按揭信息'] = $finance_row['title'] ? $finance_row['title']: '';
|
|
}
|
|
//是否存在意向金订单
|
|
$inten_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>4,'status>='=>0]);
|
|
$pay_status = 0;
|
|
$inten_money = 0;
|
|
if($inten_row && $inten_row['status']==0){
|
|
$pay_status = 1;
|
|
}
|
|
if($inten_row['status']==1){//已支付意向金
|
|
$inten_money = floatval($inten_row['total_price']);
|
|
}
|
|
|
|
$data = [
|
|
'id' => $id,
|
|
'name' => $row['name'],
|
|
'mobile' => mobile_asterisk($row['mobile']),
|
|
'payway' => $row['brand_id'] ? $row['payway'] : '',
|
|
'car_data' => $car_data,
|
|
'pay_status' => $pay_status,
|
|
'pay_img' => $orders_entity::API_PAY_IMG,
|
|
'pack_id' => $row['pack_id'],
|
|
'brand_id' => $row['brand_id'],
|
|
'car_id' => $row['s_id'],
|
|
'v_id' => $row['v_id'],
|
|
'color_id' => $row['cor_id'],
|
|
'incolor_id' => $row['incor_id'],
|
|
'delry_time' => $row['delry_time']!='0000-00-00 00:00:00' ? date('Y-m-d',strtotime($row['delry_time'])):'',
|
|
'finance_id' => !$row['payway'] ? $row['finance_id'] : '',
|
|
'deposit' => $money_json['price_book'] ? $money_json['price_book'] : 0,
|
|
'disc_money' => $money_json['price_discount'] ? $money_json['price_discount'] : '',
|
|
'disc_fine_money' => $money_json['price_fine_discount'] ? $money_json['price_fine_discount'] : 0,
|
|
'srv_arr' => $row['srv_ids'] ? json_decode($row['srv_ids'],true) : [],
|
|
'cus_id' => $row['customer_id'],
|
|
'status' => $row['status'],
|
|
'if_fine' => $row['if_fine'] ? 1 : 0,
|
|
'main_type' => intval($row['main_type']),
|
|
'fines' => $row['fines'] ? json_decode($row['fines'],true) : [],
|
|
'address' => $info_json['c_address'] ? $info_json['c_address'] : ''
|
|
];
|
|
if($row['main_type']){
|
|
$info_json['c_credit'] && $data['credit'] = $info_json['c_credit'];
|
|
$info_json['c_company'] && $data['company'] = $info_json['c_company'];
|
|
}else{
|
|
$data['owner_name'] = $row['owner_name'];
|
|
$data['owner_mobile'] = $row['owner_mobile'];
|
|
$data['owner_cardid'] = $info_json['c_owner_cardid'];
|
|
}
|
|
$data['cardid'] = $info_json['c_cardid'];
|
|
$inten_money && $data['inten_money'] = $inten_money;
|
|
//选择随车物品
|
|
$ckcar_status = 0;
|
|
if($this->receiver_order_status_model->count(['o_id'=>$row['id'],'pid_status'=>3,'status'=>1]) && !$this->receiver_order_status_model->count(['o_id'=>$row['id'],'pid_status'=>4,'status'=>1])){
|
|
$ckcar_status = 1;
|
|
}
|
|
$delivery = $this->order_deliverys_model->get(['o_id'=>$row['id']],'status,info,tool,remark');
|
|
$ckcar_data = [
|
|
'info' => $delivery['info'] ? explode(',',$delivery['info']) : [],
|
|
'tool' => $delivery['tool'] ? explode(',',$delivery['tool']) : [],
|
|
'remark' => $delivery['remark'] ? $delivery['remark'] : ''
|
|
];
|
|
$data['ckcar_status'] = $ckcar_status;
|
|
$data['ckcar_data'] = $ckcar_data;
|
|
$price_book = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>1,'status'=>1]); //定金是否支付
|
|
$data['price_book_status'] = $price_book ? true : false;
|
|
$price_srv = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>2,'status'=>1]); //服务费是否支付
|
|
$data['price_srv_status'] = $price_srv ? true : false;
|
|
$price_last = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>3,'status'=>1]); //尾款是否支付
|
|
$data['price_last_status'] = $price_last ? true : false;
|
|
$data['edit_status'] = $price_last ? 0 : 1;
|
|
$data['loan_status'] = true;
|
|
|
|
$loan_row = $this->order_loans_model->get(['o_id'=>$row['id']]);
|
|
$data['notify_file'] = [
|
|
'src' => $loan_row['notify_file'] ? build_qiniu_image_url($loan_row['notify_file']) : '',
|
|
'value' => $loan_row['notify_file'] ? $loan_row['notify_file'] : ''
|
|
];
|
|
$data['lend_file'] = [
|
|
'src' => $loan_row['lend_file'] ? build_qiniu_image_url($loan_row['lend_file']) : '',
|
|
'value' => $loan_row['lend_file'] ? $loan_row['lend_file'] : ''
|
|
];
|
|
$data['price_loan'] = $money_json['price_loan'] ? $money_json['price_loan'] : 0.00;
|
|
return $data;
|
|
}
|
|
|
|
private function lists(){
|
|
$group_id = $this->session['group_id'];
|
|
$uid = $this->session['uid'];
|
|
$keyword = $this->input_param('keyword');
|
|
$status = $this->input_param('status');
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
|
|
$where = [
|
|
'status>=' => 0,
|
|
'biz_id' => $this->biz_id,
|
|
];
|
|
|
|
$group_id == 1 && $where['sale_id'] = $uid;//销售
|
|
if($group_id == 4 && $this->biz_id!=1){
|
|
$where['brand_id!='] = 3; //渠道经理过滤
|
|
}
|
|
|
|
if($keyword){
|
|
$where["(name='{$keyword}' or mobile='{$keyword}')"] = null;
|
|
}
|
|
if($status == 11 ){ //进行中
|
|
$where['status'] = 0;
|
|
}elseif($status == 12 ){ //已完成
|
|
$where['status'] = 1;
|
|
}else{
|
|
strlen($status) && $where['status'] = $status;
|
|
}
|
|
$fileds = 'id,name,mobile,brand_id,s_id,v_id,cor_id,incor_id,payway,status,c_time,money_json,if_num';
|
|
$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');
|
|
|
|
//获取车辆属性
|
|
$version_arr = array_unique(array_column($rows,'v_id'));
|
|
$color_arr = array_unique(array_column($rows,'cor_id'));
|
|
$attrs_arr = array_merge($version_arr,$color_arr);
|
|
$attrs = $this->auto_attr_model->get_map_by_ids($attrs_arr,'id,title');
|
|
//旧订单数据
|
|
$old_rows = [];
|
|
$old_ids = array_unique(array_column($rows,'id'));
|
|
if($old_ids){
|
|
$ids_str = implode(',',$old_ids);
|
|
$where = [
|
|
"id in ({$ids_str})" => null,
|
|
];
|
|
$old_rows = $this->receiver_orders_model->map('id','status',$where,'','','','id,status');
|
|
}
|
|
|
|
//获取订单资料
|
|
$order_datas = $this->receiver_order_datas_model->get_map_by_oids(array_column($rows,'id'),'id,o_id,cardida,business_licence,car_img,register_img,ins_img,other_img');
|
|
$status_arr = $this->orders_model->get_status();
|
|
$old_status_arr = $this->receiver_orders_model->get_status();
|
|
foreach($rows as $key=>$val){
|
|
if($val['id']>=Orders_v2_entity::V2_START_ID){
|
|
$money_json = json_decode($val['money_json'],true);
|
|
if($val['brand_id']){ //已选择车型
|
|
$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'] : '';
|
|
$color = isset($attrs[$val['cor_id']]) ? $attrs[$val['cor_id']][0]['title'] : '';
|
|
$version = isset($attrs[$val['v_id']]) ? $attrs[$val['v_id']][0]['title'] : '';
|
|
$title = "{$brand_name}{$serie_name}-{$color}-{$version}";
|
|
|
|
$img_status = $this->order_datas_entity->data_status($order_datas[$val['id']][0]);
|
|
$ck_user_status = $this->receiver_order_status_model->count(['o_id'=>$val['id'],'pid_status'=>4,'status'=>2]); //用户已确认
|
|
$ck_admin_status = $this->receiver_order_status_model->count(['o_id'=>$val['id'],'pid_status'=>4,'status'=>1]); //顾问确认已确认
|
|
$ck_status = [
|
|
['value'=>'顾问确认','selected'=>$ck_admin_status?true:false],
|
|
['value'=>'用户确认','selected'=>$ck_user_status?true:false]
|
|
];
|
|
|
|
$other_data = [
|
|
'品牌车型' => ['type'=> 'text','value'=>$title,'bg_color'=>''],
|
|
'付款方式' => ['type'=> 'text','value'=>$val['payway']?'全款':'分期','bg_color'=>''],
|
|
];
|
|
$book_is_pay = $this->app_liche_orders_model->get(['o_id'=>$val['id'],'type'=>1]); //定金
|
|
$p_row = $this->app_liche_orders_model->get(['o_id'=>$val['id'],'pid'=>0],'id'); //父订单
|
|
$last_row = $this->app_liche_orders_model->get(['o_id'=>$val['id'],'pid'=>$p_row['id'],'type'=>3],'id'); //尾款订单
|
|
//除去尾款已支付金额
|
|
$total_pay = $this->app_liche_orders_model->sum('total_price',['pid'=>$p_row['id'],'o_id'=>$val['id'],'status'=>1,'id!='=>$last_row['id']]);
|
|
//已支付尾款
|
|
$last_pay = $this->app_liche_orders_model->sum('total_price',['pid'=>$last_row['id'],'status'=>1]);
|
|
$is_pay_price = $total_pay['total_price'] + $last_pay['total_price'];
|
|
$need_pay = $this->orders_v2_entity->recevable_price($val['id'],false); //需要支付车款
|
|
$need_last_pay = $need_pay - $money_json['price_book'];
|
|
if($book_is_pay){
|
|
$book_is_pay_text = $book_is_pay['status'] ? '已支付':'未支付';
|
|
$price_book_text = $money_json['price_book']."($book_is_pay_text)";
|
|
$other_data['定金金额'] = ['type'=> 'text','value'=>$price_book_text,'bg_color'=>''];
|
|
}
|
|
$last_is_pay_text = $is_pay_price >= $need_pay ? '已支付':'未支付';
|
|
$last_text = $need_last_pay."($last_is_pay_text)";
|
|
$other_data['尾款金额'] = ['type'=> 'text','value'=>$last_text,'bg_color'=>''];
|
|
|
|
if($book_is_pay['status'] || $this->app_liche_orders_model->count(['o_id'=>$val['id'],'type'=>6,'status'=>1])){
|
|
if(!$val['payway']){
|
|
$other_data['分期办理'] = ['type'=> 'text','value'=>$this->orders_status_entity->status_cn($val['id'],1),'bg_color'=>''];
|
|
}
|
|
$other_data['车辆分配'] = ['type'=> 'text','value'=>$this->orders_status_entity->status_cn($val['id'],2),'bg_color'=>''];
|
|
$other_data['发票'] = ['type'=> 'text','value'=>$this->orders_status_entity->status_cn($val['id'],3),'bg_color'=>''];
|
|
$other_data['身份证'] = ['type'=> 'text','value'=>$img_status['cardida']['text'],'bg_color'=>$img_status['cardida']['color']];
|
|
$other_data['登记证'] = ['type'=> 'text','value'=>$img_status['register_img']['text'],'bg_color'=>$img_status['register_img']['color']];
|
|
$other_data['行驶证'] = ['type'=> 'text','value'=>$img_status['car_img']['text'],'bg_color'=>$img_status['car_img']['color']];
|
|
$other_data['保单'] = ['type'=> 'text','value'=>$img_status['ins_img']['text'],'bg_color'=>$img_status['ins_img']['color']];
|
|
$other_data['交车合照'] = ['type'=> 'text','value'=>$img_status['other_img']['text'],'bg_color'=>$img_status['other_img']['color']];
|
|
$other_data['交付'] = ['type'=> 'checkbox','value'=>'','lists' => $ck_status,'bg_color'=>''];
|
|
}
|
|
$other_data['订单日期'] = ['type'=> 'text','value'=>date('Y-m-d',$val['c_time']),'bg_color'=>''];
|
|
}else{
|
|
$price_intention = $money_json['price_intention'] ? $money_json['price_intention'] : '';
|
|
$other_data = [
|
|
'意向金' => ['type'=> 'text','value'=> $price_intention,'bg_color'=>''],
|
|
'订单日期' => ['type'=> 'text','value'=>date('Y-m-d',$val['c_time']),'bg_color'=>''],
|
|
];
|
|
}
|
|
$lists[] = [
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'mobile' => mobile_asterisk($val['mobile']),
|
|
'status_name' => $status_arr[$val['status']],
|
|
'other_data' => $other_data,
|
|
];
|
|
}else{//旧订单
|
|
$status = $old_rows[$val['id']] ? $old_rows[$val['id']] : 0;
|
|
$money_json = json_decode($val['money_json'],true);
|
|
if($val['brand_id']){ //已选择车型
|
|
$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'] : '';
|
|
$color = isset($attrs[$val['cor_id']]) ? $attrs[$val['cor_id']][0]['title'] : '';
|
|
$version = isset($attrs[$val['v_id']]) ? $attrs[$val['v_id']][0]['title'] : '';
|
|
//是否需要代办
|
|
$srv_arr = explode(',',$val['srv_ids']);
|
|
$db_title = in_array(2,$srv_arr) ? '需要' : '';
|
|
|
|
$other_data = [
|
|
'品牌车型' => "{$brand_name}{$serie_name}-{$color}-{$version}",
|
|
'付款方式' => $val['payway']?'全款':'分期',
|
|
'代办车牌' => $db_title,
|
|
'定金金额' => $money_json['price_book'],
|
|
'订单日期' => date('Y-m-d',$val['c_time']),
|
|
];
|
|
}else{
|
|
$other_data = [
|
|
'意向金' => $money_json['price_intention'] ? $money_json['price_intention'] : '',
|
|
'订单日期' => date('Y-m-d',$val['c_time']),
|
|
];
|
|
}
|
|
$lists[] = [
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'mobile' => mobile_asterisk($val['mobile']),
|
|
'status_name' => $old_status_arr[$status],
|
|
'other_data' => $other_data,
|
|
'remark' => $this->orders_entity->get_remark($status)
|
|
];
|
|
}
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
//订单列表头部
|
|
protected function get_tabs(){
|
|
$lists = [
|
|
['key' =>11 ,'name' => '进行中'],
|
|
['key' =>12 ,'name' => '已完成'],
|
|
];
|
|
return $lists;
|
|
}
|
|
|
|
//修改用户基本信息
|
|
protected function put_info(){
|
|
$id = $this->input_param('id');
|
|
$owner_name = trim($this->input_param('owner_name'));
|
|
$owner_mobile = trim($this->input_param('owner_mobile'));
|
|
$owner_cardid = trim($this->input_param('owner_cardid'));
|
|
$company = $this->input_param('company');
|
|
$c_credit = $this->input_param('credit');
|
|
$address = $this->input_param('address');
|
|
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$data = [];
|
|
$owner_name && $data['owner_name'] = $owner_name;
|
|
$owner_mobile && $data['owner_mobile'] = $owner_mobile;
|
|
$info_json = json_decode($row['info_json'],true);
|
|
$owner_cardid && $info_json['c_owner_cardid'] = $owner_cardid;
|
|
$c_credit && $info_json['c_credit'] = $c_credit;
|
|
$company && $info_json['c_company'] = $company;
|
|
$address && $info_json['c_address'] = $address;
|
|
$info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE);
|
|
$result = $this->orders_model->update($data,['id'=>$row['id']]);
|
|
if($result){
|
|
if($this->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)'=>null])){
|
|
$this->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (0,1)'=>null]);
|
|
}
|
|
throw new Exception('修改成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('修改失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
protected function put_status(){
|
|
$id = $this->input_param('id');
|
|
$row = $this->orders_model->get(['id'=>$id]);
|
|
if(!$row){
|
|
throw new Exception('订单不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$is_pay = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'status'=>1]);
|
|
if($is_pay){
|
|
throw new Exception('修改失败', ERR_PARAMS_ERROR);
|
|
}
|
|
$result = $this->orders_model->update(['status'=>-1],['id'=>$row['id']]);
|
|
if($result){
|
|
$this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id']]);
|
|
throw new Exception('修改成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('修改失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
}
|