diff --git a/admin/controllers/items/goods/Goods.php b/admin/controllers/items/goods/Goods.php index a69e5c4c..0006323b 100644 --- a/admin/controllers/items/goods/Goods.php +++ b/admin/controllers/items/goods/Goods.php @@ -17,6 +17,7 @@ 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("sys/sys_addr_model", 'addr_model'); } public function index() @@ -41,14 +42,49 @@ class Goods extends HD_Controller if ($params['v_id']) { $where['v_id'] = $params['v_id']; } + if($params['addr_id']){ + $where['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; + } else { + $where['addr_id'] = -1; + } + } else { + $params['city_id'] = ''; + $params['county_id'] = ''; + $params['addr_id'] = ''; + } + if(strlen($params['status'])>0){ + $where['status'] = $params['status']; + } else { + $params['status'] = ''; + } + + if($params['vin']){ + $where["vin like '%{$params['vin']}%'"] = null; + } + $autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name'); $count = $this->mdItems->count($where); $lists = array(); if ($count) { - $fileds = 'id,brand_id,s_id,ori_price,sale_price,bill_price,c_time,if_pack,discount,buy_price,address,status - ,v_id,cor_id,incor_id'; + $fileds = 'id,brand_id,s_id,vin,v_id,cor_id,incor_id,p_time,addr_id'; $rows = $this->mdItems->select($where, 'id desc', $page, $size, $fileds); - $brand_id_arr = array_unique(array_column($rows, 'brand_id')); + $brand_id_arr = array(); + $addr_ids = array(); + foreach($rows as $v){ + !in_array($v['brand_id'], $brand_id_arr) && $brand_id_arr[] = $v['brand_id']; + $v['addr_id'] && !in_array($v['addr_id'], $addr_ids) && $addr_ids[] = $v['addr_id']; + } $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'); @@ -58,7 +94,19 @@ class Goods extends HD_Controller $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); + } foreach ($rows as $key => $val) { + $p_days = ''; + if('0000-00-00 00:00:00' != $val['p_time']){ + $p_days = intval((time() - strtotime($val['p_time']))/3600/24); + } $setVal = array(); $setVal['id'] = $val['id']; $setVal['brand_name'] = isset($brands_rows[$val['brand_id']]) ? $brands_rows[$val['brand_id']][0]['name'] : ''; @@ -66,12 +114,10 @@ class Goods extends HD_Controller $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['if_pack_name'] = $val['if_pack']; - $setVal['ori_price'] = $val['ori_price']; - $setVal['discount'] = $val['discount'] ? $val['discount'] . '%' : '100%'; - $setVal['buy_price'] = $val['buy_price']; - $setVal['status_name'] = $this->statusAry[$val['status']]; - $setVal['address'] = $val['address'] ? '收货地址:' . $val['address'] : ''; + $setVal['vin'] = $val['vin']; + $setVal['address'] = $val['addr_id'] ? $map_addr[$val['addr_id']] : ''; + $setVal['p_time'] = '0000-00-00 00:00:00' == $val['p_time'] ? '' : $val['p_time']; + $setVal['p_days'] = $p_days; $lists[] = $setVal; } } @@ -79,6 +125,7 @@ class Goods extends HD_Controller $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); $this->data['params'] = $params; $this->data['autoList'] = $autoList; + $this->data['statusAry'] = $this->statusAry; $this->data['_title'] = '商品管理'; return $this->show_view('/items/goods/lists', true); } @@ -111,7 +158,6 @@ class Goods extends HD_Controller } 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']; @@ -173,7 +219,6 @@ class Goods extends HD_Controller $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']){ - $this->load->model("sys/sys_addr_model", 'addr_model'); $row_addr = $this->addr_model->get(array('id' => $info['addr_id'])); $info['address'] = $row_addr['city_name'].$row_addr['county_name'].$row_addr['title']; } else { @@ -241,65 +286,10 @@ class Goods extends HD_Controller return $this->show_json(SYS_CODE_SUCCESS, '添加成功!'); } - //编辑单条数据 - public function edit() - { - $info = $this->input->post('info'); - $checkInfo = $this->checkInfo($info); - if (!$checkInfo['code']) { - return $this->show_json($checkInfo['code'], $checkInfo['msg']); - } - $editData['brand_id'] = $info['brand_id']; - $editData['s_id'] = $info['s_id']; - $editData['v_id'] = $info['v_id']; - $editData['cor_id'] = $info['cor_id']; - $editData['incor_id'] = $info['incor_id']; - $editData['if_pack'] = $info['if_pack']; - $editData['status'] = $info['status']; - - $editData['address'] = $info['address']; - $editData['vin'] = $info['vin']; - $editData['stdard_num'] = $info['stdard_num']; - $editData['engine_num'] = $info['engine_num']; - $editData['ori_price'] = $info['ori_price']; - $editData['discount'] = $info['discount']; - $editData['dis_price'] = $info['dis_price']; - $editData['bill_num'] = $info['bill_num']; - $editData['bill_price'] = $info['bill_price']; - $editData['buy_price'] = $info['buy_price']; - - $editData['pro_time'] = $info['pro_time']; - $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, '修改失败!'); - } - $this->data['status'] = 2; - return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); - } - - //删除单条数据 - public function del() - { - - } - - //批量操作(默认修改状态) - public function batch() - { - - } - - //导出数据列表 - public function export() - { - - } - + /** + * 导入 + * @return bool + */ public function add_excel() { require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php'; @@ -363,6 +353,224 @@ class Goods extends HD_Controller return $this->show_json(SYS_CODE_SUCCESS, '导入完成,导入总条数为:' . $j); } + //编辑单条数据 + public function edit() + { + $info = $this->input->post('info'); + $checkInfo = $this->checkInfo($info); + if (!$checkInfo['code']) { + return $this->show_json($checkInfo['code'], $checkInfo['msg']); + } + $editData['brand_id'] = $info['brand_id']; + $editData['s_id'] = $info['s_id']; + $editData['v_id'] = $info['v_id']; + $editData['cor_id'] = $info['cor_id']; + $editData['incor_id'] = $info['incor_id']; + $editData['if_pack'] = $info['if_pack']; + $editData['status'] = $info['status']; + + $editData['address'] = $info['address']; + $editData['vin'] = $info['vin']; + $editData['stdard_num'] = $info['stdard_num']; + $editData['engine_num'] = $info['engine_num']; + $editData['ori_price'] = $info['ori_price']; + $editData['discount'] = $info['discount']; + $editData['dis_price'] = $info['dis_price']; + $editData['bill_num'] = $info['bill_num']; + $editData['bill_price'] = $info['bill_price']; + $editData['buy_price'] = $info['buy_price']; + + $editData['pro_time'] = $info['pro_time']; + $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, '修改失败!'); + } + $this->data['status'] = 2; + return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); + } + + //删除单条数据 + public function del() + { + + } + + //批量操作(默认修改状态) + public function batch() + { + + } + + //导出数据列表 + public function export() + { + $params = $this->input->get(); + $where = array(); + 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'); + } + 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'); + } + if ($params['v_id']) { + $where['v_id'] = $params['v_id']; + } + if($params['addr_id']){ + $where['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; + } else { + $where['addr_id'] = -1; + } + } else { + $params['city_id'] = ''; + $params['county_id'] = ''; + $params['addr_id'] = ''; + } + if(strlen($params['status'])>0){ + $where['status'] = $params['status']; + } else { + $params['status'] = ''; + } + + if($params['vin']){ + $where["vin like '%{$params['vin']}%'"] = null; + } + + $total = $this->mdItems->count($where); + if($total > 10000){ + return $this->show_json(SYS_CODE_FAIL, '数据量超过1w导出太为难我了'); + } else if(0 == $total) { + 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' =>'折扣百分比', + 'city_name' => '城市名', + 'county_name' => '行政区', + 'address' =>'存放地址', + 'vin' =>'车架号', + 'engine_num' =>'发动机号', + 'stdard_num' =>'合格证号', + 'bill_num' =>'开票号', + 'if_pack' =>'精品加装', + 'status' =>'状态', + 'pro_time' =>'生产时间', + 'p_time' =>'分配时间', + 'out_time' =>'出库时间', + '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']; + } + + $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'], + 'p_time' => '0000-00-00 00:00:00' == $v['p_time'] ? '' : $v['p_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; + } + /** * Notes:上传excel * Created on: 2021/7/14 15:06 diff --git a/admin/views/items/goods/lists.php b/admin/views/items/goods/lists.php index 371f97fd..3f77e75b 100644 --- a/admin/views/items/goods/lists.php +++ b/admin/views/items/goods/lists.php @@ -46,6 +46,46 @@ +
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
@@ -57,6 +97,7 @@
+
@@ -66,17 +107,17 @@ - + - - - - - + + + + + @@ -89,27 +130,18 @@ - - - - - - - - + + + + ; + vm.params = ; + vm.statusAry = ; + vm.init_citys(); + }, + methods:{ + init_citys:function() { + var vm = this; + $.ajax({ + type: 'get', + url: '/common/area', + dataType: 'json', + data: { + id: '350', + key: 'city', + type: 1 + }, + success: function (response) { + if (response.code == 1) { + vm.cityAry = response.data; + } + } + }); + } + }, + watch:{ + 'params.city_id':function(nv, ov){ + var that = this; + if(nv == ''){ + that.countyAry = []; + that.params.county_id = ''; + } else { + if(nv.substring(0,4) != that.params.county_id.substring(0, 4)){ + that.params.county_id = ''; + } + $.ajax({ + type: 'get', + url: '/common/area', + dataType: 'json', + data: { + id: nv, + key:'county', + type:1 + }, + success:function(response){ + if (response.code == 1) { + that.countyAry = response.data; + } + } + }); + } + }, + 'params.county_id':function(nv, ov){ + var that = this; + if(nv == ''){ + that.addrAry = []; + that.params.addr_id = ''; + } else { + $.ajax({ + type: 'get', + url: '/sys/addr/json_lists', + dataType: 'json', + data: { + county_id: nv, + status:1 + }, + success:function(response){ + if (response.code == 1) { + that.addrAry = response.data.lists; + if(that.params.addr_id>0){ + var addr_id = ''; + for(var i in that.addrAry){ + if(that.params.addr_id == thayt.addrAry[i].id){ + addr_id = that.params.addr_id; + break; + } + } + that.params.addr_id = addr_id; + } + } + } + }); + } + } + } + }); + + + $("#import").click(function () { $("#goods-file").val(''); layer.open({ @@ -202,5 +335,17 @@ }); }); + + $('#export').click(function () { + var count = ; + if (count > 10000) { + layer.msg('单次导出数据不能超过10000'); + return false; + } + var href = $.menu.parseUri(window.location.href); + var arr = href.split('?'); + href = '/items/goods/goods/export?' + arr[1]; + window.location.href = href; + }); });
商品IDID 品牌 车系 车型 车身颜色 内饰颜色选装包市场平台价折扣%采购成本车辆状态车架号存放地分配日期存放天数操作
-
-
- -
-
- 查看 - 编辑 -
+
+ 查看 + 编辑