
请教龙老大及随风大神,X1的新闻数据excel导出
要如何操作,能给个详细的教程嘛
仅供参考
后台菜单添加
array( 'title'=>'导出电子证', 'link'=>['excel/index'], 'power'=>['index','excel'], ),
<?php
namespace app\work\admin;
use app\common\controller\AdminBase;
use app\common\traits\AddEditList;
use think\Db;
class Excel extends AdminBase{
use AddEditList;
protected $form_items=[];
protected $list_items;
protected $tab_ext;
protected $model;
protected $s_model;
protected function _initialize(){
parent::_initialize();
preg_match_all('/([_a-z0-9]+)/i',get_called_class(),$array);
$dirname=$array[0][1];
$this->model=get_model_class($dirname,'content');
$this->s_model=get_model_class($dirname,'sort');
}
public function index($type='',$fid=''){
$this->tab_ext['page_title']='导出电子证';
if($type=='excel'){
return $this->excel($fid);
}
if($this->request->isPost()){
$data=$this->request->post();
$weburl=get_url('location');
return $this->success('等待导出',$weburl.(strstr($weburl,'?')?"&":'?').'type=excel&page=1&fid='.$data['fid']);
}
$sort_array=$this->s_model->getTreeTitle(0);
$this->form_items=[
['select','fid','单位','',$sort_array],
];
return $this->addContent('index');
}
protected function excel($fid='',$rows=500){
$map=[];
if(is_numeric($fid)){
$map['fid']=['in',array_values(get_sort($fid,'sons',''))];
}
$array=$this->model->getAll($map,$order="id desc",$rows);
$field_array=[
'i' =>'序号',
'id' =>'ID',
'uid' =>'用户UID',
'_uid'=>[
'key' =>'uid', //处理上面key重复的问题
'title'=>'用户帐号',
'type' =>'username',
],
'title' =>'姓名',
'sex' =>[
'title'=>'性别',
'opt' =>['未知','男','女'],
],
'idcard' =>'身份证号',
'telphone' =>'电话',
'zhiwu' =>'单位职务',
'mobphone' =>'单位联系电话',
'temperature'=>'当天体温',
'codestatus' =>'一码通状态',
'prc' =>'核酸检测信息',
'travel' =>'行程码信息',
'uptime' =>'核酸同步时间',
'create_time'=>[
'title'=>'信息登记日期',
'type' =>'time',
],
];
return $this->bak_excel($array,$field_array);
}
public function add(){ }
public function edit(){ }
public function delete(){ }
}