From 9e38e6e6087c905ec96085963fe28454398ef464 Mon Sep 17 00:00:00 2001 From: qianhy Date: Fri, 3 Feb 2023 14:52:02 +0800 Subject: [PATCH] brand status about, export --- admin/controllers/items/goods/Goods.php | 368 +++++++++++++++++++++++- 1 file changed, 362 insertions(+), 6 deletions(-) diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index 4b14c1fc..52578667 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -311,7 +311,8 @@ class Goods extends HD_Controller $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'); + $this->load->model('receiver/order/receiver_orders_v2_model', 'orders_model'); $str_ids = implode(',', $items_info['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'); @@ -875,9 +876,200 @@ class Goods extends HD_Controller public function export() { $params = $this->input->get(); - $params['page'] = 1; - $params['size'] = 10000; - $this->data = $this->dataSelect($params); + $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_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_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('status' => 1, '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_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_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['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_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['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) { + $where['status'] = $params['status']; + $where_1['m.status'] = $params['status']; + $where_2['m.status'] = $params['status']; + $where_3['m.status'] = $params['status']; + } else { + $params['status'] = ''; + $where['status >'] = 0; + $where_1['m.status >'] = 0; + $where_2['m.status >'] = 0; + $where_3['m.status >'] = 0; + } + + 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; + $where_3["m.bill_time<>'0000-00-00 00:00:00'"] = null; + $where['brand_id in (select id from lc_auto_brand where status >- 1)'] = null; + $where_1['brand_id in (select id from lc_auto_brand where status >- 1)'] = null; + $where_2['m.brand_id in (select id from lc_auto_brand where status >- 1)'] = null; + $where_3['m.brand_id in (select id from lc_auto_brand where status >- 1)'] = null; + } else { + $where["bill_time"] = '0000-00-00 00:00:00'; + $where_1["m.bill_time"] = '0000-00-00 00:00:00'; + $where_2["m.bill_time"] = '0000-00-00 00:00:00'; + $where_3["m.bill_time"] = '0000-00-00 00:00:00'; + $where['brand_id in (select id from lc_auto_brand where status = 1)'] = null; + $where_1['brand_id in (select id from lc_auto_brand where status = 1)'] = null; + $where_2['m.brand_id in (select id from lc_auto_brand where status = 1)'] = null; + $where_3['m.brand_id in (select id from lc_auto_brand where status = 1)'] = null; + } + + 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']) { + $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; + } 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']) {//精品标签数排序 + $order = $params['order']; + $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']) {//售卖时间排序 + $order = 'bill_time'; + } else if ($params['order']) { + $order = $params['order']; + } else { + $params['order'] = $order; + } + $sort = 'desc'; + if ($params['sort']) { + $sort = $params['sort']; + } else { + $params['sort'] = $sort; + } + + #$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); + if (1 == $params['sold']){ + $autoList[1] = $this->mdAutoBrand->map_brand(array('status > -1' => null), false); + } + else{ + $autoList[1] = $this->mdAutoBrand->map_brand(array('status = 1' => null), false); + } + + 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); + } + + if ($count > 10000) { + return $this->show_json(SYS_CODE_FAIL, '数据量超过1w导出太为难我了'); + } else if (0 == $count) { + return $this->show_json(SYS_CODE_SUCCESS, '当前没有数据'); + } $fileName = "车辆明细"; $indexs = array( @@ -907,10 +1099,173 @@ class Goods extends HD_Controller 'out_time' => '出库时间', 'bill_time' => '开票时间', ); - $lists = $this->data['lists']; - array_unshift($lists, $indexs); + + $lists = array(); + $fine_ids = array(); + if ($count) { + switch ($search_type) { + case 1://精品筛选 + $fileds = 'm.*,count(type_id) as fine_num'; + $orderby = "{$order} {$sort}"; + $rows = $this->mdItems->select_fine($where_1, $orderby, 0, 0, $fileds); + break; + case 2://订单筛选 + $fileds = 'm.*'; + $orderby = "{$order} {$sort}"; + $rows = $this->mdItems->select_order($where_2, $orderby, 0, 0, $fileds); + break; + case 3://精品+订单筛选 + $fileds = 'm.*, 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, 0, 0, $fileds); + break; + default: + $fileds = '*'; + $orderby = "{$order} {$sort}"; + $rows = $this->mdItems->select($where, $orderby, 0, 0, $fileds); + } + + $lists[] = $indexs; + $company_ids = $brand_ids = $s_ids = $attr_vids = $attr_corids = $attr_incorids = $biz_ids = $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['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']; + $v['company_id'] && !in_array($v['company_id'], $company_ids) && $company_ids[] = $v['company_id']; + } + + $map_company = $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) { + $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 ($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'; + $map_addr = $this->addr_model->map('id', '*', $where, $orderby, 0, 0, $select); + } + if ($company_ids) { + $str_ids = implode(',', $company_ids); + $where = array("id in ({$str_ids})" => null); + $map_company = $this->sys_company_model->map('id', 'short', $where); + } + //获取精品加装 + $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) { + //获取并组装精品信息 + $fine_ids = $map_item_fine[$v['id']]; + $auto_fine = ''; + 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']], + '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, + 'company_name' => $map_company[$v['company_id']], + 'status' => $this->statusAry[$v['status']], + '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'); $this->excel->out_csv($lists, $indexs, $fileName . "_" . date('YmdHis')); + + return 1; } public function export_() { @@ -1297,6 +1652,7 @@ class Goods extends HD_Controller $this->load->model('items/items_oplogs_model', 'mdItemsOplogs'); $fileName = '超期车辆'; $where = ['status<>' => 0, 'bill_time' => '0000-00-00 00:00:00']; + $where['brand_id in (select id from lc_auto_brand where status = 1)'] = null; $res = $this->mdItems->select($where, 'id asc', 1, 5000, 'brand_id,biz_id,addr_id,s_id,v_id,cor_id,incor_id,company_id,id,vin,in_time,status'); $data = $list = []; foreach ($res as $key => $value) {