actions = $this->getRegisterAction(); } public function index() { $this->display(); } private function getRegisterAction() { return $actions = array( 'user_record'=>'用户数据', ); } public function doAction() { $action = I('action'); if($this->actions[$action]){ $this->$action(); }else{ echo '请注册操作'; } } /** * 导出片单 * @param string start_date '2019-01-18' * @param string end_date '2019-02-22' */ public function user_record() { Vendor('PHPExcel.PHPExcel'); $obpe = new \PHPExcel(); if(!$uid = trim(I('uid'))){ exit('用户不存在'); } //登录历史 $data['login'] = M('iptv_user_login_log')->field('uid,created_at')->where(['uid'=>$uid])->order('created_at asc')->select(); $login_title = ['账号','登录时间']; array_unshift($data['login'], $login_title); //订购历史 $data['order'] = M('iptv_order')->field('uid,created_at')->where(['uid'=>$uid])->order('created_at asc')->select(); $order_title = ['账号','订购时间']; array_unshift($data['order'], $order_title); //观看历史 $data['watch'] = M('iptv_watch_log wl') ->field('wl.uid,wl.created_at,s.name as source_name') ->join('__SOURCE__ s on wl.source_id = s.id','left') ->where(['wl.uid'=>$uid]) ->order('wl.created_at asc') ->select(); $watch_title = ['账号','观看时间','节目名称']; array_unshift($data['watch'], $watch_title); /* @func 设置文档基本属性 */ // $obpe_pro = $obpe->getProperties(); // $obpe_pro->setCreator('midoks')//设置创建者 // ->setLastModifiedBy('2013/2/16 15:00')//设置时间 // ->setTitle('data')//设置标题 // ->setSubject('beizhu')//设置备注 // ->setDescription('miaoshu')//设置描述 // ->setKeywords('keyword')//设置关键字 | 标记 // ->setCategory('catagory');//设置类别 $index = 0; foreach ($data as $type => $value) { if($index != 0){ $obpe->createSheet(); } $obpe->setactivesheetindex($index); if($type == 'watch'){ $obpe->getActiveSheet()->setTitle('观看记录'); } if($type == 'login'){ $obpe->getActiveSheet()->setTitle('登录记录'); } if($type == 'order'){ $obpe->getActiveSheet()->setTitle('订购记录'); } $number = 0; foreach($value as $key2=>$value2){ /* @func 设置列 */ $key = 0; $number = $number + 1; foreach ($value2 as $value3) { $code = strtoupper(chr(65 + $key));//输出大写字母 $obpe->getactivesheet()->setcellvalue($code.$number, $value3); $key = $key+1; } } $index ++; } //写入类容 $obwrite = \PHPExcel_IOFactory::createWriter($obpe, 'Excel5'); //保存文件 $fileName = '投诉'.$uid.date('YmdHis').'.xls'; $obwrite->save($fileName); header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment;filename = ' . $fileName); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check = 0, pre-check = 0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $fileName ) ); ob_clean(); flush(); readfile( $fileName ); unlink($fileName); } }