diff --git a/admin/controllers/auto/Cars.php b/admin/controllers/auto/Cars.php new file mode 100644 index 00000000..7048f87b --- /dev/null +++ b/admin/controllers/auto/Cars.php @@ -0,0 +1,300 @@ +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->log_dir = "auto_" . get_class($this); + } + + public function index(){ + return $this->lists(); + } + + public function lists(){ + $params = $this->input->get(); + + $where = array(); + if($params['brand_id']){ + $where['brand_id'] = $params['brand_id']; + } else{ + $params['brand_id'] = ''; + } + + if($params['s_id']){ + $where['s_id'] = $params['s_id']; + } else{ + $params['s_id'] = ''; + } + 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; + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name'); + //状态 + $statusAry = array('0' => '关闭', '1' => '开启'); + + $total = $this->auto_cars_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = 'id,brand_id,s_id,attrs,status'; + $rows = $this->auto_cars_model->select($where, $orderby, $page, $size, $select); + if($rows){ + $s_ids = array(); + $attr_ids = array(); + foreach($rows as $v){ + !in_array($v['s_id'], $s_ids) && $s_ids[] = $v['s_id']; + $ids = explode('_', $v['attrs']); + $attr_ids = array_merge($attr_ids, $ids); + } + $attr_ids = array_unique($attr_ids); + //获取车系列表 + $map_sery = array(); + if($s_ids){ + $str_ids = implode(',', $s_ids); + $where_sery = array("id in ({$str_ids})" => null); + $map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name'); + } + $map_attr = array(); + if($attr_ids){ + $str_ids = implode(',', $attr_ids); + $where_attr = array("id in ({$str_ids})" => null); + $map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title'); + } + + foreach($rows as $v){ + $attr_ids = explode('_', $v['attrs']); + $attr_title = ''; + foreach($attr_ids as $attr_id){ + $attr_title .= $map_attr[$attr_id] . '-'; + } + $attr_title = trim($attr_title, '-'); + $lists[] = array( + 'id' => $v['id'], + 'brand_name' => $map_brand[$v['brand_id']], + 'sery_name' => $map_sery[$v['s_id']], + 'attr_title' => $attr_title, + 'status' => $v['status'], + 'status_name' => $statusAry[$v['status']] + ); + } + } + } + + $this->data['params'] = $params; + $this->data['lists'] = $lists; + $this->data['statusAry'] = $statusAry; + $this->data['brandAry'] = $map_brand; + $this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page, 'totle' => $total); + $this->data['_title'] = '车型库管理'; + $this->show_view('auto/cars/lists',true); + } + + public function get(){ + $id = $this->input->get('id'); + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name'); + //状态 + $statusAry = array('0' => '关闭', '1' => '开启'); + if($id){ + $row = $this->auto_cars_model->get(array('id' => $id)); + + //获取属性列表 + $attr_ids = explode('_', $row['attrs']); + $str_ids = implode(',', $attr_ids); + $where_attr = array("id in ({$str_ids})" => null); + $map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title'); + //属性分类 + $attr_types = $this->auto_attr_model->get_type(); + $attr = ""; + foreach($attr_ids as $k => $attr_id){ + $attr .= $map_attr[$attr_id]. "({$attr_types[$k]})-"; + } + $attr = trim($attr, '-'); + //车系 + $row_sery = $this->auto_series_model->get(array('id' => $row['s_id'])); + + $info = array( + 'id' => $row['id'], + 'brand_name' => $map_brand[$row['brand_id']], + 'sery_name' => $row_sery['name'], + 'attr' => $attr, + 'price_car' => $row['price_car'] > 0 ? $row['price_car'] : '', + 'price_insure' => $row['price_insure'] > 0 ? $row['price_insure'] : '', + 'price_fine' => $row['price_fine'] > 0 ? $row['price_fine'] : '', + 'price_finance' => $row['price_finance'] > 0 ? $row['price_finance'] : '', + 'first_pay' => $row['first_pay'] > 0 ? $row['first_pay'] : '', + 'price_coplus' => $row['price_coplus'] > 0 ? $row['price_coplus'] : '', + 'brokerage_1' => $row['brokerage_1'] > 0 ? $row['brokerage_1'] : '', + 'brokerage_2' => $row['brokerage_2'] > 0 ? $row['brokerage_2'] : '', + 'status' => $row['status'], + ); + + $title = '编辑车型库'; + $view = 'auto/cars/get'; + } else { + //新增车型库 + $info = array('brand_id' => '', 's_id' => ''); + $title = '新增车型库'; + $view = 'auto/cars/add'; + } + + $this->data['info'] = $info; + $this->data['statusAry'] = $statusAry; + $this->data['brandAry'] = $map_brand; + $this->data['_title'] = $title; + $this->show_view($view); + } + + public function add(){ + $info = $this->input->post('info'); + $brand_id = $info['brand_id']; + $s_id = $info['s_id']; + + $where = array('s_id' => $s_id); + $orderby = 'type asc, id asc'; + $select = 'id,type'; + $map = $this->auto_attr_model->map('type', '', $where, $orderby, 0, 0, $select); + $count = count($map); + if(!$count){ + return $this->show_json(SYS_CODE_FAIL, '该车系暂无属性!'); + } + $attrs = array_column($map[0], 'id');//属性组合 + for($i=1; $i<$count; $i++){ + $arr1 = $attrs; + $arr2 = $map[$i]; + $attrs = array(); + foreach($arr1 as $k1 => $v1){ + foreach($arr2 as $k2 => $v2){ + $attrs[] = "{$v1}_{$v2['id']}"; + } + } + } + + //车型库现有数据 + $where = array('s_id' => $s_id); + $map_cars = $this->auto_cars_model->map('attrs', '*', $where); + $adds = array(); + foreach($attrs as $attr){ + if($map_cars[$attr]){ + $map_cars[$attr]['ok'] = 1;//保留 + } else { + $adds[] = array( + 'brand_id' => $brand_id, + 's_id' => $s_id, + 'attrs' => $attr, + 'c_time' => time() + ); + } + } + //获取需要删除的车型库 + $del_ids = array(); + foreach($map_cars as $v){ + if(!$v['ok']){ + $del_ids[] = $v['id']; + } + } + + //删除旧库 + if($del_ids){ + $str_ids = implode(',', $del_ids); + $where = array("id in ({$str_ids})" => null); + $ret = $this->auto_cars_model->delete($where); + if(!$ret){ + debug_log("[error]#" . $this->auto_cars_model->db->last_query(), __FUNCTION__, $this->log_dir); + return $this->show_json(SYS_CODE_FAIL, '更新失败!'); + } + } + + //新增库 + if($adds){ + $ret = $this->auto_cars_model->add_batch($adds); + if(!$ret){ + debug_log("[error]#" . $this->auto_cars_model->db->last_query(), __FUNCTION__, $this->log_dir); + return $this->show_json(SYS_CODE_FAIL, '更新失败!'); + } + } + + return $this->show_json(SYS_CODE_SUCCESS, '更新成功!'); + } + + public function edit(){ + $info = $this->input->post('info'); + + $upd = array( + 'price_car' => floatval($info['price_car']), + 'price_insure' => floatval($info['price_insure']), + 'price_fine' => floatval($info['price_fine']), + 'price_finance' => floatval($info['price_finance']), + 'first_pay' => floatval($info['first_pay']), + 'price_coplus' => floatval($info['price_coplus']), + 'brokerage_1' => floatval($info['brokerage_1']), + 'brokerage_2' => floatval($info['brokerage_2']), + 'status' => $info['status'], + ); + + $where = array('id' => $info['id']); + $ret = $this->auto_cars_model->update($upd, $where); + if(!$ret){ + debug_log("[error]#" . $this->auto_cars_model->db->last_query(), __FUNCTION__, $this->log_dir); + return $this->show_json(SYS_CODE_FAIL, '更新失败!'); + } + + return $this->show_json(SYS_CODE_SUCCESS, '更新成功!'); + } + + function edit_status(){ + $id = $this->input->post('id'); + $status = $this->input->post('status'); + + $upd = array('status' => $status); + $where = array('id' => $id); + + $ret = $this->auto_cars_model->update($upd, $where); + if(!$ret){ + debug_log("[error]# " . $this->auto_cars_model->db->last_query(), __FUNCTION__, $this->log_dir); + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + public function del(){ + // TODO: Implement del() method. + } + + public function batch(){ + // TODO: Implement batch() method. + } + + public function export(){ + // TODO: Implement export() method. + } + +} \ No newline at end of file diff --git a/admin/controllers/auto/Series.php b/admin/controllers/auto/Series.php index 3ca323cb..80eefa47 100644 --- a/admin/controllers/auto/Series.php +++ b/admin/controllers/auto/Series.php @@ -52,6 +52,38 @@ class Series extends HD_Controller{ $this->show_view('auto/series/lists', true); } + /** + * 获取数据列表 + * @return bool + */ + public function json_lists(){ + $brand_id = $this->input->post('brand_id'); + $page = $this->input->post('page'); + $size = $this->input->post('size'); + + $where = array('status > -1' => null); + $brand_id && $where['brand_id'] = $brand_id; + $orderby = 'id desc'; + + $total = $this->auto_series_model->count($where); + + $lists = array(); + if($total){ + $select = 'id, name'; + $rows = $this->auto_series_model->select($where, $orderby, $page, $size, $select); + + foreach($rows as $v){ + $lists[] = array( + 'id' => $v['id'], + 'name' => $v['name'], + ); + } + } + + $this->data = array('total' => $total, 'list' => $lists); + return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + } + public function get(){ $id = $this->input->get('id'); diff --git a/admin/views/auto/cars/add.php b/admin/views/auto/cars/add.php new file mode 100644 index 00000000..52e40876 --- /dev/null +++ b/admin/views/auto/cars/add.php @@ -0,0 +1,112 @@ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/admin/views/auto/cars/get.php b/admin/views/auto/cars/get.php new file mode 100644 index 00000000..953d0c07 --- /dev/null +++ b/admin/views/auto/cars/get.php @@ -0,0 +1,141 @@ +
+
+ +
{{info.brand_name}}
+
+
+ +
{{info.sery_name}}
+
+
+ +
{{info.attr}}
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/admin/views/auto/cars/lists.php b/admin/views/auto/cars/lists.php new file mode 100644 index 00000000..b663092f --- /dev/null +++ b/admin/views/auto/cars/lists.php @@ -0,0 +1,136 @@ + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + +
ID品牌车系车型-车身-内饰状态操作
{{v.id}}{{v.brand_name}}{{v.sery_name}}{{v.attr_title}}{{v.status_name}} + 编辑 + 关闭 + 开启 +
+
+
+
+
+
+ +
+
+
+ + diff --git a/common/models/auto/Auto_attr_model.php b/common/models/auto/Auto_attr_model.php index a507bd11..ae598acd 100644 --- a/common/models/auto/Auto_attr_model.php +++ b/common/models/auto/Auto_attr_model.php @@ -8,7 +8,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class Auto_attr_model extends HD_Model{ private $table_name = 'lc_auto_attr'; - private $type_arr = [ 0 => '颜色', 1 => '型号', 2 => '内饰颜色']; + private $type_arr = [ 0 => '车身颜色', 1 => '型号', 2 => '内饰颜色']; private $status_arr = [ '-1' => '删除',0 => '下架',1 => '正常']; public function __construct() diff --git a/common/models/auto/Auto_cars_model.php b/common/models/auto/Auto_cars_model.php new file mode 100644 index 00000000..2a509d00 --- /dev/null +++ b/common/models/auto/Auto_cars_model.php @@ -0,0 +1,17 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/sql/auto.sql b/sql/auto.sql index f7d24d91..9e04db10 100644 --- a/sql/auto.sql +++ b/sql/auto.sql @@ -47,3 +47,31 @@ create table lc_auto_attr ( primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型属性'; alter table lc_auto_attr add status tinyint(1) not null default 1 comment '状态(-1删除 0禁用 1正常)' after jsondata; + +-- ---------------------------- +-- Title:车型库 +-- Author:xusir +-- Table:lc_auto_cars +-- ---------------------------- +-- attrs:属性组合,颜色ID_型号ID_内饰ID +-- ---------------------------- +drop table if exists lc_auto_cars; +create table lc_auto_cars ( + id int(10) not null auto_increment comment '自增id', + brand_id int(11) not null comment '品牌id', + s_id int(10) not null comment '车系id', + attrs char(30) not null comment '属性组合:{type0id}_{type1id}_{type2id}', + price_car double(10,2) not null default 0.0 comment '裸车报价', + price_insure double(10,2) not null default 0.0 comment '保险报价', + price_fine double(10,2) not null default 0.0 comment '精品报价', + price_finance double(10,2) not null default 0.0 comment '金融报价', + first_pay double(10,2) not null default 0.0 comment '分期首付', + price_coplus double(10,2) not null default 0.0 comment '公司加价', + brokerage_1 double(10,2) not null default 0.0 comment '一级分销佣金', + brokerage_2 double(10,2) not null default 0.0 comment '二级分销佣金', + status tinyint(1) not null default '0' comment '状态(1开启 0关闭 -1删除)', + u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间', + c_time int(10) not null default '0' comment '创建时间', + primary key (id), + unique(attrs) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型库';