167 lines
7.3 KiB
PHP
167 lines
7.3 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/07/13
|
|
* Time: 14:08
|
|
*/
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
class Loan extends Wxapp{
|
|
|
|
public 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('app/liche/app_liche_users_model');
|
|
$this->load->model('app/liche/app_liche_orders_model');
|
|
|
|
$this->load->model('receiver/order/receiver_orders_v2_model');
|
|
$this->load->model('receiver/order/receiver_order_loans_model', 'order_loans_model');
|
|
$this->load->model('receiver/order/receiver_order_loans0_model', 'order_loans0_model');
|
|
|
|
$this->load->library('receiver/orders_v2_entity');
|
|
$this->load->library('receiver/orders_status_entity');
|
|
}
|
|
|
|
protected function get(){
|
|
}
|
|
|
|
protected function post(){
|
|
|
|
}
|
|
|
|
protected function put(){
|
|
$if_loan0 = $this->input_param('if_loan0');
|
|
//$if_loan0 = 1; // 模拟首付按揭
|
|
if ($if_loan0){
|
|
$this->put_loan0();
|
|
}
|
|
|
|
$oid = $this->input_param('o_id');
|
|
$finance_id = $this->input_param('finance_id');
|
|
$notify_file = $this->input_param('notify_file');
|
|
$lend_file = $this->input_param('lend_file');
|
|
$price_loan = $this->input_param('price_loan');
|
|
$num = $this->input_param('num');
|
|
$is_tiexi = intval($this->input_param('is_tiexi'));
|
|
|
|
$order_row = $this->receiver_orders_v2_model->get(['id' => $oid], 'id,mobile,money_json,payway');
|
|
$row = $this->order_loans_model->get(['o_id' => $oid]);
|
|
if(!$finance_id || !$notify_file || !$price_loan || !$order_row || $order_row['payway']){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
if(!$row){
|
|
$row['id'] = $this->order_loans_model->add(['c_time'=>time(),'o_id'=>$oid]);
|
|
}
|
|
$price_last = $this->app_liche_orders_model->get(['o_id'=>$oid,'type'=>3,'status'=>1]); //尾款是否支付
|
|
$last_pay = $this->app_liche_orders_model->count(['o_id'=>$oid,'pid'=>$price_last['id'],'status'=>1]); //存在已支付尾款
|
|
if($last_pay){
|
|
if($lend_file){
|
|
$update['lend_file'] = $lend_file;
|
|
$this->order_loans_model->update($update, ['id' => $row['id']]);
|
|
throw new Exception('保存成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('当前状态不可修改', API_CODE_FAIL);
|
|
}
|
|
}
|
|
|
|
$money_json = json_decode($order_row['money_json'], true);
|
|
$money_json['price_loan'] = $price_loan;
|
|
$money_json['loan_rebate'] = $this->input_param('loan_rebate') ? $this->input_param('loan_rebate') : 0; # 0612 按揭返点系数
|
|
$this->receiver_orders_v2_model->update(['finance_id' => $finance_id, 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE)], ['id' => $order_row['id']]);
|
|
//删除未支付订单
|
|
$this->app_liche_orders_model->delete(['o_id'=>$row['o_id'],'status'=>0,'pid!='=>0,'type!='=>1]);
|
|
//生成购车订单
|
|
$userinfo = $this->app_liche_users_model->get(['mobile'=>$order_row['mobile']]);
|
|
$this->orders_v2_entity->add_order($order_row['id'],$userinfo['id']);
|
|
$this->orders_status_entity->set_status($oid,1,1);
|
|
$update = [
|
|
'notify_file' => implode(',',$notify_file)
|
|
];
|
|
$lend_file && $update['lend_file'] = $lend_file;
|
|
$num && $update['num'] = $num;
|
|
$update['is_tiexi'] = $is_tiexi;
|
|
$update && $result = $this->order_loans_model->update($update, ['id' => $row['id']]);
|
|
$this->order_status_check_after_edit_loan($order_row);
|
|
throw new Exception('保存成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
// 首付按揭:功能参考put,操作对象有差异,更新 money_json['price_loan0'] 与 finance_id0
|
|
protected function put_loan0(){
|
|
$oid = $this->input_param('o_id');
|
|
$finance_id = $this->input_param('finance_id');
|
|
$notify_file = $this->input_param('notify_file');
|
|
$lend_file = $this->input_param('lend_file');
|
|
$price_loan = $this->input_param('price_loan');
|
|
$num = $this->input_param('num');
|
|
$is_tiexi = intval($this->input_param('is_tiexi'));
|
|
|
|
$order_row = $this->receiver_orders_v2_model->get(['id' => $oid], 'id,mobile,money_json,payway');
|
|
if(!$finance_id || !$notify_file || !$price_loan || !$order_row || $order_row['payway']){
|
|
throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
$row = $this->order_loans0_model->get(['o_id' => $oid]);
|
|
if(!$row){
|
|
$row['id'] = $this->order_loans0_model->add(['c_time'=>time(),'o_id'=>$oid]);
|
|
}
|
|
|
|
$money_json = json_decode($order_row['money_json'], true);
|
|
$money_json['price_loan0'] = $price_loan;
|
|
$money_json['loan0_rebate'] = $this->input_param('loan_rebate') ? $this->input_param('loan_rebate') : 0; # 0612 按揭返点系数
|
|
$this->receiver_orders_v2_model->update(['finance_id0' => $finance_id, 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE)], ['id' => $order_row['id']]);
|
|
//生成购车订单
|
|
$userinfo = $this->app_liche_users_model->get(['mobile'=>$order_row['mobile']]);
|
|
$this->orders_v2_entity->add_order($order_row['id'],$userinfo['id']);
|
|
//$this->orders_status_entity->set_status($oid,1,1); // 首付按揭不改订单状态
|
|
$update = [
|
|
'notify_file' => implode(',',$notify_file)
|
|
];
|
|
$lend_file && $update['lend_file'] = $lend_file;
|
|
$num && $update['num'] = $num;
|
|
$update['is_tiexi'] = $is_tiexi;
|
|
$update && $result = $this->order_loans0_model->update($update, ['id' => $row['id']]);
|
|
$this->order_status_check_after_edit_loan($order_row);
|
|
throw new Exception('保存成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
// 0首付下状态处理:非首付按揭有通知函 / 首付按揭时两个按揭的通知函都有,就可以设置 pid_status = 0 status = 2
|
|
private function order_status_check_after_edit_loan($order_row){
|
|
if (!$order_row){
|
|
return false;
|
|
}
|
|
|
|
$money_json = json_decode($order_row['money_json'], true);
|
|
$payway = $order_row['payway'];
|
|
$deposit = $money_json['price_book'];
|
|
$if_zero_firstpay = $payway == 0 && !$deposit ? 1 : 0;
|
|
if (!$if_zero_firstpay){
|
|
return false;
|
|
}
|
|
|
|
$oid = $order_row['id'];
|
|
|
|
$row = $this->order_loans_model->get(['o_id' => $oid]);
|
|
$if_loans_notify_file = $row && $row['notify_file'] ? 1 : 0;
|
|
|
|
if ($money_json['price_loan0']){
|
|
$row0 = $this->order_loans0_model->get(['o_id' => $oid]);
|
|
$if_loans0_notify_file = $row0 && $row0['notify_file'] ? 1 : 0;
|
|
}
|
|
else{
|
|
$if_loans0_notify_file = 1;
|
|
}
|
|
|
|
if ($if_loans_notify_file && $if_loans0_notify_file){
|
|
$this->orders_status_entity->set_status($oid,0,2);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|