diff --git a/admin/controllers/auto/Attr.php b/admin/controllers/auto/Attr.php new file mode 100644 index 00000000..6c5da5d2 --- /dev/null +++ b/admin/controllers/auto/Attr.php @@ -0,0 +1,140 @@ +load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_attr_model'); + } + + public function index(){ + $this->lists(); + } + + public function lists(){ + $params = $this->input->get(); + $page = $this->input->get('page'); + !$page && $page = 1; + $size = 20; + $where["status > -1"] = null; + $params['title'] && $where["title like '%{$params['title']}%'"] = null; + $count = $this->auto_attr_model->count($where); + $rows = $this->auto_attr_model->select($where, 'id desc', $page, $size); + $type_arr = $this->auto_attr_model->get_type(); + $status_arr = $this->auto_brand_model->get_status(); + $list = []; + if($rows){ + $series_arr = array_column($rows,'s_id'); + $series_rows = $this->auto_series_model->get_map_by_ids($series_arr,'id,name'); + foreach($rows as $key=>$val){ + $list[] = [ + 'id' => $val['id'], + 'title' => $val['title'], + 's_name' => $series_rows[$val['s_id']] ? $series_rows[$val['s_id']][0]['name'] : '', + 'status_name' => $status_arr[$val['status']], + 'type_cn' => $type_arr[$val['type']], + 'c_time' => date('Y-m-d H:i:s',$val['c_time']) + ]; + } + } + $this->data['lists'] = $list; + $this->data['params'] = $params; + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['_title'] = '属性管理'; + $this->show_view('auto/attr/lists', true); + } + + public function get(){ + $id = $this->input->get('id'); + + $info = [ + 'title' => '' + ]; + if ($id) { + $info = $this->auto_attr_model->get(array('id' => $id)); + if (!$info || empty($info)) { + return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); + } + $info['jsondata'] = json_decode($info['jsondata'],true); + $info['jsondata']['img'] && $info['jsondata']['s_img'] = build_qiniu_image_url($info['jsondata']['img']); + } + $series = $this->auto_series_model->select([],'','','','id,name'); + $type_arr = $this->auto_attr_model->get_type(); + !$info['type'] && $info['type'] = 0; + !$info['s_id'] && $info['s_id'] = $series[0]['id']; + !$info['jsondata']['img'] && $info['jsondata']['img'] = ''; + $this->data['series'] = $series; + $this->data['type_arr'] = $type_arr; + $this->data['info'] = $info; + $this->data['_title'] = $id ? '编辑' : '新增'; + return $this->show_view('auto/attr/edit',true); + } + + public function add(){ + if (!$this->if_ajax) { + return $this->show_json(SYS_CODE_FAIL, '提交出错!'); + } + $post = $this->input->post(); + if (!$post['title']) { + return $this->show_json(SYS_CODE_FAIL, '标题不能为空'); + } + $add_data = [ + 'title' => $post['title'], + 's_id' => $post['s_id'], + 'type' => $post['type'], + 'c_time' => time() + ]; + $post['jsondata'] && $add_data['jsondata'] = json_encode($post['jsondata'],JSON_UNESCAPED_UNICODE); + $result = $this->auto_attr_model->add($add_data); + if (!$result) { + return $this->show_json(SYS_CODE_FAIL, '添加失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + } + + public function edit(){ + if (!$this->if_ajax) { + return $this->show_json(SYS_CODE_FAIL, '提交出错!'); + } + $post = $this->input->post(); + $row = $this->auto_attr_model->get(['id'=>$post['id']]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL, '数据不存在'); + } + if (!$post['title']) { + return $this->show_json(SYS_CODE_FAIL, '标题不能为空'); + } + $update = [ + 'title' => $post['title'], + 's_id' => $post['s_id'], + 'type' => $post['type'], + ]; + $post['jsondata'] && $update['jsondata'] = json_encode($post['jsondata'],JSON_UNESCAPED_UNICODE); + $result = $this->auto_attr_model->update($update,['id'=>$row['id']]); + if (!$result) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + public function del(){ + } + + public function batch(){ + + } + + public function export(){ + + } + +} diff --git a/admin/controllers/auto/Series.php b/admin/controllers/auto/Series.php index b1bc86f4..3ca323cb 100644 --- a/admin/controllers/auto/Series.php +++ b/admin/controllers/auto/Series.php @@ -62,7 +62,8 @@ class Series extends HD_Controller{ return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); } } - + $brands = $this->auto_brand_model->select([],'','','','id,name'); + $this->data['brands'] = $brands; $this->data['info'] = $info; $this->data['_title'] = $id ? '编辑车系' : '新增车系'; return $this->show_view('auto/series/edit'); @@ -74,7 +75,7 @@ class Series extends HD_Controller{ } $id = $this->input->post('id'); $name = $this->input->post('name'); - $img = $this->input->post('img'); + $brand_id = $this->input->post('brand_id'); if (!$name || empty($name)) { return $this->show_json(SYS_CODE_FAIL, '车系名称不能为空'); } @@ -84,7 +85,7 @@ class Series extends HD_Controller{ } $add_data = array( 'name' => $name, - 'logo' => $img, + 'brand_id' => $brand_id, 'c_time' => time() ); $brand_id = $this->auto_series_model->add($add_data); @@ -100,8 +101,8 @@ class Series extends HD_Controller{ } $id = $this->input->post('id'); $name = $this->input->post('name'); - $img = $this->input->post('img'); - $row = $this->auto_brand_model->get(['id' => $id]); + $brand_id = $this->input->post('brand_id'); + $row = $this->auto_series_model->get(['id' => $id]); if (!$row) { return $this->show_json(SYS_CODE_FAIL, '数据不存在!'); } @@ -116,10 +117,10 @@ class Series extends HD_Controller{ return $this->show_json(SYS_CODE_FAIL, '车系已经存在'); } $up_data = array( + 'brand_id' => $brand_id, 'name' => $name, ); - $img && $up_data['logo'] = $img; - $this->auto_brand_model->update($up_data, array('id' => $id)); + $this->auto_series_model->update($up_data, array('id' => $id)); return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } diff --git a/admin/views/auto/attr/edit.php b/admin/views/auto/attr/edit.php new file mode 100755 index 00000000..80e42f98 --- /dev/null +++ b/admin/views/auto/attr/edit.php @@ -0,0 +1,112 @@ +
+ diff --git a/admin/views/auto/attr/lists.php b/admin/views/auto/attr/lists.php new file mode 100755 index 00000000..056b00f5 --- /dev/null +++ b/admin/views/auto/attr/lists.php @@ -0,0 +1,59 @@ +| ID | +标题 | +车系名称 | +类型 | +状态 | +创建时间 | +操作 | +
|---|---|---|---|---|---|---|
| = $v['id'] ?> | += $v['title'] ?> | += $v['s_name'] ?> | += $v['type_cn'] ?> | += $v['status_name'] ?> | += $v['c_time'] ?> | ++ = '编辑' ?> + | +