From d257ddbe8701f06142e54e02810d640159de2eb2 Mon Sep 17 00:00:00 2001 From: xxb Date: Thu, 26 Aug 2021 16:47:34 +0800 Subject: [PATCH] liche update for admin goods add auto_fine --- admin/controllers/auto/Fine.php | 243 +++++++++++++++++++++ admin/controllers/items/goods/Goods.php | 56 +++++ admin/views/auto/fine/get.php | 76 +++++++ admin/views/auto/fine/lists.php | 90 ++++++++ admin/views/items/goods/edit.php | 227 ++++++++++++++++++- admin/views/items/goods/get_info.php | 51 ++++- common/models/auto/Auto_fine_model.php | 16 ++ common/models/items/Items_relate_model.php | 16 ++ sql/auto.sql | 18 ++ sql/item.sql | 14 ++ 10 files changed, 801 insertions(+), 6 deletions(-) create mode 100644 admin/controllers/auto/Fine.php create mode 100644 admin/views/auto/fine/get.php create mode 100644 admin/views/auto/fine/lists.php create mode 100644 common/models/auto/Auto_fine_model.php create mode 100644 common/models/items/Items_relate_model.php diff --git a/admin/controllers/auto/Fine.php b/admin/controllers/auto/Fine.php new file mode 100644 index 00000000..835db308 --- /dev/null +++ b/admin/controllers/auto/Fine.php @@ -0,0 +1,243 @@ +load->model('auto/auto_fine_model'); + + $this->log_dir = "auto_" . get_class($this); + } + + public function index(){ + return $this->lists(); + } + + public function lists(){ + $params = $this->input->get(); + + $statusAry = array(0 => '关闭', 1 => '开启'); + + $where = array(); + + if($params['title']){ + $where["title like '%{$params['title']}%'"] = null; + } + if(strlen($params['status']) > 0){ + $where['status'] = $params['status']; + } else{ + $where['status>-1'] = null; + $params['status'] = ''; + } + + $page = $params['page']; + $page = !$page ? 1 : $page; + $size = $params['size']; + $size = !$size ? 20 : $size; + + $total = $this->auto_fine_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = 'id, title, status'; + $rows = $this->auto_fine_model->select($where, $orderby, $page, $size, $select); + foreach($rows as $v){ + $lists[] = array( + 'id' => $v['id'], + 'title' => $v['title'], + 'status' => $v['status'], + 'status_name' => $statusAry[$v['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/fine/lists',true); + } + + public function get(){ + $id = $this->input->get('id'); + if($id){ + $row = $this->auto_fine_model->get(array('id' => $id)); + $info = array( + 'id' => $row['id'], + 'title' => $row['title'], + 'status' => $row['status'] + ); + $title = '编辑车辆精品'; + $action = 'auto/fine/edit'; + } else { + $info = array( + 'title' => '', + 'status' => 1, + ); + $title = '新增车辆精品'; + $action = 'auto/fine/add'; + } + + $statusAry = array(0 => '关闭', 1 => '开启'); + + $this->data['info'] = $info; + $this->data['statusAry'] = $statusAry; + $this->data['action'] = $action; + $this->data['_title'] = $title; + $this->show_view('auto/fine/get'); + } + + /** + * 新增精品 + * @return bool + */ + public function add(){ + $info = $this->input->post('info'); + if(!$info['title']){ + return $this->show_json(SYS_CODE_FAIL, '请输入精品名称'); + } + + $where = array("title" => trim($info['title'])); + $old = $this->auto_fine_model->get($where); + if($old && $old['status'] > -1){ + return $this->show_json(SYS_CODE_FAIL, '精品已经存在'); + } else if(-1 == $old['status']) { + //旧数据存在,更新 + $upd = array('status' => $info['status']); + $ret = $this->auto_fine_model->update($upd, array('id' => $old['id'])); + if(!$ret){ + debug_log('[error]# update fail; ' . $this->auto_fine_model->db->last_query(), __FUNCTION__, $this->log_dir); + return $this->show_json(SYS_CODE_FAIL, '添加失败'); + } + } else { + $add = array( + 'title' => $info['title'], + 'status' => $info['status'], + 'c_time' => time(), + ); + $ret = $this->auto_fine_model->add($add); + if(!$ret){ + debug_log('[error]# add fail; ' . $this->auto_fine_model->db->last_query(), __FUNCTION__, $this->log_dir); + return $this->show_json(SYS_CODE_FAIL, '添加失败'); + } + } + + return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + } + + /** + * 编辑 + * @return bool + */ + public function edit(){ + $info = $this->input->post('info'); + if(!$info['title']){ + return $this->show_json(SYS_CODE_FAIL, '请输入精品名称'); + } + + $where = array( + "title" => trim($info['title']), + "id<>{$info['id']}" => null, + "status>-1" => null + ); + $old = $this->auto_fine_model->get($where); + if($old){ + return $this->show_json(SYS_CODE_FAIL, '精品已经存在'); + } + + $upd = array('title' => $info['title'], 'status' => $info['status']); + $ret = $this->auto_fine_model->update($upd, array('id' => $info['id'])); + if(!$ret){ + debug_log('[error]# update fail; ' . $this->auto_fine_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'); + $stauts = $this->input->post('status'); + if (!$id) { + $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $where = array('id' => $id); + $this->auto_fine_model->update(array('status' => $stauts), $where); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + + public function del(){ + $id = $this->input->post('id'); + if (!$id) { + $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $where = array('id' => $id); + $ret = $this->auto_fine_model->update(array('status' => -1), $where); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + + public function batch(){ + // TODO: Implement batch() method. + } + + public function export(){ + // TODO: Implement export() method. + } + + /** + * @return bool + */ + function json_lists(){ + $id = $this->input->post('id'); + $title = trim($this->input->post('title')); + $status = $this->input->post('status'); + $page = $this->input->post('page'); + $size = $this->input->post('size'); + + $where = array(); + if($id){ + if(is_numeric($id)){ + $where['id'] = $id; + } else { + if(is_array($id)){ + $id = implode(',', $id); + } + $where["id in ({$id})"] = null; + } + } else { + $title && $where["title like '%{$title}%'"] = null; + if(strlen($status) > 0){ + $where['status'] = $status; + } else { + $where['status>-1'] = null; + } + } + + $total = $this->auto_fine_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = 'id, title'; + $rows = $this->auto_fine_model->select($where, $orderby, $page, $size, $select); + + foreach($rows as $v){ + $lists[] = array( + 'id' => $v['id'], + 'title' => $v['title'], + ); + } + } + + $this->data = array('total' => $total, 'list' => $lists); + return $this->show_json(SYS_CODE_SUCCESS); + } +} \ No newline at end of file diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 0006323b..e6825ae3 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -14,6 +14,7 @@ class Goods extends HD_Controller { parent::__construct(); $this->load->model('items/items_model', 'mdItems'); + $this->load->model('items/items_relate_model'); $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); $this->load->model('auto/auto_series_model', 'mdAutoSeries'); $this->load->model('auto/auto_attr_model', 'mdAutoAttr'); @@ -167,12 +168,19 @@ class Goods extends HD_Controller $info['addr_id'] = ''; } + //获取精品加装 + $where = array('item_id' => $id, 'type' => 1, 'status' => 1); + $rows_fine = $this->items_relate_model->select($where, '', 0, 0, 'type_id'); + $fine_ids = $rows_fine ? array_column($rows_fine, 'type_id') : array(); + $info['fine_ids'] = $fine_ids; + $_title = '编辑商品'; $edit_url = '/items/goods/goods/edit'; } else { $info['city_id'] = ''; $info['county_id'] = ''; $info['addr_id'] = ''; + $info['fine_ids'] = array(); $_title = '新增商品'; $edit_url = '/items/goods/goods/add'; } @@ -224,6 +232,13 @@ class Goods extends HD_Controller } else { $info['address'] = ''; } + + //获取精品加装 + $where = array('item_id' => $id, 'type' => 1, 'status' => 1); + $rows_fine = $this->items_relate_model->select($where, '', 0, 0, 'type_id'); + $fine_ids = $rows_fine ? array_column($rows_fine, 'type_id') : array(); + $info['fine_ids'] = $fine_ids; + $this->data['info'] = $info; return $this->show_view('/items/goods/get_info'); } @@ -282,6 +297,21 @@ class Goods extends HD_Controller if (!$id) { return $this->show_json(SYS_CODE_FAIL, '添加失败!'); } + + //保存精品 + if($info['fine_ids']){ + $adds = array(); + foreach($info['fine_ids'] as $fine_id){ + $adds[] = array( + 'item_id' => $id, + 'type' => 1, + 'type_id' => $fine_id, + 'status' => 1 + ); + } + $ret = $this->items_relate_model->add_batch($adds); + } + $this->data['status'] = 1; return $this->show_json(SYS_CODE_SUCCESS, '添加成功!'); } @@ -390,6 +420,32 @@ class Goods extends HD_Controller if (!$ret) { return $this->show_json(SYS_CODE_FAIL, '修改失败!'); } + + //保存精品 + $where = array('item_id' => $info['id'], 'type' => 1); + //删除旧数据 + $this->items_relate_model->update(array('status' => -1), $where); + $map_relate = $this->items_relate_model->map('type_id', 'status', $where); + if($info['fine_ids']){ + $adds = array(); + foreach($info['fine_ids'] as $fine_id){ + if(!$map_relate[$fine_id]){ + //新增 + $adds[] = array( + 'item_id' => $info['id'], + 'type' => 1, + 'type_id' => $fine_id, + 'status' => 1 + ); + } else { + //启用旧数据 + $where = array('item_id' => $info['id'], 'type' => 1, 'type_id' => $fine_id); + $this->items_relate_model->update(array('status' => 1), $where); + } + } + $adds && $this->items_relate_model->add_batch($adds); + } + $this->data['status'] = 2; return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); } diff --git a/admin/views/auto/fine/get.php b/admin/views/auto/fine/get.php new file mode 100644 index 00000000..3cb069b4 --- /dev/null +++ b/admin/views/auto/fine/get.php @@ -0,0 +1,76 @@ +
+
+ +
+
+
+ +
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/admin/views/auto/fine/lists.php b/admin/views/auto/fine/lists.php new file mode 100644 index 00000000..eea60f43 --- /dev/null +++ b/admin/views/auto/fine/lists.php @@ -0,0 +1,90 @@ + +
+
+ +
+
+
共有条数据
+ + + + + + + + + + + + + + + + + +
ID名称状态操作
{{v.id}}{{v.title}}{{v.status_name}} + 编辑 + 关闭 + 开启 + 删除 +
+
+
+
+
+
+ +
+
+
+ + diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php index aa255b44..1d08b840 100644 --- a/admin/views/items/goods/edit.php +++ b/admin/views/items/goods/edit.php @@ -1,3 +1,41 @@ + + +
@@ -66,10 +104,20 @@
- + + +
精品加装
- +
+
+ {{v.title}} + +
+
+
@@ -211,6 +259,62 @@
+ diff --git a/common/models/auto/Auto_fine_model.php b/common/models/auto/Auto_fine_model.php new file mode 100644 index 00000000..4fcd52aa --- /dev/null +++ b/common/models/auto/Auto_fine_model.php @@ -0,0 +1,16 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/common/models/items/Items_relate_model.php b/common/models/items/Items_relate_model.php new file mode 100644 index 00000000..e6d5bbe3 --- /dev/null +++ b/common/models/items/Items_relate_model.php @@ -0,0 +1,16 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/sql/auto.sql b/sql/auto.sql index 0c0c25dd..6569d0aa 100644 --- a/sql/auto.sql +++ b/sql/auto.sql @@ -77,3 +77,21 @@ create table lc_auto_cars ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型库'; alter table lc_auto_cars add column month_pay double(10,2) not null default 0.0 comment '月供' after first_pay; alter table lc_auto_cars add column price_book double(10,2) not null default 0.0 comment '定金' after price_car; + + +-- ---------------------------- +-- Title:车辆精品 +-- Author:xusir +-- Table:lc_auto_fine +-- --------------------------- +drop table if exists lc_auto_fine; +create table lc_auto_fine ( + id int(10) not null auto_increment comment '自增id', + title varchar(50) not null default '' 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) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车辆精品'; + + diff --git a/sql/item.sql b/sql/item.sql index 2c79fc60..32b39729 100644 --- a/sql/item.sql +++ b/sql/item.sql @@ -37,3 +37,17 @@ alter table lc_items drop column frame_num; alter table lc_items modify if_pack varchar(256) not null default '' comment '精品加装'; alter table lc_items add column addr_id int unsigned not null default 0 comment '存放地址ID' after address; +-- ---------------------------- +-- Title:商品关联 +-- Author:xusir +-- Table:lc_items_relate +-- --------------------------- +drop table if exists lc_items_relate; +create table lc_items_relate ( + item_id int unsigned not null comment '商品id', + type varchar(50) not null default '0' comment '1-精品', + type_id int unsigned not null comment '类型ID', + status tinyint(1) not null default 1 comment '状态:-1删除,1正常', + primary key (item_id,type,type_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='商品关联'; +