Files
liche/api/controllers/wxapp/licheb/Cusorder2.php
T
xiaoyu d995cd0b9c order_time
order_time

order_time
2021-10-31 01:30:11 +08:00

219 lines
8.7 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('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_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');
}
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');
$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 || !$cardid || !$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_step($omobile);
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()
];
$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);
//获取挂牌价
if($series_row['brand_id']==3){ //狸车品牌写死挂牌费用0.01 测试用
$money_json['fee_carno'] = 0.01;
}else{
$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'];
}
$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' => strtotime('now')),['id'=>$cus_id]);
//增加分销记录
$this->load->library('entity/deal_entity',['app_id'=>1]);
$this->deal_entity->deal_log($o_id);
//意向金订单
if($inten_money){
$userinfo = $this->app_liche_users_model->get(['mobile'=>$data['mobile']]);
$this->orders_entity->c_intention($o_id,$userinfo,$inten_money);
}
return ['id'=>$o_id];
}
//修改订单信息
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');
$row = $this->orders_model->get(['id'=>$id]);
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
$car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id]);
if(!$row || !$series_row || !$car_row){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
if($row['status']>2){ //车辆确认后不可修改
throw new Exception('修改失败,信息不可修改', ERR_PARAMS_ERROR);
}
if(!$payway){ //分期
$finance_row = $this->sys_finance_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,
];
$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'];
$orders_entity = new Orders_entity();
if(!$payway){
if($series_row['brand_id']==4){ //哪吒品牌 金融服务费2000
$money_json['price_finance'] = 2000;
}else{
$money_json['price_finance'] = $orders_entity::PRICE_FINANCE;
}
}
$data['money_json'] = json_encode($money_json,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);
}
}
}