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 @@