From 057fd4d5a44e7d16eba7b8c594c822ef21995a66 Mon Sep 17 00:00:00 2001 From: xxb Date: Fri, 20 Aug 2021 20:25:48 +0800 Subject: [PATCH] liche update for admin auto and goods edit --- admin/controllers/Common.php | 16 +- admin/controllers/auto/Attr.php | 23 ++ admin/controllers/auto/Cars.php | 27 +++ admin/controllers/auto/Series.php | 15 +- admin/controllers/items/goods/Goods.php | 19 ++ admin/controllers/sys/Addr.php | 281 ++++++++++++++++++++++++ admin/views/auto/attr/lists.php | 75 +++++++ admin/views/auto/cars/lists.php | 6 +- admin/views/auto/series/lists.php | 31 +++ admin/views/items/goods/edit.php | 144 ++++++++++-- admin/views/receiver/clues/edit.php | 5 +- admin/views/receiver/orders/get.php | 8 +- admin/views/receiver/orders/oinfo.php | 7 +- admin/views/sys/addr/get.php | 127 +++++++++++ admin/views/sys/addr/lists.php | 152 +++++++++++++ common/models/sys/Sys_addr_model.php | 16 ++ sql/item.sql | 1 + sql/sys.sql | 21 ++ 18 files changed, 944 insertions(+), 30 deletions(-) create mode 100644 admin/controllers/sys/Addr.php create mode 100644 admin/views/sys/addr/get.php create mode 100644 admin/views/sys/addr/lists.php create mode 100644 common/models/sys/Sys_addr_model.php diff --git a/admin/controllers/Common.php b/admin/controllers/Common.php index 9b41c4d2..7102fbfa 100644 --- a/admin/controllers/Common.php +++ b/admin/controllers/Common.php @@ -1401,14 +1401,20 @@ class Common extends CI_Controller $v_id = $this->input->post('v_id'); $cor_id = $this->input->post('cor_id'); $incor_id = $this->input->post('incor_id'); + $vin = $this->input->post('vin'); $page = $this->input->post('page') ? intval($this->input->post('page')) : 1; $size = $this->input->post('size') ? intval($this->input->post('size')) : 10; $where = "status=1 "; - $brand_id && $where .= " and brand_id=$brand_id"; - $s_id && $where .= " and s_id=$s_id"; - $v_id && $where .= " and v_id=$v_id"; - $cor_id && $where .= " and cor_id=$cor_id"; - $incor_id && $where .= " and incor_id=$incor_id"; + if($vin){ + $where .= " and vin='{$vin}'"; + } else { + $brand_id && $where .= " and brand_id=$brand_id"; + $s_id && $where .= " and s_id=$s_id"; + $v_id && $where .= " and v_id=$v_id"; + $cor_id && $where .= " and cor_id=$cor_id"; + $incor_id && $where .= " and incor_id=$incor_id"; + } + if ($select_id) { $fhwhere = [ "($where) or (id=$select_id)" => null diff --git a/admin/controllers/auto/Attr.php b/admin/controllers/auto/Attr.php index 6c5da5d2..c736a771 100644 --- a/admin/controllers/auto/Attr.php +++ b/admin/controllers/auto/Attr.php @@ -27,10 +27,32 @@ class Attr extends HD_Controller{ $size = 20; $where["status > -1"] = null; $params['title'] && $where["title like '%{$params['title']}%'"] = null; + + if($params['s_id']){ + $where['s_id'] = $params['s_id']; + }if($params['brand_id']){ + $where_sery = array('status > -1' => null, 'brand_id' => $params['brand_id']); + $rows_sery = $this->auto_series_model->select($where_sery, 'id desc', 0, 0, 'id'); + if($rows_sery){ + $sery_ids = array_column($rows_sery, 'id'); + $str_ids = implode(',', $sery_ids); + $where["s_id in ({$str_ids})"] = null; + } else { + $where['s_id'] = -1; + } + } + !$params['s_id'] && $params['s_id'] = ''; + !$params['brand_id'] && $params['brand_id'] = ''; + $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(); + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name'); + $list = []; if($rows){ $series_arr = array_column($rows,'s_id'); @@ -48,6 +70,7 @@ class Attr extends HD_Controller{ } $this->data['lists'] = $list; $this->data['params'] = $params; + $this->data['brandAry'] = $map_brand; $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); $this->data['_title'] = '属性管理'; $this->show_view('auto/attr/lists', true); diff --git a/admin/controllers/auto/Cars.php b/admin/controllers/auto/Cars.php index 7f1f05ae..de433ef3 100644 --- a/admin/controllers/auto/Cars.php +++ b/admin/controllers/auto/Cars.php @@ -316,4 +316,31 @@ class Cars extends HD_Controller{ // TODO: Implement export() method. } + /** + * 获取车型库信息 + * @return bool + */ + function json_get(){ + $brand_id = $this->input->post('brand_id'); + $s_id = $this->input->post('s_id'); + $attrs = $this->input->post('attrs'); + + $where = array( + 'status' => 1, + 'brand_id' => $brand_id, + 's_id' => $s_id, + 'attrs' => $attrs + ); + $row = $this->auto_cars_model->get($where); + + $data = array( + 'id' => $row['id'], + 'price_car' => $row['price_car'] + ); + + $this->data = $data; + + return $this->show_json(SYS_CODE_SUCCESS); + } + } \ No newline at end of file diff --git a/admin/controllers/auto/Series.php b/admin/controllers/auto/Series.php index 80eefa47..5b60bc21 100644 --- a/admin/controllers/auto/Series.php +++ b/admin/controllers/auto/Series.php @@ -26,15 +26,23 @@ class Series extends HD_Controller{ $size = 20; $where["status > -1"] = null; $params['title'] && $where["name like '%{$params['title']}%'"] = null; + if($params['brand_id']){ + $where['brand_id'] = $params['brand_id']; + } else { + $params['brand_id'] = ''; + } $count = $this->auto_series_model->count($where); $rows = $this->auto_series_model->select($where, 'id desc', $page, $size); $status_arr = $this->auto_series_model->get_status(); $list = []; + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name'); + if($rows){ - $brand_arr = array_column($rows,'brand_id'); - $brand_rows = $this->auto_brand_model->get_map_by_ids($brand_arr,'id,name'); foreach($rows as $key=>$val){ - $brand_name = $brand_rows[$val['brand_id']] ? $brand_rows[$val['brand_id']][0]['name'] : ''; + $brand_name = $map_brand[$val['brand_id']] ? $map_brand[$val['brand_id']] : ''; $list[] = [ 'id' => $val['id'], 'brand_name' => $brand_name, @@ -47,6 +55,7 @@ class Series extends HD_Controller{ } $this->data['lists'] = $list; $this->data['params'] = $params; + $this->data['brandAry'] = $map_brand; $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); $this->data['_title'] = '车系列表'; $this->show_view('auto/series/lists', true); diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 092429c7..b45cd859 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -109,9 +109,24 @@ class Goods extends HD_Controller $autoList[4] = $this->mdAutoAttr->select(array('type' => 0, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); $autoList[5] = $this->mdAutoAttr->select(array('type' => 2, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name'); } + + if($info['addr_id']){ + $this->load->model("sys/sys_addr_model", 'addr_model'); + $row_addr = $this->addr_model->get(array('id' => $info['addr_id'])); + $info['city_id'] = $row_addr['city_id']; + $info['county_id'] = $row_addr['county_id']; + } else { + $info['city_id'] = ''; + $info['county_id'] = ''; + $info['addr_id'] = ''; + } + $_title = '编辑商品'; $edit_url = '/items/goods/goods/edit'; } else { + $info['city_id'] = ''; + $info['county_id'] = ''; + $info['addr_id'] = ''; $_title = '新增商品'; $edit_url = '/items/goods/goods/add'; } @@ -209,6 +224,8 @@ class Goods extends HD_Controller $addData['out_time'] = $info['out_time'] ? $info['out_time'] : '0000-00-00 00:00:00'; $addData['bill_time'] = $info['bill_time'] ? $info['bill_time'] : '0000-00-00 00:00:00'; $addData['c_time'] = time(); + //存货地址 + $addData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0; $id = $this->mdItems->add($addData); if (!$id) { return $this->show_json(SYS_CODE_FAIL, '添加失败!'); @@ -248,6 +265,8 @@ class Goods extends HD_Controller $editData['p_time'] = $info['p_time']; $editData['out_time'] = $info['out_time']; $editData['bill_time'] = $info['bill_time']; + //存货地址 + $editData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0; $ret = $this->mdItems->update($editData, array('id' => $info['id'])); if (!$ret) { return $this->show_json(SYS_CODE_FAIL, '修改失败!'); diff --git a/admin/controllers/sys/Addr.php b/admin/controllers/sys/Addr.php new file mode 100644 index 00000000..06f6e117 --- /dev/null +++ b/admin/controllers/sys/Addr.php @@ -0,0 +1,281 @@ +load->model("sys/sys_addr_model", 'addr_model'); + $this->load->model("area_model"); + + $this->log_dir = 'sys_' . get_class($this); + } + + public function index(){ + return $this->lists(); + } + + public function lists(){ + $params = $this->input->get(); + $page = $params['page']; + $page = !$page ? 1 : $page; + $size = $params['size']; + $size = !$size ? 20 : $size; + + $where = array('province_id' => '350'); + if($params['title']){ + $where["title like '%{$params['title']}%'"] = null; + } + + if($params['city_id']){ + $where['city_id'] = $params['city_id']; + } else { + $params['city_id'] = ''; + } + + if($params['county_id']){ + $where['county_id'] = $params['county_id']; + } else { + $params['county_id'] = ''; + } + + if(strlen($params['status'])>0){ + $where['status'] = $params['status']; + } else { + $where['status>-1'] = null; + $params['status'] = ''; + } + + $total = $this->addr_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = 'id, title, city_name, county_name, status'; + $rows = $this->addr_model->select($where, $orderby, $page, $size, $select); + foreach($rows as $v){ + $lists[] = array( + 'id' => $v['id'], + 'title' => $v['title'], + 'city_name' => $v['city_name'], + 'county_name' => $v['county_name'], + 'status' => $v['status'], + 'status_name' => 1 == $v['status'] ? '开启' : '停用', + ); + } + } + + $this->data['params'] = $params; + $this->data['lists'] = $lists; + $this->data['pager'] = array('count'=>ceil($total/$size),'curr'=>$page,'totle'=>$total); + $this->data['_title'] = '地址管理'; + $this->show_view('sys/addr/lists',true); + } + + function json_lists(){ + $params = $this->input->get(); + $page = $params['page']; + $size = $params['size']; + + $where = array('province_id' => '350'); + if($params['title']){ + $where["title like '%{$params['title']}%'"] = null; + } + + if($params['city_id']){ + $where['city_id'] = $params['city_id']; + } else { + $params['city_id'] = ''; + } + + if($params['county_id']){ + $where['county_id'] = $params['county_id']; + } else { + $params['county_id'] = ''; + } + + if(strlen($params['status'])>0){ + $where['status'] = $params['status']; + } else { + $where['status>-1'] = null; + $params['status'] = ''; + } + + $total = $this->addr_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = 'id, title'; + $rows = $this->addr_model->select($where, $orderby, $page, $size, $select); + foreach($rows as $v){ + $lists[] = array( + 'id' => $v['id'], + 'title' => $v['title'], + ); + } + } + + $this->data['lists'] = $lists; + $this->data['total'] = $total; + return $this->show_json(SYS_CODE_SUCCESS); + } + + public function get(){ + $id = $this->input->get('id'); + if($id){ + $row = $this->addr_model->get(array('id' => $id)); + $info = array( + 'id' => $row['id'], + 'title' => $row['title'], + 'city_id' => $row['city_id'], + 'county_id' => $row['county_id'], + ); + $action = '/sys/addr/edit'; + $title = '编辑地址'; + } else { + $info = array( + 'title' => '', + 'city_id' => '', + 'county_id' => '', + ); + $action = '/sys/addr/add'; + $title = '新增地址'; + } + + $this->data['info'] = $info; + $this->data['action'] = $action; + $this->data['_title'] = $title; + $this->show_view('sys/addr/get'); + } + + public function add(){ + $info = $this->input->post('info'); + $title = trim($info['title']); + $city_id = $info['city_id']; + $county_id = $info['county_id']; + if(!$title){ + return $this->show_json(SYS_CODE_FAIL, '请输入地址'); + } + if(!$city_id){ + return $this->show_json(SYS_CODE_FAIL, '请选择城市'); + } + if(!$county_id){ + return $this->show_json(SYS_CODE_FAIL, '请选行政区'); + } + + $where = array("title like '{$title}'" => null); + $count = $this->addr_model->count($where); + if($count>0){ + return $this->show_json(SYS_CODE_FAIL, '地址已存在'); + } + + //获取行政区信息 + $where = array('county_id' => $county_id); + $row_area = $this->area_model->get($where); + if(!$row_area){ + return $this->show_json(SYS_CODE_FAIL, '行政区不存在'); + } + + $add = array( + 'title' => $title, + 'province_id' => $row_area['province_id'], + 'province_name' => $row_area['province_name'], + 'city_id' => $row_area['city_id'], + 'city_name' => $row_area['city_name'], + 'county_id' => $row_area['county_id'], + 'county_name' => $row_area['county_name'], + 'status' => 1 + ); + + $ret = $this->addr_model->add($add); + if(!$ret){ + debug_log("[error]# " . $this->addr_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']); + $city_id = $info['city_id']; + $county_id = $info['county_id']; + if(!$title){ + return $this->show_json(SYS_CODE_FAIL, '请输入地址'); + } + if(!$city_id){ + return $this->show_json(SYS_CODE_FAIL, '请选择城市'); + } + if(!$county_id){ + return $this->show_json(SYS_CODE_FAIL, '请选行政区'); + } + + $where = array("title like '{$title}'" => null, "id<>{$info['id']}" => null); + $count = $this->addr_model->count($where); + if($count>0){ + return $this->show_json(SYS_CODE_FAIL, '地址已存在'); + } + + //获取行政区信息 + $where = array('county_id' => $county_id); + $row_area = $this->area_model->get($where); + if(!$row_area){ + return $this->show_json(SYS_CODE_FAIL, '行政区不存在'); + } + + $upd = array( + 'title' => $title, + 'province_id' => $row_area['province_id'], + 'province_name' => $row_area['province_name'], + 'city_id' => $row_area['city_id'], + 'city_name' => $row_area['city_name'], + 'county_id' => $row_area['county_id'], + 'county_name' => $row_area['county_name'], + ); + + $ret = $this->addr_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->addr_model->update($upd, $where); + if(!$ret){ + debug_log("[error]# " . $this->addr_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/auto/attr/lists.php b/admin/views/auto/attr/lists.php index 056b00f5..300cea07 100755 --- a/admin/views/auto/attr/lists.php +++ b/admin/views/auto/attr/lists.php @@ -7,6 +7,24 @@ +
+ +
+ +
+
+
+ +
+ +
+
@@ -55,5 +73,62 @@ + diff --git a/admin/views/auto/cars/lists.php b/admin/views/auto/cars/lists.php index ca555289..ec661433 100644 --- a/admin/views/auto/cars/lists.php +++ b/admin/views/auto/cars/lists.php @@ -214,7 +214,6 @@ 'params.brand_id':function(nv, ov){ var vm = this; vm.seryAry = {}; - vm.params.s_id = ''; if(nv > 0){ $.ajax({ url: '/auto/series/json_lists', @@ -231,6 +230,9 @@ seryAry[row.id] = row.name; } vm.seryAry = seryAry; + if(vm.params.s_id>0 && undefined == seryAry[vm.params.s_id]){ + vm.params.s_id = ''; + } } }, complete: function () { @@ -238,6 +240,8 @@ layer.closeAll('loading'); } }); + } else { + vm.params.s_id = ''; } } } diff --git a/admin/views/auto/series/lists.php b/admin/views/auto/series/lists.php index daf2a65f..b26a3e1a 100755 --- a/admin/views/auto/series/lists.php +++ b/admin/views/auto/series/lists.php @@ -7,6 +7,15 @@ +
+ +
+ +
+
@@ -61,5 +70,27 @@ + diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php index bae196fd..aa255b44 100644 --- a/admin/views/items/goods/edit.php +++ b/admin/views/items/goods/edit.php @@ -34,8 +34,7 @@
车型
-