diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index cdd30150..0990f77b 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -391,7 +391,7 @@ class Goods extends HD_Controller } $this->data['status'] = 1; - return $this->show_json(SYS_CODE_SUCCESS, '添加成功!'); + return $this->show_json(SYS_CODE_SUCCESS, '添加成功!', '/items/goods/goods'); } /** @@ -536,7 +536,7 @@ class Goods extends HD_Controller } $this->data['status'] = 2; - return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); + return $this->show_json(SYS_CODE_SUCCESS, '修改成功!', '/items/goods/goods'); } //删除单条数据 @@ -555,20 +555,31 @@ class Goods extends HD_Controller public function export() { $params = $this->input->get(); - $where = array(); + $where = $where_fine = array(); + $search_type = 0; if ($params['brand_id']) { $where['brand_id'] = $params['brand_id']; - $autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $params['brand_id']), 'id desc', 0, 0, 'id,name'); + $where_fine['brand_id'] = $params['brand_id']; } if ($params['s_id']) { $where['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'); + $where_fine['s_id'] = $params['s_id']; } if ($params['v_id']) { $where['v_id'] = $params['v_id']; + $where_fine['v_id'] = $params['v_id']; } + //车身颜色 + if ($params['cor_id']) { + $where['cor_id'] = $params['cor_id']; + $where_fine['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']; } else if($params['city_id']){ $where_addr = array('status>0' => null, 'city_id' => $params['city_id']); if($params['county_id']){ @@ -580,8 +591,10 @@ 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; } else { $where['addr_id'] = -1; + $where_fine['addr_id'] = -1; } } else { $params['city_id'] = ''; @@ -590,18 +603,51 @@ class Goods extends HD_Controller } if(strlen($params['status'])>0){ $where['status'] = $params['status']; + $where_fine['m.status'] = $params['status']; } else { $params['status'] = ''; } if($params['vin']){ $where["vin like '%{$params['vin']}%'"] = null; + $where_fine["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; + } else { + $params['fine_ids'] = ''; } - $total = $this->mdItems->count($where); - if($total > 10000){ + $order = 'id'; + if('fine_num' == $params['order']){ + $order = $params['order']; + $search_type = 1; + } else if($params['order']){ + $order = $params['order']; + } else { + $params['order'] = $order; + } + $sort = 'desc'; + if($params['sort']){ + $sort = $params['sort']; + } else { + $params['sort'] = $sort; + } + + if(1 == $search_type){ + //精品筛选 + $count = $this->mdItems->count_fine($where_fine); + } else { + $count = $this->mdItems->count($where); + } + + if($count > 10000){ return $this->show_json(SYS_CODE_FAIL, '数据量超过1w导出太为难我了'); - } else if(0 == $total) { + } else if(0 == $count) { return $this->show_json(SYS_CODE_SUCCESS, '当前没有数据'); } @@ -626,7 +672,7 @@ class Goods extends HD_Controller 'engine_num' =>'发动机号', 'stdard_num' =>'合格证号', 'bill_num' =>'开票号', - 'if_pack' =>'精品加装', + 'auto_fine' =>'精品加装', 'status' =>'状态', 'pro_time' =>'生产时间', 'in_time' =>'分配时间', @@ -634,80 +680,121 @@ class Goods extends HD_Controller 'bill_time' =>'开票时间', ); - $rows = $this->mdItems->select($where, 'id desc', 0, 0, '*'); - $lists[] = $indexs; - $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array(); - foreach($rows as $v){ - $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']; - } + $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, 0, 0, $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, 0, 0, $fileds); + } - $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); - } - 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'; - $map_addr = $this->addr_model->map('id', '*', $where, $orderby, 0, 0, $select); - } - foreach($rows as $v){ - $addr = $map_addr[$v['addr_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']], - 'ori_price' =>$v['ori_price'], - 'sale_price' => $v['sale_price'], - 'bill_price' => $v['bill_price'], - 'buy_price' => $v['buy_price'], - 'dis_price' => $v['dis_price'], - 'discount' => $v['discount'], - 'city_name' => $addr ? $addr['city_name'] : '', - 'county_name' => $addr ? $addr['county_name'] : '', - 'address' => $addr ? $addr['title'] : '', - 'vin' => $v['vin'], - 'engine_num' => $v['engine_num'], - 'stdard_num' =>$v['stdard_num'], - 'bill_num' => $v['bill_num'], - 'if_pack' => $v['if_pack'], - 'status' => $this->statusAry[$v['status']], - 'pro_time' => '0000-00-00 00:00:00' == $v['pro_time'] ? '' : $v['pro_time'], - 'in_time' => '0000-00-00 00:00:00' == $v['in_time'] ? '' : $v['in_time'], - 'out_time' => '0000-00-00 00:00:00' == $v['out_time'] ? '' : $v['out_time'], - 'bill_time' => '0000-00-00 00:00:00' == $v['bill_time'] ? '' : $v['bill_time'], - ); + $lists[] = $indexs; + $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $addr_ids = array(); + $ids = array(); + foreach($rows as $v){ + $ids[] = $v['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); + } + 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'; + $map_addr = $this->addr_model->map('id', '*', $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_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和名称映射 + $map_fine = array(); + 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); + } + + foreach($rows as $v){ + $addr = $map_addr[$v['addr_id']]; + //获取并组装精品信息 + $fine_ids = $map_item_fine[$v['id']]; + $auto_fine = ''; + foreach($fine_ids as $fine_id){ + $auto_fine = $auto_fine ? "{$auto_fine} {$map_fine[$fine_id]}" : $map_fine[$fine_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']], + 'ori_price' =>$v['ori_price'], + 'sale_price' => $v['sale_price'], + 'bill_price' => $v['bill_price'], + 'buy_price' => $v['buy_price'], + 'dis_price' => $v['dis_price'], + 'discount' => $v['discount'], + 'city_name' => $addr ? $addr['city_name'] : '', + 'county_name' => $addr ? $addr['county_name'] : '', + 'address' => $addr ? $addr['title'] : '', + 'vin' => $v['vin'], + 'engine_num' => $v['engine_num'], + 'stdard_num' =>$v['stdard_num'], + 'bill_num' => $v['bill_num'], + 'auto_fine' => $auto_fine, + 'status' => $this->statusAry[$v['status']], + 'pro_time' => '0000-00-00 00:00:00' == $v['pro_time'] ? '' : $v['pro_time'], + 'in_time' => '0000-00-00 00:00:00' == $v['in_time'] ? '' : $v['in_time'], + 'out_time' => '0000-00-00 00:00:00' == $v['out_time'] ? '' : $v['out_time'], + 'bill_time' => '0000-00-00 00:00:00' == $v['bill_time'] ? '' : $v['bill_time'], + ); + } } $this->load->library('excel'); diff --git a/admin/views/items/goods/edit.php b/admin/views/items/goods/edit.php index 64b49205..aee28645 100644 --- a/admin/views/items/goods/edit.php +++ b/admin/views/items/goods/edit.php @@ -439,8 +439,8 @@ icon: 1, time: 2000 }, function () { - if (data.data.status == 1) { - $.form.href('#/items/goods/goods'); + if (data.url != '') { + $.form.href(data.url); } else { $.form.reload(); } diff --git a/admin/views/receiver/orders/get.php b/admin/views/receiver/orders/get.php index 3d2bca87..21dd7a78 100644 --- a/admin/views/receiver/orders/get.php +++ b/admin/views/receiver/orders/get.php @@ -88,6 +88,48 @@ require_once "oinfo.php" ?> + +