From 355bd1cb95476562194f0bc879aa7d2a75074f35 Mon Sep 17 00:00:00 2001 From: xxb Date: Thu, 29 Jul 2021 20:04:10 +0800 Subject: [PATCH] liche update for admin company manger --- admin/controllers/biz/brand/Brand.php | 14 +- admin/controllers/sys/Company.php | 184 ++++++++++++++++++++++++ admin/views/biz/brand/edit.php | 12 +- admin/views/sys/city/lists.php | 11 +- admin/views/sys/company/get.php | 80 +++++++++++ admin/views/sys/company/lists.php | 89 ++++++++++++ common/models/sys/Sys_company_model.php | 28 ++++ sql/biz.sql | 3 +- sql/sys.sql | 17 +++ 9 files changed, 431 insertions(+), 7 deletions(-) create mode 100644 admin/controllers/sys/Company.php create mode 100644 admin/views/sys/company/get.php create mode 100644 admin/views/sys/company/lists.php create mode 100644 common/models/sys/Sys_company_model.php diff --git a/admin/controllers/biz/brand/Brand.php b/admin/controllers/biz/brand/Brand.php index 5d12e00c..4f5eb6ab 100755 --- a/admin/controllers/biz/brand/Brand.php +++ b/admin/controllers/biz/brand/Brand.php @@ -46,6 +46,9 @@ class Brand extends HD_Controller public function get() { $id = $this->input->get('id'); + + $this->load->model("sys/sys_company_model", 'company_model'); + if ($id) { $info = $this->bizBrand->get(array('id' => $id)); if (!$info || empty($info)) { @@ -53,13 +56,20 @@ class Brand extends HD_Controller } $action = '/biz/brand/brand/edit'; } else { - $info = array('type' => 0); + $info = array('type' => 0, 'company_id' => 0); $action = '/biz/brand/brand/add'; } + //获取公司ID列表 + $where = array('status' => 1); + $orderby = 'id desc'; + $select = 'id, title'; + $map_company = $this->company_model->map('id', 'title', $where, $orderby, 0, 0, $select); + $this->data['info'] = $info; $this->data['action'] = $action; $this->data['typeAry'] = $this->bizBrand->type_ary(); + $this->data['companyAry'] = $map_company; $this->data['_title'] = $id ? '编辑品牌' : '新增品牌'; return $this->show_view('biz/brand/edit'); } @@ -102,6 +112,7 @@ class Brand extends HD_Controller 'brand_name' => $brand_name, 'brand_logo' => $img, 'type' => intval($type), + 'company_id' => intval($info['company_id']), 'c_time' => time() ); $brand_id = $this->bizBrand->add($add_brand_data); @@ -139,6 +150,7 @@ class Brand extends HD_Controller 'brand_name' => $brand_name, 'brand_logo' => $img, 'type' => intval($type), + 'company_id' => intval($info['company_id']), ); $this->bizBrand->update($add_brand_data, array('id' => $id)); return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); diff --git a/admin/controllers/sys/Company.php b/admin/controllers/sys/Company.php new file mode 100644 index 00000000..27114fcd --- /dev/null +++ b/admin/controllers/sys/Company.php @@ -0,0 +1,184 @@ +load->model("sys/sys_company_model", 'company_model'); + + $this->log_dir = 'sys_' . get_class($this); + } + + public function index(){ + return $this->lists(); + } + + public function lists(){ + $params = $this->input->get(); + + $where = array(); + if ($params['keyword']){ + $where["(title like '%{$params['keyword']}%' or short like '%{$params['keyword']}%')"] = null; + } + + 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 = $this->company_model->status_ary(); + + $count = $this->company_model->count($where); + $lists = array(); + if($count){ + $orderby = 'id desc'; + $select = 'id, title, short, status'; + $rows = $this->company_model->select($where, $orderby, $page, $size, $select); + foreach($rows as $k => $v){ + $lists[] = array( + 'id' => $v['id'], + 'title' => $v['title'], + 'short' => $v['short'], + '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($count/$size),'curr'=>$page,'totle'=>$count); + $this->data['_title'] = '公司管理'; + $this->show_view('sys/company/lists',true); + } + + public function get(){ + $id = $this->input->get('id'); + if($id){ + $row = $this->company_model->get(array('id' => $id)); + $info = array( + 'id' => $row['id'], + 'title' => $row['title'], + 'short' => $row['short'], + 'status' => $row['status'], + ); + $action = '/sys/company/edit'; + $title = '编辑公司'; + } else { + $info = array( + 'title' => '', + 'short' => '', + 'status' => 0, + ); + $action = '/sys/company/add'; + $title = '新增公司'; + } + + $this->data['info'] = $info; + $this->data['action'] = $action; + $this->data['statusAry'] = $this->company_model->status_ary(); + $this->data['_title'] = $title; + $this->show_view('sys/company/get'); + } + + public function add(){ + $info = $this->input->post('info'); + $title = trim($info['title']); + if(!$title){ + return $this->show_json(SYS_CODE_FAIL, '请输入公司名称'); + } + + $where = array("title like '{$title}'" => null); + $count = $this->company_model->count($where); + if($count>0){ + return $this->show_json(SYS_CODE_FAIL, '公司已存在'); + } + + $add = array( + 'title' => $title, + 'short' => $info['short'] ? $info['short'] : '', + 'status' => intval($info['status']) + ); + + $id = $this->company_model->add($add); + if(!$id){ + debug_log("[error]# " . $this->company_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'); + $title = trim($info['title']); + if(!$title){ + return $this->show_json(SYS_CODE_FAIL, '请输入公司名称'); + } + + $where = array("title like '{$title}'" => null, "id<>{$info['id']}" => null); + $count = $this->company_model->count($where); + if($count>0){ + return $this->show_json(SYS_CODE_FAIL, '公司已存在'); + } + + $upd = array( + 'title' => $title, + 'short' => $info['short'] ? $info['short'] : '', + 'status' => intval($info['status']) + ); + + $ret = $this->company_model->update($upd, array('id' => $info['id'])); + if(!$ret){ + debug_log("[error]# " . $this->company_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->company_model->update($upd, $where); + if(!$ret){ + debug_log("[error]# " . $this->company_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/views/biz/brand/edit.php b/admin/views/biz/brand/edit.php index a7bcdbc0..a85c5f02 100755 --- a/admin/views/biz/brand/edit.php +++ b/admin/views/biz/brand/edit.php @@ -24,13 +24,22 @@
-
+
+
+ +
+ +
+
@@ -53,6 +62,7 @@ vm.info = ; vm.action = ''; vm.typeAry = ; + vm.companyAry = ; }, methods:{ saveEdit:function(){ diff --git a/admin/views/sys/city/lists.php b/admin/views/sys/city/lists.php index 758c2fad..8e528a50 100755 --- a/admin/views/sys/city/lists.php +++ b/admin/views/sys/city/lists.php @@ -26,7 +26,7 @@ 城市ID 城市名称 操作 - 区域 + 区域 @@ -37,14 +37,17 @@ 删除 - - 全选 - {{county.county_name}} + + + + + +
diff --git a/admin/views/sys/company/get.php b/admin/views/sys/company/get.php new file mode 100644 index 00000000..16486ce1 --- /dev/null +++ b/admin/views/sys/company/get.php @@ -0,0 +1,80 @@ +
+
+ +
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/admin/views/sys/company/lists.php b/admin/views/sys/company/lists.php new file mode 100644 index 00000000..5e702e0c --- /dev/null +++ b/admin/views/sys/company/lists.php @@ -0,0 +1,89 @@ + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + +
ID公司名称公司简称状态操作
{{v.id}}{{v.title}}{{v.short}}{{v.status_name}} + 编辑 + 关闭 + 开启 +
+
+
+
+
+
+ +
+
+
+ + diff --git a/common/models/sys/Sys_company_model.php b/common/models/sys/Sys_company_model.php new file mode 100644 index 00000000..913252ec --- /dev/null +++ b/common/models/sys/Sys_company_model.php @@ -0,0 +1,28 @@ +table_name, 'default'); + } + + /** + * 状态 + * @return array + */ + function status_ary(){ + $statusAry = array(/*'-1' => '删除',*/ '0' => '关闭', '1' => '开启'); + + return $statusAry; + } +} \ No newline at end of file diff --git a/sql/biz.sql b/sql/biz.sql index 1377990c..139af523 100644 --- a/sql/biz.sql +++ b/sql/biz.sql @@ -40,7 +40,8 @@ create table lc_biz_brand ( u_time timestamp not null default current_timestamp on update current_timestamp, primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='品牌表'; -alter table lc_biz_brand add column type tinyint(1) not null default 0 comment '类型:1-直营店,2-二网,3-合作店' after brand_logo; +alter table lc_biz_brand add column type tinyint(1) not null default 0 comment '类型:1-直营店,2-二网,3-合作店' after brand_logo; +alter table lc_biz_brand add column company_id int not null default 0 comment '公司ID' after type; -- ---------------------------- -- Title:商家标签关系 diff --git a/sql/sys.sql b/sql/sys.sql index e2e8b311..4a866120 100644 --- a/sql/sys.sql +++ b/sql/sys.sql @@ -187,3 +187,20 @@ create table lc_sys_tag_category ( status tinyint(1) not null default '1' comment '状态:-1删除,0禁用,1正常', primary key (id) ) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI COMMENT='系统标签分类表'; + + +-- ---------------------------- +-- Title:公司管理 +-- Author:xusir +-- Table:lc_sys_company +-- --------------------------- +drop table if exists lc_sys_company; +create table lc_sys_company ( + id int(10) unsigned not null auto_increment comment '自增id', + title varchar(64) not null comment '公司名称', + short varchar(32) not null default '' comment '公司简称', + status tinyint(1) not null default '1' comment '状态:-1删除,0关闭,1开启', + primary key (id) +) ENGINE=INNODB DEFAULT CHARSET=UTF8MB4 COLLATE=UTF8MB4_0900_AI_CI COMMENT='公司管理'; + +