add-auto-finance

This commit is contained in:
lccsw
2021-09-08 18:01:59 +08:00
parent cf3c0d7745
commit 53c2c9e13d
10 changed files with 670 additions and 4 deletions
+247
View File
@@ -0,0 +1,247 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Date: 2021/09/06
* Time: 10:19
*/
class Finance extends HD_Controller{
public function __construct(){
parent::__construct();
$this->load->model('auto/auto_brand_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('auto/auto_finance_model');
$this->load->model('sys/sys_finance_model');
}
public function index(){
return $this->lists();
}
public function lists(){
$params = $this->input->get();
$where = array();
if(strlen($params['status']) > 0){
$where['status'] = $params['status'];
} else {
$params['status'] = '';
}
$page = $params['page'];
$page = !$page ? 1 : $page;
$size = $params['size'];
$size = !$size ? 20 : $size;
//状态
$statusAry = array('0' => '关闭', '1' => '开启');
$total = $this->auto_finance_model->count($where);
$lists = array();
if($total){
$rows = $this->auto_finance_model->select($where, 'id desc', $page, $size, $select);
$fin_id_arr = array_column($rows,'fin_id');
$fin_rows = $this->sys_finance_model->get_map_by_ids($fin_id_arr,'id,title');
foreach($rows as $key=>$val){
$lists[] = [
'id' => $val['id'],
'car' => $this->auto_cars_model->get_title($val['car_id']),
'fin_name' => $fin_rows[$val['fin_id']] ? $fin_rows[$val['fin_id']][0]['title'] : '',
'num' => $val['num'],
'mouth_pay' => $val['mouth_pay'],
'first_pay' => $val['first_pay'],
'srv_pay' => $val['srv_pay'],
'status' => $val['status']
];
}
}
$this->data['params'] = $params;
$this->data['lists'] = $lists;
$this->data['statusAry'] = $statusAry;
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page, 'totle' => $total);
$this->data['_title'] = '车型金融产品管理';
$this->show_view('auto/finance/lists',true);
}
public function get(){
$info = [];
$id = $this->input->get('id');
$row = $this->auto_finance_model->get(['id'=>$id]);
$action = 'auto/finance/add';
if($row){
$car_row = $this->auto_cars_model->get(['id'=>$row['car_id']],'brand_id,s_id,v_id');
$action = 'auto/finance/edit';
$info['id'] = $row['id'];
$info['car_id'] = $row['car_id'];
$info['brand_id'] = $car_row['brand_id'];
$info['s_id'] = $car_row['s_id'];
$info['v_id'] = $car_row['v_id'];
$info['fin_id'] = $row['fin_id'];
$info['num'] = $row['num'];
$info['first_pay'] = $row['first_pay'];
$info['mouth_pay'] = $row['mouth_pay'];
$info['srv_pay'] = $row['srv_pay'];
$info['status'] = $row['status'];
}
$nums = $this->auto_finance_model->get_nums();
$finance = $this->sys_finance_model->select(['status'=>1],'id desc',1,20,'id,title');
!$info['fin_id'] && $info['fin_id'] = $finance[0]['id'];
!$info['num'] && $info['num'] = $nums[0];
!isset($info['status']) && $info['status'] = 1;
!$info['brand_id'] && $info['brand_id'] = 0;
!$info['s_id'] && $info['s_id'] = 0;
!$info['v_id'] && $info['v_id'] = 0;
$this->data['action'] = $action;
$this->data['finance'] = $finance;
$this->data['statusAry'] = $this->auto_finance_model->status_ary();
$this->data['nums'] = $nums;
$this->data['info'] = $info;
$this->show_view('auto/finance/get');
}
public function add(){
$info = $this->input->post('info');
if(!$info['car_id']){
return $this->show_json(SYS_CODE_FAIL, '请选择具体车辆!');
}
if(!$info['first_pay'] || !$info['mouth_pay'] || !$info['srv_pay'] ||!$info['num']){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$row = $this->auto_finance_model->get(['car_id'=>$info['car_id'],'num'=>$info['num'],'fin_id'=>$info['fin_id']]);
if($row){
$finance = $this->sys_finance_model->get(['id'=>$info['fin_id']]);
return $this->show_json(SYS_CODE_FAIL, "该车已配置:{$finance['title']}金融-{$info['num']}");
}
$adata = [
'car_id' => $info['car_id'],
'fin_id' => $info['fin_id'],
'first_pay' => $info['first_pay'],
'mouth_pay' => $info['mouth_pay'],
'srv_pay' => $info['srv_pay'],
'num' => $info['num'],
'c_time' => time()
];
!$info['status'] && $adata['status'] = 0;
$res = $this->auto_finance_model->add($adata);
if(!$res){
return $this->show_json(SYS_CODE_FAIL, '添加失败!');
}
return $this->show_json(SYS_CODE_SUCCESS, '添加成功!');
}
public function edit(){
$info = $this->input->post('info');
$row = $this->auto_finance_model->get(['id'=>$info['id']]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if(!$info['car_id']){
return $this->show_json(SYS_CODE_FAIL, '请选择具体车辆!');
}
if(!$info['first_pay'] || !$info['mouth_pay'] || !$info['srv_pay'] ||!$info['num']){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$row = $this->auto_finance_model->get(['car_id'=>$info['car_id'],'num'=>$info['num'],'fin_id'=>$info['fin_id'],'id !='=>$info['id']]);
if($row){
$finance = $this->sys_finance_model->get(['id'=>$info['fin_id']]);
return $this->show_json(SYS_CODE_FAIL, "该车已配置:{$finance['title']}金融-{$info['num']}");
}
$adata = [
'car_id' => $info['car_id'],
'fin_id' => $info['fin_id'],
'first_pay' => $info['first_pay'],
'mouth_pay' => $info['mouth_pay'],
'srv_pay' => $info['srv_pay'],
'num' => $info['num'],
'c_time' => time()
];
!$info['status'] && $adata['status'] = 0;
$res = $this->auto_finance_model->update($adata,['id'=>$info['id']]);
if(!$res){
return $this->show_json(SYS_CODE_FAIL, '更新失败!');
}
return $this->show_json(SYS_CODE_SUCCESS, '更新成功!');
}
public function del(){
}
public function batch(){
// TODO: Implement batch() method.
}
public function export(){
// TODO: Implement export() method.
}
public function get_cars(){
$brand_id = $this->input->get('brand_id');
$s_id = $this->input->get('s_id');
$v_id = $this->input->get('v_id');
$t1 = 'lc_auto_cars';
$t2 = 'lc_auto_brand';
$t3 = 'lc_auto_series';
$where = [
"$t1.status" => 1
];
$brand_id && $where["$t1.brand_id"] = $brand_id;
$s_id && $where["$t1.s_id"] = $s_id;
$v_id && $where["$t1.v_id"] = $v_id;
$count = $this->auto_cars_model->select_car($where,'',0,0,'',1);
$lists = [];
$size = $page = 0;
if($count){
$fileds = "$t1.id,$t1.v_id,$t1.cor_id,$t1.incor_id,$t2.name as b_name,$t3.name as s_name";
$rows = $this->auto_cars_model->select_car($where,'id desc',$page,$size,$fileds);
$v_id_arr = array_column($rows,'v_id');
$cor_id_arr = array_column($rows,'cor_id');
$incor_id_arr = array_column($rows,'incor_id');
$attr_id_arr = array_unique(array_merge($v_id_arr,$cor_id_arr,$incor_id_arr));
$attrs = $this->auto_attr_model->get_map_by_ids($attr_id_arr,'id,title');
foreach($rows as $key => $val){
$lists[] = [
'id' => $val['id'],
'b_name' => $val['b_name'],
's_name' => $val['s_name'],
'v_name' => $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '',
'cor_name' => $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '',
'incor_name' => $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'] : '',
];
}
}
$this->data['lists'] = $lists;
return $this->show_json(SYS_CODE_SUCCESS);
}
function edit_status(){
$id = $this->input->post('id');
$field = $this->input->post('field');
$value = $this->input->post('value');
$status = $this->input->post('status');
if('status' == $field){
$status = $value;
}
$upd = array('status' => $status);
if(is_numeric($id)){
$where = array('id' => $id);
} else {
$where = array("id in ({$id})" => null);
}
$ret = $this->auto_finance_model->update($upd, $where);
if(!$ret){
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
}
+1 -1
View File
@@ -196,4 +196,4 @@ class Finance extends HD_Controller{
public function export(){
// TODO: Implement export() method.
}
}
}
+202
View File
@@ -0,0 +1,202 @@
<form id="vue-edit" class="am-form am-form-horizontal" action="/sys/finance/edit" data-auto="true" method="post" style="width: 90%;padding:25px 30px 20px 0;margin: 0 auto">
<div class="am-form-group">
<label class="am-para-label"><span class="com-must-star">*</span>车型:</label>
<div class="am-para-input">
<div class="am-form-group am-para-inline w150">
<select name="brand_id" v-model="info.brand_id">
<option value="0">选择品牌</option>
<option :value="v.id" v-for="v in brand_arr">{{v.name}}</option>
</select>
</div>
<div class="am-form-group am-para-inline w150">
<select name="s_id" v-model="info.s_id">
<option value="0">选择车系</option>
<option :value="v.id" v-for="v in s_arr">{{v.name}}</option>
</select>
</div>
<div class="am-form-group am-para-inline w150">
<select name="s_id" v-model="info.v_id">
<option :value="v.id" v-for="v in v_arr">{{v.name}}</option>
</select>
</div>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label"></label>
<div class="am-para-input wp40">
<select name="car_id" v-model="info.car_id">
<option value="0">选择具体车辆</option>
<option :value="v.id" v-for="v in cars_arr">{{v.b_name}}{{v.s_name}} {{v.v_name}}-{{v.cor_name}}-内饰{{v.incor_name}}</option>
</select>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label"><span class="com-must-star">*</span>金融产品:</label>
<div class="am-para-input wp40">
<select v-model="info.fin_id">
<option v-for="(v,i) in finance" :value="v.id">{{v.title}}</option>
</select>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">期数:</label>
<div class="am-para-input wp40">
<select v-model="info.num">
<option v-for="(v,i) in nums" :value="v">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">首付:</label>
<div class="am-para-input">
<input type="text" name="first_pay" v-model="info.first_pay" style="width: 20%; display: inline"/>
<span>万元</span>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">月供:</label>
<div class="am-para-input">
<input type="text" name="mouth_pay" v-model="info.mouth_pay" style="width: 20%; display: inline"/>
<span></span>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">服务费:</label>
<div class="am-para-input">
<input type="text" name="srv_pay" v-model="info.srv_pay" style="width: 20%; display: inline"/>
<span></span>
</div>
</div>
<div class="am-form-group">
<label class="am-para-label">状态:</label>
<div class="am-para-input wp40">
<select name="status" v-model="info.status">
<option v-for="(v,i) in statusAry" :value="i">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input"><button class="am-btn am-btn-secondary" type="button" @click="saveEdit">提交</button></div>
</div>
</form>
<script>
var loading = 0;
var vue_obj;
$(function(){
vue_obj = new Vue({
el: '#vue-edit',
data: {
info:{},
statusAry:[],
action:'',
finance:[],
nums:[],
brand_arr:[],
s_arr:[],
v_arr:[],
cars_arr:[],
},
mounted:function(){
this.info = <?=json_encode($info)?>;
this.statusAry = <?=json_encode($statusAry)?>;
this.action = '<?=$action?>';
this.finance = <?=json_encode($finance)?>;
this.nums = <?=json_encode($nums)?>;
this.init_auto();
},
methods:{
init_auto:function(){
var vm = this;
$.get('common/auto',{type:1,tp:1},function(response){
if (response.code == 1) {
vm.brand_arr = response.data;
}
});
if(vm.info.brand_id>0){
$.get('common/auto',{pid:vm.info.brand_id,type:2,tp:1},function(response){
if (response.code == 1) {
vm.s_arr = response.data;
}
});
}
if(vm.info.s_id>0){
$.get('common/auto',{pid:vm.info.s_id,type:3,tp:1},function(response){
if (response.code == 1) {
vm.v_arr = response.data;
}
});
}
if(vm.info.v_id){
$.get('auto/finance/get_cars',{brand_id:vm.info.brand_id,s_id:vm.info.s_id,v_id:vm.info.v_id},function(response){
if (response.code == 1) {
vm.cars_arr = response.data.lists
}
});
}
},
saveEdit:function(){
$.post(this.action,{info:this.info},function(data){
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
layer.closeAll();
$.form.reload();
});
} else {
layer.msg(data.msg, {icon: 2});
}
})
}
},
watch:{
'info.brand_id':function(nv, ov){
var that = this;
if(nv == 0){
that.cars_arr = [];
that.s_arr = [];
that.v_arr = [];
that.info.s_id = 0;
that.info.car_id = 0;
that.info.v_id = 0;
} else {
$.get('common/auto',{pid:that.info.brand_id,type:2,tp:1},function(response){
if (response.code == 1) {
that.s_arr = response.data
}
});
}
},
'info.s_id':function(nv, ov){
var that = this;
if(nv == 0){
that.v_arr = [];
that.cars_arr = [];
that.info.car_id = 0;
that.info.v_id = 0;
} else {
$.get('common/auto',{pid:that.info.s_id,type:3},function(response){
if (response.code == 1) {
that.v_arr = response.data;
}
});
}
},
'info.v_id':function(nv, ov){
var that = this;
if(nv == 0){
that.cars_arr = [];
that.info.car_id = 0;
} else {
$.get('auto/finance/get_cars',{brand_id:that.info.brand_id,s_id:that.info.s_id,v_id:that.info.v_id},function(response){
if (response.code == 1) {
that.cars_arr = response.data.lists
}
});
}
},
}
});
});
</script>
+97
View File
@@ -0,0 +1,97 @@
<div class="coms-table-wrap">
<div class="coms-table-hd clearfix no-border">
<form action="/auto/cars/lists" class="form-search" onsubmit="return false">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label">状态:</label>
<div class="am-para-inline w150">
<select name="status" v-model="params.status">
<option value="">请选择</option>
<option :value="i" v-for="(v,i) in statusAry">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group fl ml20">
<button type="submit" class="am-btn am-btn-sm am-btn-success w100">搜索</button>
<a data-modal="/auto/finance/get" data-title="添加数据" class="am-btn am-btn-sm am-btn-success w100">新增</a>
</div>
</div>
</form>
</div>
<div class="coms-table-bd">
<div class="fr">共有<?= $pager['totle'] ?>条数据</div>
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="15%"><span>车型</span></th>
<th width="15%"><span>金融产品</span></th>
<th width="10%"><span>期数</span></th>
<th width="15%"><span>首付/(万)</span></th>
<th width="15%"><span>月供</span></th>
<th width="15%"><span>服务费</span></th>
<th width=""><span>操作</span></th>
</tr>
</thead>
<tbody>
<template v-for="(v,i) in lists">
<tr >
<td @dblclick="set_edit(i,1)">{{v.car}}</td>
<td @dblclick="set_edit(i,1)">{{v.fin_name}}</td>
<td @dblclick="set_edit(i,1)">{{v.num}}</td>
<td @dblclick="set_edit(i,1)">{{v.first_pay}}</td>
<td @dblclick="set_edit(i,1)">{{v.mouth_pay}}</td>
<td @dblclick="set_edit(i,1)">{{v.srv_pay}}</td>
<td>
<a href="javascript:void(0);" class="am-btn am-btn-primary am-btn-xs"
:data-modal="'/auto/finance/get?id='+v.id" :data-title="v.title">编辑</a>
<a :data-update="v.id" data-action="/auto/finance/edit_status" class="am-btn am-btn-danger am-btn-xs"
data-field="status" data-value="0" v-if="1==v.status">关闭</a>
<a :data-update="v.id" data-action="/auto/finance/edit_status" class="am-btn am-btn-success am-btn-xs"
data-field="status" data-value="1" v-if="0==v.status">开启</a>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
var vue_obj;
var loading = 0;
$(function(){
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params:[],
lists:[],
statusAry:[],
seryAry:[],
info_edit:{}
},
mounted:function() {
var vm = this;
var lists = [];
lists = <?=json_encode($lists)?>;
vm.params = <?=json_encode($params)?>;
vm.statusAry = <?=json_encode($statusAry)?>;
for(var i in lists){
lists[i].edit = 0;
}
vm.lists = lists;
},
methods:{
},
});
<?php page_script($pager) ?>
});
</script>
+3 -1
View File
@@ -63,10 +63,11 @@ class Cusorder extends Wxapp{
$mobile = $this->input_param('mobile');
$address = $this->input_param('address');
$cardid = $this->input_param('cardid');
$delry_time = $this->input_param('delry_time');
$row = $this->customers_model->get(['id'=>$cus_id]);
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
if(!$row || !$series_row || !$cardid || !$address){
if(!$row || !$series_row || !$cardid || !$address ||!$delry_time){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
//判断是否存在未完成流程
@@ -118,6 +119,7 @@ class Cusorder extends Wxapp{
$payway && $data['payway'] = 1;
$pack_id && $data['pack_id'] = $pack_id;
$main_type && $data['main_type'] = 1;
$delry_time && $data['delry_time'] = $delry_time;
$info_json = [];
if($ifentrust){
$data['ifentrust'] = 1;
+51 -1
View File
@@ -14,4 +14,54 @@ class Auto_cars_model extends HD_Model{
{
parent::__construct($this->table_name, 'default');
}
}
//获取完整车辆信息
public function get_title($id){
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->load->model('auto/auto_attr_model');
$row = $this->get(['id'=>$id],'brand_id,s_id,v_id,cor_id,incor_id');
$b_row = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
$s_row = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
if($row){
$where = [
"id in ({$row['v_id']},{$row['cor_id']},{$row['incor_id']})" => null
];
$attr = $this->auto_attr_model->map('id','',$where,'','','','id,title');
}
$title = $b_row['name'].$s_row['name'];
$attr[$row['v_id']] && $title.= $attr[$row['v_id']][0]['title'];
$attr[$row['cor_id']] && $title.= "-".$attr[$row['cor_id']][0]['title'];
$attr[$row['incor_id']] && $title.= "-".$attr[$row['incor_id']][0]['title'];
return $title;
}
//获取车系品牌完整信息
public function select_car($where=[],$order,$page,$size,$fileds='',$count=''){
!$fileds && $fileds = "{$this->table_name}.*";
$this->db->select($fileds);
$this->db->from($this->table_name);
$this->db->join('lc_auto_brand', "lc_auto_brand.id = {$this->table_name}.brand_id");
$this->db->join('lc_auto_series', "lc_auto_series.id = {$this->table_name}.s_id");
if ($where) {
$this->db->where($where);
}
if ($count) {
return $this->db->count_all_results();
}
if ($order) {
$this->db->order_by($order);
}
if ($page) {
$offset = ($page - 1) * $page_size;
$limit = $page_size;
} else {
$offset = null;
$limit = null;
}
$this->db->limit($limit, $offset);
return $this->db->get()->result_array();
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auto_finance_model extends HD_Model{
private $table_name = 'lc_auto_car_finance';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
/**
* 期数
* @return array
*/
public function get_nums(){
$nums = [24];
return $nums;
}
/**
* 状态
* @return array
*/
function status_ary(){
$statusAry = ['0' => '关闭', '1' => '开启'];
return $statusAry;
}
}
+21 -1
View File
@@ -15,6 +15,26 @@ class Sys_finance_model extends HD_Model
parent::__construct($this->table_name, 'default');
}
/**
* 根据id获取数据
* @param $ids
* @param string $fileds
* @return array
*/
public function get_map_by_ids($ids, $fileds = '')
{
$rows = [];
$ids = array_filter($ids);
if ($ids) {
$cf_ids = implode(',', $ids);
$where = [
"id in ($cf_ids)" => null
];
$rows = $this->map('id', '', $where, '', '', '', $fileds);
}
return $rows;
}
/**
* 状态
* @return array
@@ -24,4 +44,4 @@ class Sys_finance_model extends HD_Model
return $statusAry;
}
}
}
+19
View File
@@ -101,3 +101,22 @@ create table lc_auto_fine (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车辆精品';
-- ----------------------------
-- Title:车型金融信息
-- Author:lcc
-- Table:lc_auto_car_finance
-- ---------------------------
drop table if exists lc_auto_car_finance;
create table lc_auto_car_finance (
id int(10) unsigned not null auto_increment comment '自增id',
car_id int(10) unsigned not null default '0' comment '车型库id',
fin_id int(10) unsigned not null default '0' comment '金融产品id',
first_pay decimal(12,2) not null default '0.00' comment '首付(万元)',
mouth_pay decimal(12,2) not null default '0.00' comment '月供',
srv_pay decimal(12,2) not null default '0.00' comment '服务费',
num int(3) unsigned not null default '0' comment '金融期数',
status tinyint(1) not null default '1' comment '状态:-1删除,0关闭,1开启',
c_time int(10) not null default '0' comment '创建时间',
u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型金融信息'
+1
View File
@@ -184,3 +184,4 @@ create table lc_receiver_orders (
alter table lc_receiver_orders add pack_id int(10) unsigned not null default 0 comment '服务包id' after incor_id;
alter table lc_receiver_orders add main_type tinyint(1) unsigned not null default 0 comment '购车主体(0个人 1公司)' after admin_id;
alter table lc_receiver_orders add ifentrust tinyint(1) unsigned not null default 0 comment '是否委托代办' after main_type;
alter table lc_receiver_orders add delry_time timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '期望交付时间' after status;