240 lines
10 KiB
PHP
240 lines
10 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 Cusorder2 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_contracts_model');
|
|
$this->load->model('receiver/receiver_fine_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("biz/biz_model");
|
|
//$this->load->model('sys/sys_finance_model');
|
|
$this->load->model('sys/sys_supplier_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/customers_entity');
|
|
}
|
|
|
|
protected function get(){
|
|
}
|
|
|
|
//创建订单
|
|
protected function post(){
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
$cus_id = $this->input_param('cus_id');
|
|
$name = $this->input_param('name');
|
|
$mobile = $this->input_param('mobile');
|
|
$bak_mobile = $this->input_param('bak_mobile');
|
|
$address = $this->input_param('address');
|
|
$cardid = $this->input_param('cardid');
|
|
$ifentrust = $this->input_param('ifentrust');
|
|
$entrust_name = $this->input_param('entrust_name');
|
|
$entrust_mobile = $this->input_param('entrust_mobile');
|
|
$entrust_idcard = $this->input_param('entrust_idcard');
|
|
$inten_money = floatval($this->input_param('inten_money'));//意向金
|
|
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
if(!$row || !$address){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if($inten_money > 2000){
|
|
throw new Exception('意向金不得高于2000', ERR_PARAMS_ERROR);
|
|
}
|
|
//判断是否存在未完成流程
|
|
$omobile = $mobile ? $mobile : $row['mobile'];
|
|
$o_order = $this->orders_model->get(['mobile'=>$omobile,'status>='=>0,'status<'=>6]);
|
|
if($o_order){
|
|
$this->orders_model->update(['status'=>-1],['id'=>$o_order['id']]);
|
|
}
|
|
$data = [
|
|
'rid' => $cus_id,
|
|
'sid' => create_order_no(350200,$this->app_key),
|
|
'name' => $name ? $name : $row['name'],
|
|
'mobile' => $mobile ? $mobile : $row['mobile'],
|
|
'biz_id' => $biz_id,
|
|
'admin_id' => $this->session['uid'],
|
|
'c_time' => time()
|
|
];
|
|
$bak_mobile && $data['bak_mobile'] = $bak_mobile;
|
|
$info_json = [];
|
|
$cardid && $info_json['c_cardid'] = $cardid;
|
|
$address && $info_json['c_address'] = $address;
|
|
if($ifentrust){
|
|
if(!$entrust_name || !$entrust_mobile || !$entrust_idcard){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
$info_json['entrust_name'] = $entrust_name;
|
|
$info_json['entrust_mobile'] = $entrust_mobile;
|
|
$info_json['entrust_idcard'] = $entrust_idcard;
|
|
}
|
|
$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'], '生成订单', 6);
|
|
|
|
//意向金订单
|
|
$orders_entity = new Orders_entity();
|
|
if($inten_money){
|
|
$userinfo = $this->app_liche_users_model->get(['mobile'=>$data['mobile']]);
|
|
$orders_entity->c_intention($o_id,$userinfo,$inten_money);
|
|
}
|
|
return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_CREATE_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');
|
|
$pack_id = $this->input_param('pack_id');
|
|
$main_type = $this->input_param('main_type');
|
|
$delry_time = $this->input_param('delry_time');
|
|
$finance_id = $this->input_param('finance_id');
|
|
$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_ids = $this->input_param('srv_ids');
|
|
$fine_ids = $this->input_param('fine_ids');
|
|
|
|
$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']);
|
|
if(!$row || !$series_row || !$car_row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if($row['status']>2){ //车辆确认后不可修改
|
|
throw new Exception('修改失败,信息不可修改', ERR_PARAMS_ERROR);
|
|
}
|
|
if($biz['type'] == 1 && !count($srv_ids)){ //直营店必须选择一个代办
|
|
throw new Exception('请选择代办项目', 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_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]);
|
|
$finance_row = $this->sys_supplier_model->get(['id'=>$finance_id,'status'=>1]);
|
|
if(!$finance_row){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
$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 = [
|
|
'brand_id' => $series_row['brand_id'],
|
|
's_id' => $series_row['id'],
|
|
'v_id' => $v_id,
|
|
'cor_id' => $color_id,
|
|
'incor_id' => $incolor_id,
|
|
'car_json' => json_encode($car_json,JSON_UNESCAPED_UNICODE),
|
|
'price' => $car_row['price_car'],
|
|
'deposit' => $car_row['price_book'],
|
|
'payway' => $payway ? 1 : 0,
|
|
'srv_ids' => implode(',',$srv_ids),
|
|
'fine_ids' => implode(',',$fine_ids)
|
|
];
|
|
$pack_id && $data['pack_id'] = $pack_id;
|
|
$main_type && $data['main_type'] = 1;
|
|
$delry_time && $data['delry_time'] = $delry_time;
|
|
$finance_row && $data['finance_id'] = $finance_row['id'];
|
|
|
|
//获取金额json数据
|
|
$money_json = json_decode($row['money_json'],true);
|
|
$money_json['price_car'] = $car_row['price_car'];
|
|
$money_json['price_book'] = $car_row['price_book'];
|
|
$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;
|
|
$orders_entity = new Orders_entity();
|
|
$money_json['price_finance'] = $series_row['brand_id'] == 4 ? $orders_entity::PRICE_FINANCE_NZ : $orders_entity::PRICE_FINANCE;
|
|
$data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE);
|
|
|
|
$jsondata = json_decode($row['jsondata'],true);
|
|
$jsondata['if_fine'] = $if_fine ? 1 : 0;
|
|
$data['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE);
|
|
|
|
$result = $this->orders_model->update($data,['id'=>$row['id']]);
|
|
if($result){
|
|
$orders_entity->edit_order($data,$row,$this->session['uid'],$this->session['uname']);
|
|
throw new Exception('修改成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('创建失败', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
}
|