diff --git a/admin/controllers/app/licheb/Member.php b/admin/controllers/app/licheb/Member.php index c9fb3e05..5c167e60 100755 --- a/admin/controllers/app/licheb/Member.php +++ b/admin/controllers/app/licheb/Member.php @@ -165,4 +165,38 @@ class Member extends HD_Controller{ { } + + function json_lists(){ + $biz_id = $this->input->post('biz_id'); + $status = $this->input->post('status'); + $page = $this->input->post('page'); + $size = $this->input->post('size'); + + $where = array(); + if(strlen($status) > 0){ + $where['status'] = $status; + } else { + $whre['status > -1'] = null; + } + $biz_id && $where['biz_id'] = $biz_id; + + $total = $this->userM->count($where); + + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = 'id,uname'; + $rows = $this->userM->select($where, $orderby, $page, $size, $select); + + foreach($rows as $v){ + $lists[] = array( + 'id' => $v['id'], + 'title' => $v['uname'], + ); + } + } + + $this->data = array('total' => $total, 'list' => $lists); + return $this->show_json(SYS_CODE_SUCCESS); + } } diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 8d540668..e3673360 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -31,33 +31,44 @@ class Goods extends HD_Controller $params = $this->input->get(); $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; - $where = $where_fine = $autoList = array(); - $search_type = 0; + $where = $where_1 = $where_2 = $where_3 = $autoList = array(); + $search_type = 0;//0不连表,1联表筛选精品,2联表筛选销售,3联表筛选精品和销售 if ($params['brand_id']) { $where['brand_id'] = $params['brand_id']; - $where_fine['brand_id'] = $params['brand_id']; + $where_1['brand_id'] = $params['brand_id']; + $where_2['m.brand_id'] = $params['brand_id']; + $where_3['m.brand_id'] = $params['brand_id']; $autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $params['brand_id']), 'id desc', 0, 0, 'id,name'); } if ($params['s_id']) { $where['s_id'] = $params['s_id']; - $where_fine['s_id'] = $params['s_id']; + $where_1['s_id'] = $params['s_id']; + $where_2['m.s_id'] = $params['s_id']; + $where_3['m.s_id'] = $params['s_id']; $autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $params['s_id']), 'id desc', 0, 0, 'id,title as name'); } if ($params['v_id']) { $where['v_id'] = $params['v_id']; - $where_fine['v_id'] = $params['v_id']; + $where_1['v_id'] = $params['v_id']; + $where_2['m.v_id'] = $params['v_id']; + $where_3['m.v_id'] = $params['v_id']; } //车身颜色 if ($params['cor_id']) { $where['cor_id'] = $params['cor_id']; - $where_fine['cor_id'] = $params['cor_id']; + $where_1['cor_id'] = $params['cor_id']; + $where_2['m.cor_id'] = $params['cor_id']; + $where_3['m.cor_id'] = $params['cor_id']; } else { $params['cor_id'] = ''; } + //地址筛选 if($params['addr_id']){ $where['addr_id'] = $params['addr_id']; - $where_fine['addr_id'] = $params['addr_id']; + $where_1['addr_id'] = $params['addr_id']; + $where_2['m.addr_id'] = $params['addr_id']; + $where_3['m.addr_id'] = $params['addr_id']; } else if($params['city_id']){ $where_addr = array('status>0' => null, 'city_id' => $params['city_id']); if($params['county_id']){ @@ -69,41 +80,89 @@ class Goods extends HD_Controller if($rows_addr){ $str_ids = implode(',', array_column($rows_addr, 'id')); $where["addr_id in ({$str_ids})"] = null; - $where_fine["addr_id in ({$str_ids})"] = null; + $where_1["addr_id in ({$str_ids})"] = null; + $where_2["m.addr_id in ({$str_ids})"] = null; + $where_3["m.addr_id in ({$str_ids})"] = null; } else { $where['addr_id'] = -1; - $where_fine['addr_id'] = -1; + $where_1['addr_id'] = -1; + $where_2['m.addr_id'] = -1; + $where_3['m.addr_id'] = -1; } } else { $params['city_id'] = ''; $params['county_id'] = ''; $params['addr_id'] = ''; } - if(strlen($params['status'])>0){ + + if(2 == $params['status']){//已售 $where['status'] = $params['status']; - $where_fine['m.status'] = $params['status']; + $where_1['m.status'] = $params['status']; + $where_2['m.status'] = $params['status']; + $where_3['m.status'] = $params['status']; + $view = '/items/goods/lists_sold'; + $_title = '已售车辆'; } else { - $params['status'] = ''; + $where['status'] = 1; + $where_1['m.status'] = 1; + $where_2['m.status'] = 1; + $where_3['m.status'] = 1; + $view = '/items/goods/lists'; + $_title = '未售车辆'; } if($params['vin']){ $where["vin like '%{$params['vin']}%'"] = null; - $where_fine["vin like '%{$params['vin']}%'"] = null; + $where_1["vin like '%{$params['vin']}%'"] = null; + $where_2["m.vin like '%{$params['vin']}%'"] = null; + $where_3["m.vin like '%{$params['vin']}%'"] = null; } //精品筛选 if($params['fine_ids']){ $fine_num = substr_count($params['fine_ids'], ',') + 1; - $where_fine["type_id in ({$params['fine_ids']})"] = null; - $where_fine["having"] = "fine_num={$fine_num}"; - $search_type = 1; + $where_1["type_id in ({$params['fine_ids']})"] = null; + $where_1["having"] = "fine_num={$fine_num}"; + $where_2["j2.type_id in ({$params['fine_ids']})"] = null; + $where_2["having"] = "fine_num={$fine_num}"; + $search_type = 0 == $search_type || 1 == $search_type ? 1: 3; } else { $params['fine_ids'] = ''; } + //是否选入精品 + if(strlen($params['is_fine']) > 0){ + if(1 == $params['is_fine']){ + $where_1["j.type_id>0"] = null; + $where_1["having"] = "fine_num>0"; + $where_3["j2.type_id>0"] = null; + $where_3["having"] = "fine_num>0"; + } else { + $where_1["j.type_id is null"] = null; + $where_3["j2.type_id is null"] = null; + } + $search_type = 0 == $search_type || 1 == $search_type ? 1: 3; + } else { + $params['is_fine'] = ''; + } + + //销售员筛选 + if($params['admin_id']){ + $search_type = 0 == $search_type || 2 == $search_type ? 2 : 3; + $where_2['j.admin_id'] = $params['admin_id']; + $where_3['j.admin_id'] = $params['admin_id']; + } else { + $params['city_id_admin'] = ''; + $params['county_id_admin'] = ''; + $params['biz_id_admin'] = ''; + $params['admin_id'] = ''; + } $order = 'id'; - if('fine_num' == $params['order']){ + if('fine_num' == $params['order']){//精品标签数排序 $order = $params['order']; - $search_type = 1; + $search_type = 0 == $search_type || 1 == $search_type ? 1: 3; + } else if('admin_id' == $params['order']){//销售员ID排序 + $order = $params['order']; + $search_type = 0 == $search_type || 2 == $search_type ? 2 : 3; } else if($params['order']){ $order = $params['order']; } else { @@ -117,75 +176,184 @@ class Goods extends HD_Controller } $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); - if(1 == $search_type){ - //精品筛选 - $count = $this->mdItems->count_fine($where_fine); - } else { - $count = $this->mdItems->count($where); + switch($search_type){ + case 1://精品筛选 + $count = $this->mdItems->count_fine($where_1); + break; + case 2://订单筛选 + $count = $this->mdItems->count_order($where_2); + break; + case 3://精品+订单筛选 + $count = $this->mdItems->count_order_fine($where_3); + break; + default: + $count = $this->mdItems->count($where); } $lists = array(); $fine_ids = array(); if ($count) { - if(1 == $search_type){ - //精品筛选 - $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,addr_id,count(type_id) as fine_num'; - $orderby = "{$order} {$sort}"; - $rows = $this->mdItems->select_fine($where_fine, $orderby, $page, $size, $fileds); - } else { - $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,addr_id'; - $orderby = "{$order} {$sort}"; - $rows = $this->mdItems->select($where, $orderby, $page, $size, $fileds); + switch($search_type){ + case 1://精品筛选 + $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,addr_id,count(type_id) as fine_num'; + $orderby = "{$order} {$sort}"; + $rows = $this->mdItems->select_fine($where_1, $orderby, $page, $size, $fileds); + break; + case 2://订单筛选 + $fileds = 'm.id, m.brand_id, m.s_id, m.vin, m.v_id, m.cor_id, m.incor_id, m.in_time, m.addr_id'; + $orderby = "{$order} {$sort}"; + $rows = $this->mdItems->select_order($where_2, $orderby, $page, $size, $fileds); + break; + case 3://精品+订单筛选 + $fileds = 'm.id, m.brand_id, m.s_id, m.vin, m.v_id, m.cor_id, m.incor_id, m.in_time, m.addr_id, count(j2.type_id) as fine_num'; + if(in_array($order, array('admin_id'))){ + $orderby = "{$order} {$sort}"; + } else { + $orderby = "m.{$order} {$sort}"; + } + $rows = $this->mdItems->select_order_fine($where_3, $orderby, $page, $size, $fileds); + break; + default: + $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,addr_id'; + $orderby = "{$order} {$sort}"; + $rows = $this->mdItems->select($where, $orderby, $page, $size, $fileds); } - $brand_id_arr = array(); - $addr_ids = array(); + $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array(); $ids = array(); foreach($rows as $v){ $ids[] = $v['id']; - !in_array($v['brand_id'], $brand_id_arr) && $brand_id_arr[] = $v['brand_id']; + $v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id']; $v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id']; + $v['s_id'] && !in_array($v['s_id'], $s_ids) && $s_ids[] = $v['s_id']; + $v['v_id'] && !in_array($v['v_id'], $attr_vids) && $attr_vids[] = $v['v_id']; + $v['cor_id'] && !in_array($v['cor_id'], $attr_corids) && $attr_corids[] = $v['cor_id']; + $v['incor_id'] && !in_array($v['incor_id'], $attr_incorids) && $attr_incorids[] = $v['incor_id']; + } + $map_brand = $map_sery = $map_vid = $map_corid = $map_incorid = $map_addr = array(); + if($brand_ids){ + $str_ids = implode(',', $brand_ids); + $where = array("id in ({$str_ids})" => null); + $map_brand = $this->mdAutoBrand->map('id', 'name', $where); + } + if($s_ids){ + $str_ids = implode(',', $s_ids); + $where = array("id in ({$str_ids})" => null); + $map_sery = $this->mdAutoSeries->map('id', 'name', $where); + } + if($attr_vids){ + $str_ids = implode(',', $attr_vids); + $where = array("id in ({$str_ids})" => null); + $map_vid = $this->mdAutoAttr->map('id', 'title', $where); + } + if($attr_corids){ + $str_ids = implode(',', $attr_corids); + $where = array("id in ({$str_ids})" => null); + $map_corid = $this->mdAutoAttr->map('id', 'title', $where); + } + if($attr_incorids){ + $str_ids = implode(',', $attr_incorids); + $where = array("id in ({$str_ids})" => null); + $map_incorid = $this->mdAutoAttr->map('id', 'title', $where); } - $brands_rows = $this->mdAutoBrand->get_map_by_ids($brand_id_arr, 'id,name'); - $series_id_arr = array_unique(array_column($rows, 's_id')); - $series_rows = $this->mdAutoSeries->get_map_by_ids($series_id_arr, 'id,name'); - $attr_vid_arr = array_unique(array_column($rows, 'v_id')); - $attr_vid_rows = $this->mdAutoAttr->get_map_by_ids($attr_vid_arr, 'id,title'); - $attr_corid_arr = array_unique(array_column($rows, 'cor_id')); - $attr_corid_rows = $this->mdAutoAttr->get_map_by_ids($attr_corid_arr, 'id,title'); - $attr_incorid_arr = array_unique(array_column($rows, 'incor_id')); - $attr_incorid_rows = $this->mdAutoAttr->get_map_by_ids($attr_incorid_arr, 'id,title'); - //获取存放地址 - $map_addr = array(); if($addr_ids){ $str_ids = implode(',', $addr_ids); $where = array("id in ({$str_ids})" => null); $orderby = 'id desc'; - $select = 'id, title'; - $map_addr = $this->addr_model->map('id', 'title', $where, $orderby, 0, 0, $select); - } - //获取精品加装 - $str_ids = implode(',', $ids); - $where = array("item_id in ({$str_ids})" => null, 'type' => 1, 'status' => 1); - $rows_fine = $this->items_relate_model->select($where, '', 0, 0, 'item_id, type_id'); - $map_fine = array(); - foreach($rows_fine as $v){ - !in_array($v['type_id'], $fine_ids) && $fine_ids[] = $v['type_id']; - $map_fine[$v['item_id']][] = $v['type_id']; + $select = 'id, title, city_name, county_name'; + $map_addr = $this->addr_model->map('id', '*', $where, $orderby, 0, 0, $select); } - foreach ($rows as $key => $val) { - $setVal = array(); - $setVal['id'] = $val['id']; - $setVal['brand_name'] = isset($brands_rows[$val['brand_id']]) ? $brands_rows[$val['brand_id']][0]['name'] : ''; - $setVal['s_name'] = isset($series_rows[$val['s_id']]) ? $series_rows[$val['s_id']][0]['name'] : ''; - $setVal['v_name'] = isset($attr_vid_rows[$val['v_id']]) ? $attr_vid_rows[$val['v_id']][0]['title'] : ''; - $setVal['cor_name'] = isset($attr_corid_rows[$val['cor_id']]) ? $attr_corid_rows[$val['cor_id']][0]['title'] : ''; - $setVal['incor_name'] = isset($attr_incorid_rows[$val['incor_id']]) ? $attr_incorid_rows[$val['incor_id']][0]['title'] : ''; - $setVal['vin'] = $val['vin']; - $setVal['address'] = $val['addr_id'] ? $map_addr[$val['addr_id']] : ''; - $setVal['in_time'] = '0000-00-00 00:00:00' == $val['in_time'] ? '' : $val['in_time']; - $setVal['fine_ids'] = $map_fine[$val['id']] ? $map_fine[$val['id']] : array(); - $lists[] = $setVal; + $map_fine = array(); + $map_item_admin = array(); + if($ids){ + if(1 == $params['status']){ + //获取精品加装 + $str_ids = implode(',', $ids); + $where = array("item_id in ({$str_ids})" => null, 'type' => 1, 'status' => 1); + $rows_fine = $this->items_relate_model->select($where, '', 0, 0, 'item_id, type_id'); + $map_item_fine = array();//按item_id分组所属精品ID + foreach($rows_fine as $v){ + !in_array($v['type_id'], $fine_ids) && $fine_ids[] = $v['type_id']; + $map_item_fine[$v['item_id']][] = $v['type_id']; + } + //获取精品ID和名称映射 + if($fine_ids){ + $this->load->model('auto/auto_fine_model'); + $str_ids = implode(',', $fine_ids); + $where= array("id in ({$str_ids})" => null); + $map_fine = $this->auto_fine_model->map('id', 'title', $where); + } + } + + //获取销售员信息 + if(2 == $params['status']){ + //订单列表 + $this->load->model('receiver/order/receiver_orders_model','orders_model'); + $str_ids = implode(',', $ids); + $where = array("item_id in ({$str_ids})" => null); + $rows_order = $this->orders_model->select($where, 'id desc', 0, 0, 'item_id, admin_id'); + $admin_ids = array(); + foreach($rows_order as $v){ + $map_item_admin[$v['item_id']] = array('admin_id' => $v['admin_id']); + $v['admin_id'] && !in_array($v['admin_id'], $admin_ids) && $admin_ids[] = $v['admin_id']; + } + if($admin_ids){ + //销售员列表 + $this->load->model('app/licheb/app_licheb_users_model', 'licheb_users_model'); + $str_ids = implode(',', $admin_ids); + $where = array("id in({$str_ids})" => null); + $select = 'id, uname, biz_id'; + $rows_admin = $this->licheb_users_model->select($where, 'id desc', 0, 0, $select); + if($rows_admin){ + $biz_ids = array(); + $map_admin = array(); + $map_biz_name = array(); + foreach($rows_admin as $v){ + $map_admin[$v['id']] = $v; + !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id']; + } + if($biz_ids){//店铺列表 + $this->load->model("biz/biz_model"); + $str_ids = implode(',', $biz_ids); + $where = array("id in({$str_ids})" => null); + $map_biz_name = $this->biz_model->map('id', 'biz_name', $where); + } + + foreach($map_item_admin as $k => $v){ + $admin_id = $v['admin_id']; + $admin = $map_admin[$admin_id]; + if(!$admin){ + continue; + } + $biz_name = $map_biz_name[$admin['biz_id']]; + $admin_name = "{$biz_name} {$admin['uname']}"; + $map_item_admin[$k] = array( + 'admin_id' => $admin_id, + 'biz_id' => $admin['biz_id'], + 'admin_name' => $admin_name + ); + } + } + } + } + } + + + foreach ($rows as $k => $v) { + $admin = $map_item_admin[$v['id']]; + $lists[] = array( + 'id' => $v['id'], + 'brand_name' => $map_brand[$v['brand_id']], + 's_name' => $map_sery[$v['s_id']], + 'v_name' => $map_vid[$v['v_id']], + 'cor_name' => $map_corid[$v['cor_id']], + 'incor_name' => $map_incorid[$v['incor_id']], + 'vin' => $v['vin'], + 'address' => $v['addr_id'] ? $map_addr[$v['addr_id']] : '', + 'in_time' => '0000-00-00 00:00:00' == $v['in_time'] ? '' : $v['in_time'], + 'fine_ids' => $map_fine[$v['id']] ? $map_fine[$v['id']] : array(), + 'admin_name' => $admin ? $admin['admin_name'] : '', + ); } } $this->data['lists'] = $lists; @@ -194,8 +362,8 @@ class Goods extends HD_Controller $this->data['params'] = $params; $this->data['autoList'] = $autoList; $this->data['statusAry'] = $this->statusAry; - $this->data['_title'] = '商品管理'; - return $this->show_view('/items/goods/lists', true); + $this->data['_title'] = $_title; + return $this->show_view($view, true); } public function get() diff --git a/admin/views/app/licheb/member/lists.php b/admin/views/app/licheb/member/lists.php index e64b5eb9..a8e0a96e 100755 --- a/admin/views/app/licheb/member/lists.php +++ b/admin/views/app/licheb/member/lists.php @@ -142,7 +142,7 @@ if(that.params.biz_id>0){ var biz_id = ''; for(var i in that.bizAry){ - if(that.params.biz_id == thayt.bizAry[i].id){ + if(that.params.biz_id == that.bizAry[i].id){ biz_id = that.params.biz_id; break; } diff --git a/admin/views/items/goods/lists.php b/admin/views/items/goods/lists.php index 1fd9cef7..cb2f58d4 100644 --- a/admin/views/items/goods/lists.php +++ b/admin/views/items/goods/lists.php @@ -92,6 +92,7 @@ action="/items/goods/goods"> +
| + + + ID + + + + + | ++ + + 车辆 + + + + + | ++ + + 车架号 + + + + + | ++ + + 销售员 + + + + | ++ + + 销售日期 + + + + + | +操作 | +
|---|---|---|---|---|---|
| {{v.id}} | +{{v.brand_name}}-{{v.s_name}}-{{v.v_name}}-{{v.cor_name}} | +{{v.vin}} | +{{v.admin_name}} | +{{v.out_time}} | ++ 查看 + 编辑 + | +