Files
liche/api/controllers/wxapp/licheb/Loan.php
T
2021-10-28 18:56:14 +08:00

106 lines
3.2 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('receiver/order/receiver_order_loans_model','order_loans_model');
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$this->load->model('auto/auto_cars_model');
}
protected function get(){
$oid = $this->input_param('oid');
$row = $this->orders_model->get(['id'=>$oid]);
$where_car = array(
's_id'=>$row['s_id'],
'v_id' => $row['v_id'],
);
$car = $this->auto_cars_model->get($where_car,'first_pay');
$money = $car['first_pay'] ? $car['first_pay'] * 36 : 0;
$banks = [
'易鑫金融'
];
$years = [
36
];
$data = [
'banks' => $banks,
'years' => $years,
'first_price' => $money
];
return $data;
}
protected function post(){
$oid = $this->input_param('oid');
$bank = $this->input_param('bank');
$year = $this->input_param('year');
$money = $this->input_param('money');
$loan = $this->order_loans_model->count(['o_id'=>$oid]);
if($loan){
throw new Exception('创建失败', ERR_PARAMS_ERROR);
}
$row = $this->orders_model->get(['id'=>$oid]);
if(!$row || !$bank || !$year || !$money){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$add_data = [
'o_id' => $oid,
'title' => $bank,
'year' => $year,
'first_price' => $money
];
$l_id = $this->order_loans_model->add($add_data);
if($l_id){
$data = [
'id' => $l_id,
'bank' => $bank,
'year' => $year,
'money' => $money
];
return $data;
}else{
throw new Exception('创建失败', ERR_PARAMS_ERROR);
}
}
protected function put(){
$id = $this->input_param('id');
$bank = $this->input_param('bank');
$year = $this->input_param('year');
$money = $this->input_param('money');
$row = $this->order_loans_model->get(['id'=>$id]);
if(!$row){
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
$update = [
'title' => $bank,
'year' => $year,
'first_price' => $money
];
$result = $this->order_loans_model->update($update,['id'=>$id]);
if($result){
throw new Exception('修改成功', API_CODE_SUCCESS);
}else{
throw new Exception('修改失败', ERR_PARAMS_ERROR);
}
}
}