diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 741d629a..12a15541 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -8,7 +8,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class Goods extends HD_Controller { - private $statusAry = array( 1 => '未售', 2 => '已售', 0 => '下架'); + private $statusAry = array(1 => '未售', 2 => '已售', 0 => '下架'); public function __construct() { @@ -18,7 +18,9 @@ class Goods extends HD_Controller $this->load->model('auto/auto_brand_model', 'mdAutoBrand'); $this->load->model('auto/auto_series_model', 'mdAutoSeries'); $this->load->model('auto/auto_attr_model', 'mdAutoAttr'); + $this->load->model("biz/biz_model", 'mdBiz'); $this->load->model("sys/sys_addr_model", 'addr_model'); + $this->load->model('area_model', 'mdArea'); } public function index() @@ -31,7 +33,7 @@ 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 = array('id<>1' => null,'status>'=>0); + $where = array('id<>1' => null, 'status>' => 0); $where_1 = $where_2 = $where_3 = array('m.id<>1' => null); $autoList = array(); $search_type = 0;//0不连表,1联表筛选精品,2联表筛选销售,3联表筛选精品和销售 @@ -66,38 +68,41 @@ class Goods extends HD_Controller } //地址筛选 - if($params['addr_id']){ + if ($params['biz_id']) { + $where['biz_id'] = $params['biz_id']; + $where_1['biz_id'] = $params['biz_id']; + $where_2['m.biz_id'] = $params['biz_id']; + $where_3['m.biz_id'] = $params['biz_id']; + } + if ($params['biz_id'] == -1 && $params['addr_id']) { $where['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']){ - $where_addr['county_id'] = $params['county_id']; - } - $orderby = 'id desc'; - $select = 'id'; - $rows_addr = $this->addr_model->select($where_addr, $orderby, 0, 0, $select); - if($rows_addr){ - $str_ids = implode(',', array_column($rows_addr, 'id')); - $where["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 if ($params['city_id']) { + $where_biz['status'] = 1; + $params['city_id'] && $where_biz['city_id'] = $params['city_id']; + $params['county_id'] && $where_biz['county_id'] = $params['county_id']; + $res_biz = $this->mdBiz->select($where_biz, 'id desc', 0, 0, 'id'); + if ($res_biz) { + $str_ids = implode(',', array_column($res_biz, 'id')); + $where["biz_id in ({$str_ids})"] = null; + $where_1["biz_id in ({$str_ids})"] = null; + $where_2["m.biz_id in ({$str_ids})"] = null; + $where_3["m.biz_id in ({$str_ids})"] = null; } else { - $where['addr_id'] = -1; - $where_1['addr_id'] = -1; - $where_2['m.addr_id'] = -1; - $where_3['m.addr_id'] = -1; + $where['biz_id'] = -2; + $where_1['biz_id'] = -2; + $where_2['m.biz_id'] = -2; + $where_3['m.biz_id'] = -2; } } else { $params['city_id'] = ''; $params['county_id'] = ''; $params['addr_id'] = ''; + $params['biz_id'] = ''; } - - if(strlen($params['status'])>0){ + if (strlen($params['status']) > 0) { $where['status'] = $params['status']; $where_1['m.status'] = $params['status']; $where_2['m.status'] = $params['status']; @@ -106,7 +111,7 @@ class Goods extends HD_Controller $params['status'] = ''; } - if(1 == $params['sold']){//已售 + if (1 == $params['sold']) {//已售 $where["bill_time<>'0000-00-00 00:00:00'"] = null; $where_1["m.bill_time<>'0000-00-00 00:00:00'"] = null; $where_2["m.bill_time<>'0000-00-00 00:00:00'"] = null; @@ -122,26 +127,26 @@ class Goods extends HD_Controller $_title = '库存车辆'; } - if($params['vin']){ + if ($params['vin']) { $where["vin like '%{$params['vin']}%'"] = null; $where_1["m.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']){ + if ($params['fine_ids']) { $fine_num = substr_count($params['fine_ids'], ',') + 1; $where_1["j.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; + $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']){ + 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; @@ -150,13 +155,13 @@ class Goods extends HD_Controller $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; + $search_type = 0 == $search_type || 1 == $search_type ? 1 : 3; } else { $params['is_fine'] = ''; } //销售员筛选 - if($params['admin_id']){ + 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']; @@ -168,28 +173,28 @@ class Goods extends HD_Controller } $order = 'id'; - if('fine_num' == $params['order']){//精品标签数排序 + if ('fine_num' == $params['order']) {//精品标签数排序 $order = $params['order']; - $search_type = 0 == $search_type || 1 == $search_type ? 1: 3; - } else if(in_array($params['order'], array('admin_id', 'mobile', 'uname'))){//销售员ID、订单用户电话、订单用户名称 + $search_type = 0 == $search_type || 1 == $search_type ? 1 : 3; + } else if (in_array($params['order'], array('admin_id', 'mobile', 'uname'))) {//销售员ID、订单用户电话、订单用户名称 $order = $params['order']; $search_type = 0 == $search_type || 2 == $search_type ? 2 : 3; - }else if('sold_time' == $params['order']){//售卖时间排序 + } else if ('sold_time' == $params['order']) {//售卖时间排序 $order = 'bill_time'; - } else if($params['order']){ + } else if ($params['order']) { $order = $params['order']; } else { $params['order'] = $order; } $sort = 'desc'; - if($params['sort']){ + if ($params['sort']) { $sort = $params['sort']; } else { $params['sort'] = $sort; } $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); - switch($search_type){ + switch ($search_type) { case 1://精品筛选 $count = $this->mdItems->count_fine($where_1); break; @@ -206,17 +211,17 @@ class Goods extends HD_Controller $lists = array(); $fine_ids = array(); if ($count) { - switch($search_type){ + switch ($search_type) { case 1://精品筛选 - $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,bill_time,addr_id,count(type_id) as fine_num'; + $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,bill_time,biz_id,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.bill_time, m.addr_id'; - if(in_array($order, array('admin_id', 'mobile'))){ + $fileds = 'm.id, m.brand_id, m.s_id, m.vin, m.v_id, m.cor_id, m.incor_id, m.in_time, m.bill_time, m.biz_id, m.addr_id'; + if (in_array($order, array('admin_id', 'mobile'))) { $orderby = "j.{$order} {$sort}"; - } else if('uname' == $order){ + } else if ('uname' == $order) { $orderby = "j.name {$sort}"; } else { $orderby = "{$order} {$sort}"; @@ -224,10 +229,10 @@ class Goods extends HD_Controller $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.bill_time, m.addr_id, count(j2.type_id) as fine_num'; - if(in_array($order, array('admin_id', 'mobile'))){ + $fileds = 'm.id, m.brand_id, m.s_id, m.vin, m.v_id, m.cor_id, m.incor_id, m.in_time, m.bill_time, m.biz_id,m.addr_id, count(j2.type_id) as fine_num'; + if (in_array($order, array('admin_id', 'mobile'))) { $orderby = "j.{$order} {$sort}"; - } else if('uname' == $order){ + } else if ('uname' == $order) { $orderby = "j.name {$sort}"; } else { $orderby = "m.{$order} {$sort}"; @@ -235,108 +240,113 @@ class Goods extends HD_Controller $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,bill_time,addr_id'; + $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,in_time,bill_time,biz_id,addr_id'; $orderby = "{$order} {$sort}"; $rows = $this->mdItems->select($where, $orderby, $page, $size, $fileds); } - $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array(); + $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $biz_ids = $addr_ids = array(); $ids = array(); - foreach($rows as $v){ + foreach ($rows as $v) { $ids[] = $v['id']; $v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id']; + $v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_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){ + $map_brand = $map_sery = $map_vid = $map_corid = $map_incorid = $map_biz = $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){ + 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){ + 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){ + 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){ + if ($attr_incorids) { $str_ids = implode(',', $attr_incorids); $where = array("id in ({$str_ids})" => null); $map_incorid = $this->mdAutoAttr->map('id', 'title', $where); } - if($addr_ids){ + if ($biz_ids) { + $str_ids = implode(',', $biz_ids); + $where = array("id in ({$str_ids})" => null); + $map_biz = $this->mdBiz->map('id', 'biz_name', $where); + } + if ($addr_ids) { $str_ids = implode(',', $addr_ids); $where = array("id in ({$str_ids})" => null); $orderby = 'id desc'; $select = 'id, title, city_name, county_name'; $rows_addr = $this->addr_model->select($where, $orderby, 0, 0, $select); - foreach($rows_addr as $v){ - $map_addr[$v['id']] = "{$v['city_name']} {$v['county_name']} {$v['title']}"; + foreach ($rows_addr as $v) { + $map_addr[$v['id']] = "{$v['city_name']} {$v['county_name']} 其它 {$v['title']}"; } } $map_item_fine = array(); $map_order = array(); - if($ids){ + if ($ids) { //获取精品加装 $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){ + 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']; } //已售商品订单信息 - $this->load->model('receiver/order/receiver_orders_model','orders_model'); + $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, name, mobile'); $admin_ids = array(); - foreach($rows_order as $v){ + foreach ($rows_order as $v) { $map_order[$v['item_id']] = array('admin_id' => $v['admin_id'], 'uname' => $v['name'], 'mobile' => $v['mobile']); $v['admin_id'] && !in_array($v['admin_id'], $admin_ids) && $admin_ids[] = $v['admin_id']; } - if($admin_ids){ + 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){ + if ($rows_admin) { $biz_ids = array(); $map_admin = array(); $map_biz_name = array(); - foreach($rows_admin as $v){ + 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"); + if ($biz_ids) {//店铺列表 $str_ids = implode(',', $biz_ids); $where = array("id in({$str_ids})" => null); - $map_biz_name = $this->biz_model->map('id', 'biz_name', $where); + $map_biz_name = $this->mdBiz->map('id', 'biz_name', $where); } - foreach($map_order as $k => $v){ + foreach ($map_order as $k => $v) { $admin_id = $v['admin_id']; $admin = $map_admin[$admin_id]; - if(!$admin){ + if (!$admin) { continue; } $biz_name = $map_biz_name[$admin['biz_id']]; @@ -355,6 +365,20 @@ class Goods extends HD_Controller foreach ($rows as $k => $v) { $order = $map_order[$v['id']]; + $address = ''; + if ($v['biz_id'] > 0) { + $address = $map_biz[$v['biz_id']]; + $re_biz = $this->mdBiz->get(array('id' => $v['biz_id'])); + if ($re_biz['county_id']) { + $re_area = $this->mdArea->get(array('county_id' => $re_biz['county_id'])); + $re_area && $address = "{$re_area['city_name']} {$re_area['county_name']} {$address}"; + } else if ($re_biz['city_id']) { + $re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id'])); + $re_area && $address = "{$re_area['city_name']} {$address}"; + } + } else if ($v['biz_id'] == -1 && $v['addr_id']) { + $address = $map_addr[$v['addr_id']]; + } $lists[] = array( 'id' => $v['id'], 'brand_name' => $map_brand[$v['brand_id']], @@ -363,7 +387,7 @@ class Goods extends HD_Controller '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']] : '', + 'address' => $address, 'in_time' => '0000-00-00 00:00:00' == $v['in_time'] ? '' : substr($v['in_time'], 0, 10), 'sold_time' => '0000-00-00 00:00:00' == $v['bill_time'] ? '' : substr($v['bill_time'], 0, 10), 'fine_ids' => $map_item_fine[$v['id']] ? $map_item_fine[$v['id']] : array(), @@ -390,7 +414,7 @@ class Goods extends HD_Controller $autoList = array(); $id = intval($this->input->get('id')); $info['brand_id'] = $info['s_id'] = $info['v_id'] = $info['cor_id'] = $info['incor_id'] = 0; - $info['if_pack'] = ''; + $info['if_pack'] = $info['city_id'] = $info['county_id'] = $info['biz_id'] = $info['addr_id'] = ''; $info['status'] = 1; $autoList[2] = $autoList[3] = $autoList[4] = $autoList[5] = array(); if ($id > 0) { @@ -411,17 +435,20 @@ 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']){ - $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'] = ''; + $info['city_id'] = ''; + $info['county_id'] = ''; + $info['biz_id'] = $info['biz_id'] ? $info['biz_id'] : ''; + if ($info['biz_id']) { + if ($info['biz_id'] > 0) { + $row_biz = $this->mdBiz->get(array('id' => $info['biz_id'])); + $info['city_id'] = $row_biz['city_id']; + $info['county_id'] = $row_biz['county_id']; + } else if ($info['addr_id']) { + $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']; + } } - //获取精品加装 $where = array('item_id' => $id, 'type' => 1, 'status' => 1); $rows_fine = $this->items_relate_model->select($where, '', 0, 0, 'type_id'); @@ -431,9 +458,6 @@ class Goods extends HD_Controller $_title = '编辑商品'; $edit_url = '/items/goods/goods/edit'; } else { - $info['city_id'] = ''; - $info['county_id'] = ''; - $info['addr_id'] = ''; $info['fine_ids'] = array(); $info['in_time'] = date('Y-m-d H:i:s'); $_title = '新增商品'; @@ -481,9 +505,9 @@ class Goods extends HD_Controller $info['in_time'] = $re['in_time'] != '0000-00-00 00:00:00' ? $re['in_time'] : ''; $info['out_time'] = $re['out_time'] != '0000-00-00 00:00:00' ? $re['out_time'] : ''; $info['bill_time'] = $re['bill_time'] != '0000-00-00 00:00:00' ? $re['bill_time'] : ''; - if($info['addr_id']){ + if ($info['addr_id']) { $row_addr = $this->addr_model->get(array('id' => $info['addr_id'])); - $info['address'] = $row_addr['city_name'].$row_addr['county_name'].$row_addr['title']; + $info['address'] = $row_addr['city_name'] . $row_addr['county_name'] . $row_addr['title']; } else { $info['address'] = ''; } @@ -508,15 +532,15 @@ class Goods extends HD_Controller $msg = '请选择品牌'; } else if (!$info['s_id']) { $msg = '请选择车系'; - } else if(!$info['v_id']){ + } else if (!$info['v_id']) { $msg = '请选择车型'; - } else if(!$info['cor_id']){ + } else if (!$info['cor_id']) { $msg = '请选择车身颜色'; - } else if(!$info['incor_id']){ + } else if (!$info['incor_id']) { $msg = '请选择内饰颜色'; - } else if(!$info['addr_id']){ - $msg = '请选择地址'; - } else if(!$info['in_time']){ + } else if (!$info['biz_id'] && !$info['addr_id']) { + $msg = '请选择门店或地址'; + } else if (!$info['in_time']) { $msg = '请选择入库时间'; } else { $code = SYS_CODE_SUCCESS; @@ -533,11 +557,11 @@ class Goods extends HD_Controller return $this->show_json($checkInfo['code'], $checkInfo['msg']); } - if($info['vin']){ + if ($info['vin']) { //车架号不重复 $where = array('vin' => $info['vin']); $count = $this->mdItems->count($where); - if($count>0){ + if ($count > 0) { return $this->show_json(SYS_CODE_FAIL, 'vin码已存在'); } } @@ -567,16 +591,21 @@ class Goods extends HD_Controller $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; + $biz_id = $addr_id = 0; + if ($info['biz_id']) { + $biz_id = $info['biz_id']; + $addr_id = $info['biz_id'] == -1 ? $info['addr_id'] : 0; + } + $addData['biz_id'] = $biz_id; + $addData['addr_id'] = $addr_id; $id = $this->mdItems->add($addData); if (!$id) { return $this->show_json(SYS_CODE_FAIL, '添加失败!'); } - //保存精品 - if($info['fine_ids']){ + if ($info['fine_ids']) { $adds = array(); - foreach($info['fine_ids'] as $fine_id){ + foreach ($info['fine_ids'] as $fine_id) { $adds[] = array( 'item_id' => $id, 'type' => 1, @@ -586,7 +615,6 @@ class Goods extends HD_Controller } $ret = $this->items_relate_model->add_batch($adds); } - $this->data['status'] = 1; $url = $info['bill_time'] ? '/items/goods/goods?sold=1' : "/items/goods/goods"; return $this->show_json(SYS_CODE_SUCCESS, '添加成功!', $url); @@ -669,11 +697,11 @@ class Goods extends HD_Controller return $this->show_json($checkInfo['code'], $checkInfo['msg']); } - if($info['vin']){ + if ($info['vin']) { //车架号不重复 $where = array('vin' => $info['vin'], "id<>{$info['id']}" => null); $count = $this->mdItems->count($where); - if($count>0){ + if ($count > 0) { return $this->show_json(SYS_CODE_FAIL, 'vin码已存在'); } } @@ -702,7 +730,13 @@ class Goods extends HD_Controller $editData['out_time'] = $info['out_time']; $editData['bill_time'] = $info['bill_time']; //存货地址 - $editData['addr_id'] = $info['addr_id'] ? $info['addr_id'] : 0; + $biz_id = $addr_id = 0; + if ($info['biz_id']) { + $biz_id = $info['biz_id']; + $addr_id = $info['biz_id'] == -1 ? $info['addr_id'] : 0; + } + $editData['biz_id'] = $biz_id; + $editData['addr_id'] = $addr_id; $ret = $this->mdItems->update($editData, array('id' => $info['id'])); if (!$ret) { return $this->show_json(SYS_CODE_FAIL, '修改失败!'); @@ -713,10 +747,10 @@ class Goods extends HD_Controller //删除旧数据 $this->items_relate_model->update(array('status' => -1), $where); $map_relate = $this->items_relate_model->map('type_id', 'status', $where); - if($info['fine_ids']){ + if ($info['fine_ids']) { $adds = array(); - foreach($info['fine_ids'] as $fine_id){ - if(!$map_relate[$fine_id]){ + foreach ($info['fine_ids'] as $fine_id) { + if (!$map_relate[$fine_id]) { //新增 $adds[] = array( 'item_id' => $info['id'], @@ -787,38 +821,43 @@ class Goods extends HD_Controller } //地址筛选 - if($params['addr_id']){ + //地址筛选 + if ($params['biz_id']) { + $where['biz_id'] = $params['biz_id']; + $where_1['biz_id'] = $params['biz_id']; + $where_2['m.biz_id'] = $params['biz_id']; + $where_3['m.biz_id'] = $params['biz_id']; + } + if ($params['biz_id'] == -1 && $params['addr_id']) { $where['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']){ - $where_addr['county_id'] = $params['county_id']; - } - $orderby = 'id desc'; - $select = 'id'; - $rows_addr = $this->addr_model->select($where_addr, $orderby, 0, 0, $select); - if($rows_addr){ - $str_ids = implode(',', array_column($rows_addr, 'id')); - $where["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 if ($params['city_id']) { + $where_biz['status'] = 1; + $params['city_id'] && $where_biz['city_id'] = $params['city_id']; + $params['county_id'] && $where_biz['county_id'] = $params['county_id']; + $res_biz = $this->mdBiz->select($where_biz, 'id desc', 0, 0, 'id'); + if ($res_biz) { + $str_ids = implode(',', array_column($res_biz, 'id')); + $where["biz_id in ({$str_ids})"] = null; + $where_1["biz_id in ({$str_ids})"] = null; + $where_2["m.biz_id in ({$str_ids})"] = null; + $where_3["m.biz_id in ({$str_ids})"] = null; } else { - $where['addr_id'] = -1; - $where_1['addr_id'] = -1; - $where_2['m.addr_id'] = -1; - $where_3['m.addr_id'] = -1; + $where['biz_id'] = -2; + $where_1['biz_id'] = -2; + $where_2['m.biz_id'] = -2; + $where_3['m.biz_id'] = -2; } } else { $params['city_id'] = ''; $params['county_id'] = ''; $params['addr_id'] = ''; + $params['biz_id'] = ''; } - if(strlen($params['status'])>0){ + if (strlen($params['status']) > 0) { $where['status'] = $params['status']; $where_1['m.status'] = $params['status']; $where_2['m.status'] = $params['status']; @@ -831,7 +870,7 @@ class Goods extends HD_Controller $where_3['m.status >'] = 0; } - if(1 == $params['sold']){//已售 + if (1 == $params['sold']) {//已售 $where["bill_time<>'0000-00-00 00:00:00'"] = null; $where_1["m.bill_time<>'0000-00-00 00:00:00'"] = null; $where_2["m.bill_time<>'0000-00-00 00:00:00'"] = null; @@ -843,26 +882,26 @@ class Goods extends HD_Controller $where_3["m.bill_time"] = '0000-00-00 00:00:00'; } - if($params['vin']){ + if ($params['vin']) { $where["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']){ + if ($params['fine_ids']) { $fine_num = substr_count($params['fine_ids'], ',') + 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; + $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']){ + 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; @@ -871,13 +910,13 @@ class Goods extends HD_Controller $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; + $search_type = 0 == $search_type || 1 == $search_type ? 1 : 3; } else { $params['is_fine'] = ''; } //销售员筛选 - if($params['admin_id']){ + 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']; @@ -889,28 +928,28 @@ class Goods extends HD_Controller } $order = 'id'; - if('fine_num' == $params['order']){//精品标签数排序 + if ('fine_num' == $params['order']) {//精品标签数排序 $order = $params['order']; - $search_type = 0 == $search_type || 1 == $search_type ? 1: 3; - } else if('admin_id' == $params['order']){//销售员ID排序 + $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('sold_time' == $params['order']){//售卖时间排序 + } else if ('sold_time' == $params['order']) {//售卖时间排序 $order = 'bill_time'; - } else if($params['order']){ + } else if ($params['order']) { $order = $params['order']; } else { $params['order'] = $order; } $sort = 'desc'; - if($params['sort']){ + if ($params['sort']) { $sort = $params['sort']; } else { $params['sort'] = $sort; } $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); - switch($search_type){ + switch ($search_type) { case 1://精品筛选 $count = $this->mdItems->count_fine($where_1); break; @@ -924,44 +963,44 @@ class Goods extends HD_Controller $count = $this->mdItems->count($where); } - if($count > 10000){ + if ($count > 10000) { return $this->show_json(SYS_CODE_FAIL, '数据量超过1w导出太为难我了'); - } else if(0 == $count) { + } else if (0 == $count) { return $this->show_json(SYS_CODE_SUCCESS, '当前没有数据'); } $fileName = "车辆明细"; $indexs = array( 'id' => 'ID', - 'brand_name' =>'品牌', - 's_name' =>'车系', - 'v_name' =>'车型', - 'cor_name' =>'车身颜色', - 'incor_name' =>'内饰颜色', - 'ori_price' =>'指导价', - 'sale_price' =>'售价', - 'bill_price' =>'开票金额', - 'buy_price' =>'采购成本', - 'dis_price' =>'折扣价', - 'discount' =>'折扣百分比', + 'brand_name' => '品牌', + 's_name' => '车系', + 'v_name' => '车型', + 'cor_name' => '车身颜色', + 'incor_name' => '内饰颜色', + 'ori_price' => '指导价', + 'sale_price' => '售价', + 'bill_price' => '开票金额', + 'buy_price' => '采购成本', + 'dis_price' => '折扣价', + 'discount' => '折扣百分比', 'city_name' => '城市名', 'county_name' => '行政区', - 'address' =>'存放地址', - 'vin' =>'车架号', - 'engine_num' =>'发动机号', - 'stdard_num' =>'合格证号', - 'bill_num' =>'开票号', - 'auto_fine' =>'精品加装', - 'status' =>'状态', - 'in_time' =>'入库时间', - 'out_time' =>'出库时间', - 'bill_time' =>'开票时间', + 'address' => '存放地址', + 'vin' => '车架号', + 'engine_num' => '发动机号', + 'stdard_num' => '合格证号', + 'bill_num' => '开票号', + 'auto_fine' => '精品加装', + 'status' => '状态', + 'in_time' => '入库时间', + 'out_time' => '出库时间', + 'bill_time' => '开票时间', ); $lists = array(); $fine_ids = array(); if ($count) { - switch($search_type){ + switch ($search_type) { case 1://精品筛选 $fileds = 'm.*,count(type_id) as fine_num'; $orderby = "{$order} {$sort}"; @@ -974,7 +1013,7 @@ class Goods extends HD_Controller break; case 3://精品+订单筛选 $fileds = 'm.*, count(j2.type_id) as fine_num'; - if(in_array($order, array('admin_id'))){ + if (in_array($order, array('admin_id'))) { $orderby = "{$order} {$sort}"; } else { $orderby = "m.{$order} {$sort}"; @@ -988,11 +1027,12 @@ class Goods extends HD_Controller } $lists[] = $indexs; - $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array(); + $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $biz_ids = $addr_ids = array(); $ids = array(); - foreach($rows as $v){ + foreach ($rows as $v) { $ids[] = $v['id']; $v['brand_id'] && !in_array($v['brand_id'], $brand_ids) && $brand_ids[] = $v['brand_id']; + $v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_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']; @@ -1000,33 +1040,38 @@ class Goods extends HD_Controller $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){ + $map_brand = $map_sery = $map_vid = $map_corid = $map_incorid = $map_biz = $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){ + 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){ + 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){ + 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){ + if ($attr_incorids) { $str_ids = implode(',', $attr_incorids); $where = array("id in ({$str_ids})" => null); $map_incorid = $this->mdAutoAttr->map('id', 'title', $where); } - if($addr_ids){ + if ($biz_ids) { + $str_ids = implode(',', $biz_ids); + $where = array("id in ({$str_ids})" => null); + $map_biz = $this->mdBiz->map('id', 'biz_name', $where); + } + if ($addr_ids) { $str_ids = implode(',', $addr_ids); $where = array("id in ({$str_ids})" => null); $orderby = 'id desc'; @@ -1039,29 +1084,46 @@ class Goods extends HD_Controller $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){ + 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和名称映射 $map_fine = array(); - if($fine_ids){ + if ($fine_ids) { $this->load->model('auto/auto_fine_model'); $str_ids = implode(',', $fine_ids); - $where= array("id in ({$str_ids})" => null); + $where = array("id in ({$str_ids})" => null); $map_fine = $this->auto_fine_model->map('id', 'title', $where); } - foreach($rows as $v){ - $addr = $map_addr[$v['addr_id']]; + foreach ($rows as $v) { //获取并组装精品信息 $fine_ids = $map_item_fine[$v['id']]; $auto_fine = ''; - if($fine_ids){ - foreach($fine_ids as $fine_id){ + if ($fine_ids) { + foreach ($fine_ids as $fine_id) { $auto_fine = $auto_fine ? "{$auto_fine} {$map_fine[$fine_id]}" : $map_fine[$fine_id]; } } + $addr = array(); + if ($v['biz_id'] > 0) { + $re_biz = $this->mdBiz->get(array('id' => $v['biz_id'])); + if ($re_biz['county_id']) { + $re_area = $this->mdArea->get(array('county_id' => $re_biz['county_id'])); + if ($re_area) { + $addr = array('city_name' => $re_area['city_name'], 'county_name' => $re_area['county_name'] + , 'title' => $map_biz[$v['biz_id']]); + } + } else if ($re_biz['city_id']) { + $re_area = $this->mdArea->get(array('city_id' => $re_biz['city_id'])); + if ($re_area) { + $addr = array('city_name' => $re_area['city_name'], 'title' => $map_biz[$v['biz_id']]); + } + } + } else if ($v['biz_id'] == -1 && $v['addr_id']) { + $addr = $map_addr[$v['addr_id']]; + } $lists[] = array( 'id' => $v['id'], 'brand_name' => $map_brand[$v['brand_id']], @@ -1069,7 +1131,7 @@ class Goods extends HD_Controller 'v_name' => $map_vid[$v['v_id']], 'cor_name' => $map_corid[$v['cor_id']], 'incor_name' => $map_incorid[$v['incor_id']], - 'ori_price' =>$v['ori_price'], + 'ori_price' => $v['ori_price'], 'sale_price' => $v['sale_price'], 'bill_price' => $v['bill_price'], 'buy_price' => $v['buy_price'], @@ -1080,7 +1142,7 @@ class Goods extends HD_Controller 'address' => $addr ? $addr['title'] : '', 'vin' => $v['vin'], 'engine_num' => $v['engine_num'], - 'stdard_num' =>$v['stdard_num'], + 'stdard_num' => $v['stdard_num'], 'bill_num' => $v['bill_num'], 'auto_fine' => $auto_fine, 'status' => $this->statusAry[$v['status']], diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index e96013fb..9f412c91 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -41,6 +41,7 @@ class Customer extends HD_Controller !$params['cf_title'] && $params['cf_title'] = ''; !$params['qdjl_id'] && $params['qdjl_id'] = ''; !$params['level'] && $params['level'] = ''; + !$params['cf_clues'] && $params['cf_clues'] = ''; $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; @@ -58,6 +59,9 @@ class Customer extends HD_Controller if ($params['level']) { $where['level'] = $params['level']; } + if ($params['cf_clues']) { + $where['cf_clues'] = $params['cf_clues']; + } !$params['search_tp'] && $params['search_tp'] = 'mobile'; strlen($params['status']) && $where["status"] = $params['status']; $params['cf_title'] && $where['cf_title'] = $params['cf_title']; @@ -164,7 +168,7 @@ class Customer extends HD_Controller $count = $this->customers_model->count($where); $lists = []; if ($count) { - $fileds = 'id,name,mobile,cf_title,cont_time,admin_id,status,biz_id,cf_id,level'; + $fileds = 'id,name,mobile,cf_title,cf_clues,cont_time,admin_id,status,biz_id,cf_id,level'; $rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds); //获取来源 $cf_id_arr = array_unique(array_column($rows, 'cf_id')); @@ -188,6 +192,7 @@ class Customer extends HD_Controller 'mobile_sub' => $mobile_sub, 'level' => $val['level'], 'cf_title' => $val['cf_title'], + 'cf_clues' => $val['cf_clues'], 'cf_name' => isset($cf_rows[$val['cf_id']]) ? $cf_rows[$val['cf_id']][0]['title'] : '', 'status_name' => $status_arr[$val['status']], 'admin_name' => isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : '', @@ -199,6 +204,7 @@ class Customer extends HD_Controller //渠道经理 $qdjl_lists = $this->app_licheb_users_model->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0'), 'id desc', 0, 0, 'id,uname as name'); $show_info['levelAry'] = $this->customers_model->get_sdata('level'); + $show_info['cfCluesAry'] = $this->customers_model->get_sdata('cfrom_clues'); $this->data['show_info'] = $show_info; $this->data['lists'] = $lists; $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php index e739f348..bae421a6 100644 --- a/admin/views/items/goods/edit.php +++ b/admin/views/items/goods/edit.php @@ -5,6 +5,7 @@ margin-top: 10px; font-size: 0; } + .label-group { display: inline-block; margin-right: 4px; @@ -12,23 +13,27 @@ font-size: 0; white-space: nowrap; } - .label-group-wrap .label, .label-group>.label { + + .label-group-wrap .label, .label-group > .label { font-size: 10px; font-weight: normal; margin-right: 1px; white-space: normal; line-height: 1.4; } + .label { font-weight: normal; } - .label-group>span+a.label { + + .label-group > span + a.label { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid #fff; margin-left: -3px; } - .label-group-wrap .label, .label-group>.label { + + .label-group-wrap .label, .label-group > .label { font-size: 10px; font-weight: normal; margin-right: 1px; @@ -109,10 +114,12 @@