From 53c2c9e13da16409e25907dfeee28b6f03541565 Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Wed, 8 Sep 2021 18:01:59 +0800 Subject: [PATCH] add-auto-finance --- admin/controllers/auto/Finance.php | 247 ++++++++++++++++++++++ admin/controllers/sys/Finance.php | 2 +- admin/views/auto/finance/get.php | 202 ++++++++++++++++++ admin/views/auto/finance/lists.php | 97 +++++++++ api/controllers/wxapp/licheb/Cusorder.php | 4 +- common/models/auto/Auto_cars_model.php | 52 ++++- common/models/auto/Auto_finance_model.php | 28 +++ common/models/sys/Sys_finance_model.php | 22 +- sql/auto.sql | 19 ++ sql/receiver/order.sql | 1 + 10 files changed, 670 insertions(+), 4 deletions(-) create mode 100644 admin/controllers/auto/Finance.php create mode 100644 admin/views/auto/finance/get.php create mode 100644 admin/views/auto/finance/lists.php create mode 100644 common/models/auto/Auto_finance_model.php diff --git a/admin/controllers/auto/Finance.php b/admin/controllers/auto/Finance.php new file mode 100644 index 00000000..96604652 --- /dev/null +++ b/admin/controllers/auto/Finance.php @@ -0,0 +1,247 @@ +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, '保存成功'); + } +} diff --git a/admin/controllers/sys/Finance.php b/admin/controllers/sys/Finance.php index 3e0dccea..c74cb18f 100644 --- a/admin/controllers/sys/Finance.php +++ b/admin/controllers/sys/Finance.php @@ -196,4 +196,4 @@ class Finance extends HD_Controller{ public function export(){ // TODO: Implement export() method. } -} \ No newline at end of file +} diff --git a/admin/views/auto/finance/get.php b/admin/views/auto/finance/get.php new file mode 100644 index 00000000..0c4e8e40 --- /dev/null +++ b/admin/views/auto/finance/get.php @@ -0,0 +1,202 @@ +
+ diff --git a/admin/views/auto/finance/lists.php b/admin/views/auto/finance/lists.php new file mode 100644 index 00000000..35d76900 --- /dev/null +++ b/admin/views/auto/finance/lists.php @@ -0,0 +1,97 @@ + + + + diff --git a/api/controllers/wxapp/licheb/Cusorder.php b/api/controllers/wxapp/licheb/Cusorder.php index 87c8a6df..804c90bb 100644 --- a/api/controllers/wxapp/licheb/Cusorder.php +++ b/api/controllers/wxapp/licheb/Cusorder.php @@ -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; diff --git a/common/models/auto/Auto_cars_model.php b/common/models/auto/Auto_cars_model.php index 2a509d00..66904e9b 100644 --- a/common/models/auto/Auto_cars_model.php +++ b/common/models/auto/Auto_cars_model.php @@ -14,4 +14,54 @@ class Auto_cars_model extends HD_Model{ { parent::__construct($this->table_name, 'default'); } -} \ No newline at end of file + + //获取完整车辆信息 + 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(); + } +} diff --git a/common/models/auto/Auto_finance_model.php b/common/models/auto/Auto_finance_model.php new file mode 100644 index 00000000..06e6ad40 --- /dev/null +++ b/common/models/auto/Auto_finance_model.php @@ -0,0 +1,28 @@ +table_name, 'default'); + } + /** + * 期数 + * @return array + */ + public function get_nums(){ + $nums = [24]; + return $nums; + } + + /** + * 状态 + * @return array + */ + function status_ary(){ + $statusAry = ['0' => '关闭', '1' => '开启']; + + return $statusAry; + } +} diff --git a/common/models/sys/Sys_finance_model.php b/common/models/sys/Sys_finance_model.php index 07312236..3b676347 100644 --- a/common/models/sys/Sys_finance_model.php +++ b/common/models/sys/Sys_finance_model.php @@ -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; } -} \ No newline at end of file +} diff --git a/sql/auto.sql b/sql/auto.sql index 6d468640..378b3249 100644 --- a/sql/auto.sql +++ b/sql/auto.sql @@ -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='车型金融信息' diff --git a/sql/receiver/order.sql b/sql/receiver/order.sql index e3f81639..64379b67 100644 --- a/sql/receiver/order.sql +++ b/sql/receiver/order.sql @@ -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;