84 lines
3.4 KiB
PHP
84 lines
3.4 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->library('receiver/orders_v2_entity');
|
|
$this->load->library('receiver/orders_status_entity');
|
|
}
|
|
|
|
protected function get(){
|
|
}
|
|
|
|
protected function post(){
|
|
|
|
}
|
|
|
|
protected function put(){
|
|
$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');
|
|
|
|
|
|
$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;
|
|
$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 && $result = $this->order_loans_model->update($update, ['id' => $row['id']]);
|
|
throw new Exception('保存成功', API_CODE_SUCCESS);
|
|
}
|
|
}
|