business add export use import format

This commit is contained in:
qianhy
2023-04-06 16:47:05 +08:00
parent a2934fb01b
commit 3656a641ce
2 changed files with 145 additions and 73 deletions
+132 -73
View File
@@ -20,6 +20,35 @@ class Business extends HD_Controller{
public function index()
{
$params = $this->input->get();
$where = $this->get_where($params);
$page = $params['page'];
$page = !$page ? 1 : $page;
$size = $params['size'];
$size = !$size ? 20 : $size;
//获取品牌map
$where_brand = array('status = 1' => null);
$map_brand = $this->auto_brand_model->map_brand($where_brand);
//状态
$statusAry = array('0' => '关闭', '1' => '开启');
$total = $this->auto_business_model->count($where);
$lists = array();
$total && $lists = $this->get_data($where, $page, $size, $map_brand);
$this->data['params'] = $params;
$this->data['lists'] = $lists;
$this->data['statusAry'] = $statusAry;
$this->data['brandAry'] = $this->auto_brand_model->map_brand_list($map_brand);
$this->data['cityAry'] = $this->sys_city_model->select(['status'=>1],'id desc',0,0,'city_id,name');
$this->data['yearAry'] = $this->auto_business_model->year();
$this->data['monthAry'] = $this->auto_business_model->month();
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page, 'totle' => $total);
$this->data['_title'] = '商务政策管理';
$this->show_view('auto/business/lists',true);
}
private function get_where(&$params){
!isset($params['status']) && $params['status'] = 1;
!isset($params['if_effect']) && $params['if_effect'] = 1;
!isset($params['month']) && $params['month'] = '';
@@ -67,85 +96,79 @@ class Business extends HD_Controller{
if($params['month']){
$where['month'] = $params['month'];
}
$page = $params['page'];
$page = !$page ? 1 : $page;
$size = $params['size'];
$size = !$size ? 20 : $size;
return $where;
}
//获取品牌map
$where_brand = array('status = 1' => null);
$map_brand = $this->auto_brand_model->map_brand($where_brand);
//状态
$statusAry = array('0' => '关闭', '1' => '开启');
$total = $this->auto_business_model->count($where);
private function get_data($where, $page, $size, $map_brand, $export=false){
$lists = array();
if($total){
$orderby = 'id desc';
$select = '*';
$rows = $this->auto_business_model->select($where, $orderby, $page, $size, $select);
if($rows){
$s_ids = array_unique(array_column($rows,'s_id'));
$attr_ids = array_unique(array_column($rows,'v_id'));
$city_ids = array_unique(array_column($rows,'city_id'));
//获取车系列表
$map_sery = array();
if($s_ids){
$str_ids = implode(',', $s_ids);
$where_sery = array("id in ({$str_ids})" => null);
$map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name');
}
$map_attr = array();
if($attr_ids){
$str_ids = implode(',', $attr_ids);
$where_attr = array("id in ({$str_ids})" => null);
$map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title, type');
}
if($city_ids){
$str_ids = implode(',', $city_ids);
$where_city = array("city_id in ({$str_ids})" => null);
$map_city = $this->sys_city_model->map('city_id', 'name', $where_city, 'id desc', 0 , 0, 'city_id, name');
}
//属性按'车型-车身颜色-内饰颜色'排序
foreach($rows as $v){
$title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]}";
$city_cn = $map_city[$v['city_id']];
$month = date('Y-m',strtotime("{$v['year']}-{$v['month']}"));
$lists[] = array(
'id' => $v['id'],
'title' => $title,
'status' => $v['status'],
'price_car' => $v['price_car'] > 0 ? $v['price_car'] : '0.00',
'price_floor' => $v['price_floor'] > 0 ? $v['price_floor'] : '0.00',
'price_coplus' => $v['price_coplus'] > 0 ? $v['price_coplus'] : '0.00',
'price_color' => $v['price_color'] > 0 ? $v['price_color'] : '0.00',
'profix_car' => $v['profix_car'],
'proxy_type' => $v['proxy_type'] == 0 ? '返佣' : '票折',
'proxy_profix_car' => $v['proxy_profix_car'],
'profix_insure' => $v['profix_insure'],
'profix_carno' => $v['profix_carno'],
'profix_loan' => $v['profix_loan'],
'city_cn'=> $city_cn,
'month' => $month,
's_effect_time' => $v['s_effect_time'] ? date('Y-m-d',$v['s_effect_time']) : '',
'effect_status' => $v['if_effect'] ? '生效中' : '未生效',
'if_effect' => $v['if_effect'],
'delivery_day' => $v['delivery_day']
$orderby = 'id desc';
$select = '*';
$rows = $this->auto_business_model->select($where, $orderby, $page, $size, $select);
if($rows){
$s_ids = array_unique(array_column($rows,'s_id'));
$attr_ids = array_unique(array_column($rows,'v_id'));
$city_ids = array_unique(array_column($rows,'city_id'));
//获取车系列表
$map_sery = array();
if($s_ids){
$str_ids = implode(',', $s_ids);
$where_sery = array("id in ({$str_ids})" => null);
$map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name');
}
$map_attr = array();
if($attr_ids){
$str_ids = implode(',', $attr_ids);
$where_attr = array("id in ({$str_ids})" => null);
$map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title, type');
}
if($city_ids){
$str_ids = implode(',', $city_ids);
$where_city = array("city_id in ({$str_ids})" => null);
$map_city = $this->sys_city_model->map('city_id', 'name', $where_city, 'id desc', 0 , 0, 'city_id, name');
}
//属性按'车型-车身颜色-内饰颜色'排序
foreach($rows as $v){
$title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]}";
$city_cn = $map_city[$v['city_id']];
$month = date('Y-m',strtotime("{$v['year']}-{$v['month']}"));
$row = array(
'id' => $v['id'],
'title' => $title,
'status' => $v['status'],
'price_car' => $v['price_car'] > 0 ? $v['price_car'] : '0.00',
'price_floor' => $v['price_floor'] > 0 ? $v['price_floor'] : '0.00',
'price_coplus' => $v['price_coplus'] > 0 ? $v['price_coplus'] : '0.00',
'price_color' => $v['price_color'] > 0 ? $v['price_color'] : '0.00',
'profix_car' => $v['profix_car'],
'proxy_type' => $v['proxy_type'] == 0 ? '返佣' : '票折',
'proxy_profix_car' => $v['proxy_profix_car'],
'profix_insure' => $v['profix_insure'],
'profix_carno' => $v['profix_carno'],
'profix_loan' => $v['profix_loan'],
'city_cn'=> $city_cn,
'month' => $month,
's_effect_time' => $v['s_effect_time'] ? date('Y-m-d',$v['s_effect_time']) : '',
'effect_status' => $v['if_effect'] ? '生效中' : '未生效',
'if_effect' => $v['if_effect'],
'delivery_day' => $v['delivery_day']
);
if ($export){
$export_arr = array(
'brand_name' => $map_brand[$v['brand_id']],
'sery_name' => $map_sery[$v['s_id']],
'attr_name' => $map_attr[$v['v_id']],
'year' => $v['year'],
'month' => $v['month'],
'status_name' => $v['status'] ? '开启' : '关闭',
);
$row = array_merge($row, $export_arr);
}
$lists[] = $row;
}
}
$this->data['params'] = $params;
$this->data['lists'] = $lists;
$this->data['statusAry'] = $statusAry;
$this->data['brandAry'] = $this->auto_brand_model->map_brand_list($map_brand);
$this->data['cityAry'] = $this->sys_city_model->select(['status'=>1],'id desc',0,0,'city_id,name');
$this->data['yearAry'] = $this->auto_business_model->year();
$this->data['monthAry'] = $this->auto_business_model->month();
$this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page, 'totle' => $total);
$this->data['_title'] = '商务政策管理';
$this->show_view('auto/business/lists',true);
return $lists;
}
public function lists()
@@ -514,8 +537,44 @@ class Business extends HD_Controller{
public function export()
{
// TODO: Implement export() method.
$params = $this->input->get();
$where = $this->get_where($params);
$page = 1;
$size = 10000;
//获取品牌map
$where_brand = array('status = 1' => null);
$map_brand = $this->auto_brand_model->map_brand($where_brand);
$data = $this->get_data($where, $page, $size, $map_brand, true);
$fileName = '商务政策';
$indexs = [
'brand_name' => '品牌',
'sery_name' => '车系',
'attr_name' => '车型',
'city_cn' => '城市',
's_effect_time' => '生效日期',
'year' => '时间-年',
'month' => '时间-月',
'price_car' => '裸车报价',
'pricr_floor' => '车辆底价',
'delivery_day' => '交车工作日',
'price_color' => '颜色加价',
'proxy_type' => '代理店返用方式',
'proxy_profix_car' => '代理店单车毛利',
'profix_car' => '品牌店单车毛利',
'profix_carno' => '上牌毛利',
'profix_insure' => '保险毛利',
'profix_loan' => '贷款毛利', # 以上次序与导入一致,方便导出后编辑再导入
'status_name' => '状态',
'effect_status' => '是否生效',
'id' => 'ID',
];
array_unshift($data, $indexs);
$this->load->library('excel');
$this->excel->out($data, $indexs, $fileName . "_" . date('YmdHis'));
}
function edit_status(){
$id = $this->input->post('id');
$field = $this->input->post('field');
+13
View File
@@ -72,6 +72,7 @@
<div class="am-form-group fl ml20">
<button type="submit" class="am-btn am-btn-sm am-btn-success w100">搜索</button>
<a class="am-btn am-btn-sm am-btn-success w100" data-modal="/auto/business/get" data-title="新增">新增</a>
<button type="button" id="export" class="am-btn am-btn-success am-btn-sm w100">导出</button>
<button type="button" id="import" class="am-btn am-btn-success am-btn-sm w100">导入</button>
</div>
</div>
@@ -342,6 +343,18 @@
}
});
$('#export').click(function () {
var count = <?=$pager['totle']?>;
if (count > 10000) {
layer.msg('单次导出数据不能超过10000');
return false;
}
var href = $.menu.parseUri(window.location.href);
var arr = href.split('?');
href = '/auto/business/export?' + arr[1];
window.location.href = href;
});
$("#import").click(function () {
$("#business-file").val('');
layer.open({