123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-02-17
- // +—————————————————————————————————————————————————————————————————————
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\Db;
- class MainController extends AdminbaseController {
-
- public function index(){
-
- $config=getConfigPub();
- $this->assign("config",$config);
-
- $nowtime=time();
- //当天0点
- $today=date("Y-m-d",$nowtime);
- $today_start=strtotime($today);
- //当天 23:59:59
- $today_end=strtotime("{$today} + 1 day");
-
- /* 总注册数 */
- $users_total=Db::name('user')->where("user_type=2")->count();
- $this->assign("users_total",number_format($users_total));
-
-
-
- //设备终端
- $source=Db::name('user')
- ->field("count(id) as nums,source")
- ->where("user_type=2")
- ->group("source")
- ->select()
- ->toArray();
- $data_source=[
- 'name'=>[],
- 'nums'=>[],
- 'nums_per'=>[],
- 'color'=>[],
- ];
- $color=['#99ce87','#5ba1f8','#f4a76d','#99ba64'];
- if($source){
- $nums=array_column($source,'nums');
- $nums_totoal=array_sum($nums);
-
- foreach($source as $k=>$v){
- $data_source['name'][]=$v['source'];
- $data_source['nums'][]=$v['nums'];
- $data_source['color'][]=$color[$k];
- $data_source['nums_per'][]=round($v['nums']*100/$nums_totoal);
- }
- }
-
- $this->assign("data_sourcej",json_encode($data_source));
- /* 注册渠道 */
- $login_type=Db::name('user')
- ->field("count(id) as nums,login_type")
- ->where("user_type=2")
- ->group("login_type")
- ->order("nums desc")
- ->select()
- ->toArray();
- $data_type=[
- 'name'=>[],
- 'v_n'=>[],
- ];
- $color_v_n=['#0972f4','#3289f6','#65a6f7','#8dbdf9','#b7d1f2'];
- if($login_type){
- foreach($login_type as $k=>$v){
- $data_type['v_n'][]=['value'=>$v['nums'],'name'=>$v['login_type'],'itemStyle'=>['color'=>$color_v_n[$k]]];
- $data_type['name'][]=$v['login_type'];
- }
- }
-
- $this->assign("data_typej",json_encode($data_type));
-
-
- /* 主播数据 */
- $anchor_total=Db::name('user')->where("user_type=2")->count();
- $anchor_online=Db::name('live')->where("islive=1")->count();
- $anchor_live_long_total=Db::query("select sum(endtime - starttime) as times from cmf_live_record");
- //$anchor_live_long_total=Db::name('live_record')->sum("endtime - starttime");
- $times=0;
- if($anchor_live_long_total){
- $times=$anchor_live_long_total[0]['times'];
- }
- if($times>0){
- $times=number_format(floor($times/60));
- }
-
- $anchorinfo=$this->getAnchorInfo($today_start,$today_end);
- $anchor=[
- 'anchor_total'=>$anchor_total,
- 'anchor_online'=>$anchor_online,
- 'anchor_live_long_total'=>$times,
- ];
-
- $anchor=array_merge($anchor,$anchorinfo);
- $this->assign("anchor",$anchor);
-
-
- /* 网红榜 */
- $votes_list=Db::name('user')
- ->field("id,user_nicename,avatar,avatar_thumb,votestotal")
- ->where("user_type=2")
- ->order("votestotal desc")
- ->limit(0,3)
- ->select()
- ->toArray();
- foreach($votes_list as $k=>$v){
- $v['avatar']=get_upload_path($v['avatar']);
- $v['avatar_thumb']=get_upload_path($v['avatar_thumb']);
-
- $votes_list[$k]=$v;
- }
- $this->assign("votes_list",$votes_list);
- /* 富豪榜 */
- $rich_list=Db::name('user')
- ->field("id,user_nicename,avatar,avatar_thumb,consumption")
- ->where("user_type=2")
- ->order("consumption desc")
- ->limit(0,3)
- ->select()
- ->toArray();
- foreach($rich_list as $k=>$v){
- $v['avatar']=get_upload_path($v['avatar']);
- $v['avatar_thumb']=get_upload_path($v['avatar_thumb']);
-
- $rich_list[$k]=$v;
- }
- $this->assign("rich_list",$rich_list);
-
- /* 财务 */
- $charge_total=Db::name('charge_user')->where("status=1")->sum("money");
- if(!$charge_total){
- $charge_total=0;
- }
- if($charge_total>0){
- $charge_total=number_format($charge_total);
- }
-
- $data_charge=$this->getCharge($today_start,$today_end);
- $this->assign("charge_total",$charge_total);
- $this->assign("data_chargej",json_encode($data_charge));
-
- /* 提现 */
- $cashinfo=$this->getCash($today_start,$today_end);
-
- $cash_total=Db::name('cash_record')->where("status=1")->sum("money");
- if(!$cash_total){
- $cash_total=0;
- }
- if($cash_total>0){
- $cash_total=number_format($cash_total);
- }
-
- $this->assign("cashinfo",$cashinfo);
- $this->assign("cash_total",$cash_total);
-
- $stayinfo=[];
-
-
-
- //用户认证待审核数量
- $stayinfo['auth_count'] = Db::name('user_auth')->where("status=0")->count();
-
-
- $this->assign("stayinfo",$stayinfo);
- return $this->fetch();
- }
-
- public function getdata(){
- $rs=['code'=>0,'msg'=>'','info'=>[]];
-
- $data = $this->request->param();
-
- $action=isset($data['action']) ? $data['action']: '';
- $type=isset($data['type']) ? $data['type']: '';
- $start_time=isset($data['start_time']) ? $data['start_time']: '';
- $end_time=isset($data['end_time']) ? $data['end_time']: '';
- $basic_type=isset($data['basic_type']) ? $data['basic_type']: '';
-
- $start=0;
- $end=time();
- if($type!=0){
- $nowtime=time();
- //当天0点
- $today=date("Ymd",$nowtime);
- $today_start=strtotime($today);
- //当天 23:59:59
- $today_end=strtotime("{$today} + 1 day");
- switch($type){
- case '1';
- /* 今日 */
- $start=$today_start;
- $end=$today_end;
- break;
- case '2';
- /* 昨日 */
- $yesterday_start=$today_start - 60*60*24;
- $yesterday_end=$today_start;
-
- $start=$yesterday_start;
- $end=$yesterday_end;
- break;
- case '3';
- /* 近7日 */
- $week_start=$today_end - 60*60*24*7;
- $week_end=$today_end;
-
- $start=$week_start;
- $end=$week_end;
- break;
- case '4';
- /* 近30日 */
- $month_start=$today_end - 60*60*24*30;
- $month_end=$today_end;
-
- $start=$month_start;
- $end=$month_end;
- break;
- }
-
- }else{
- if($start_time){
- $start=strtotime($start_time);
- }
- if($end_time){
- $end=strtotime($end_time) + 60*60*24;
- }
- }
- if(!$start){
- $rs['code']='1001';
- $rs['msg']='请选择开始时间';
- echo json_encode($rs);
- exit;
- }
- switch($action){
- case '3':
- $info=$this->getAnchorInfo($start,$end);
- break;
- case '4':
- $info=$this->getCharge($start,$end);
- break;
- case '5':
- $info=$this->getCash($start,$end);
- break;
- }
-
- $rs['info']=$info;
- echo json_encode($rs);
- exit;
- }
-
-
- /* 主播数据 */
- protected function getAnchorInfo($start,$end){
- $anchor_today=Db::name('live_record')->where("starttime >= {$start} and starttime<{$end}")->group("uid")->count();
- if(!$anchor_today){
- $anchor_today=0;
- }
- $anchor_live_today=Db::name('live_record')->where("starttime >= {$start} and starttime<{$end}")->count();
-
- $anchor_live_long_today=Db::query("select sum(endtime - starttime) as times from cmf_live_record where starttime >= {$start} and starttime<{$end}");
- $times=0;
- if($anchor_live_long_today){
- $times=$anchor_live_long_today[0]['times'];
- }
- if($times>0){
- $times=number_format(floor($times/60));
- }
- $info=[
- 'anchor_today'=>$anchor_today,
- 'anchor_live_today'=>$anchor_live_today,
- 'anchor_live_long_today'=>$times,
- ];
- return $info;
- }
-
- /* 财务 */
- protected function getCharge($start,$end){
- $data_charge=[
- 'name'=>[],
- 'money'=>[],
- 'color'=>[],
- ];
- $charge_type=[
- '1'=>'支付宝',
- '2'=>'微信',
- '3'=>'苹果支付',
- ];
- $charge_ambient=[
- '1'=>[
- '0'=>'APP',
- '1'=>'PC',
- ],
- '2'=>[
- '0'=>'APP',
- '1'=>'公众号',
- '2'=>'PC',
- ],
- '3'=>[
- '0'=>'沙盒',
- '1'=>'生产',
- ],
- ];
- $charge_color=['#f44957','#5bc189','#33c5f1','#f8c299'];
- $charge_total_today=Db::name('charge_user')->where("status=1 and addtime>={$start} and addtime<{$end}")->sum("money");
- if(!$charge_total_today){
- $charge_total_today=0;
- }
-
- $data_charge['color']=$charge_color;
- $data_charge['name'][]='充值总额';
- $data_charge['money'][]=$charge_total_today;
- foreach($charge_type as $k=>$v){
- $data_charge['name'][]=$v;
- $money=Db::name('charge_user')->where("status=1 and type={$k} and addtime>={$start} and addtime<{$end}")->sum("money");
- if(!$money){
- $money=0;
- }
-
- $data_charge['money'][]=$money;
-
- }
-
- return $data_charge;
- }
-
- /* 提现 */
- protected function getCash($start,$end){
- $cash_apply=Db::name('cash_record')->where("status=0 and addtime>={$start} and addtime<{$end}")->sum("money");
- if(!$cash_apply){
- $cash_apply=0;
- }
- if($cash_apply>0){
- $cash_apply=number_format($cash_apply);
- }
-
- $cash_adopt=Db::name('cash_record')->where("status=1 and addtime>={$start} and addtime<{$end}")->sum("money");
- if(!$cash_adopt){
- $cash_adopt=0;
- }
- if($cash_adopt>0){
- $cash_adopt=number_format($cash_adopt);
- }
-
- $cash_anchor=Db::name('cash_record')->where("addtime>={$start} and addtime<{$end}")->group("uid")->count();
- if(!$cash_anchor){
- $cash_anchor=0;
- }
- if($cash_anchor>0){
- $cash_anchor=number_format($cash_anchor);
- }
-
- $info=[
- 'cash_apply'=>$cash_apply,
- 'cash_adopt'=>$cash_adopt,
- 'cash_anchor'=>$cash_anchor,
- ];
- return $info;
-
- }
-
- /* 导出 */
- function export(){
- $data = $this->request->param();
-
- $action=isset($data['action']) ? $data['action']: '';
- $type=isset($data['type']) ? $data['type']: '';
- $start_time=isset($data['start_time']) ? $data['start_time']: '';
- $end_time=isset($data['end_time']) ? $data['end_time']: '';
- $basic_type=isset($data['basic_type']) ? $data['basic_type']: '';
-
- $start=0;
- $end=time();
- if($type!=0){
- $nowtime=time();
- //当天0点
- $today=date("Ymd",$nowtime);
- $today_start=strtotime($today);
- //当天 23:59:59
- $today_end=strtotime("{$today} + 1 day");
- switch($type){
- case '1';
- /* 今日 */
- $start=$today_start;
- $end=$today_end;
- break;
- case '2';
- /* 昨日 */
- $yesterday_start=$today_start - 60*60*24;
- $yesterday_end=$today_start;
-
- $start=$yesterday_start;
- $end=$yesterday_end;
- break;
- case '3';
- /* 近7日 */
- $week_start=$today_end - 60*60*24*7;
- $week_end=$today_end;
-
- $start=$week_start;
- $end=$week_end;
- break;
- case '4';
- /* 近30日 */
- $month_start=$today_end - 60*60*24*30;
- $month_end=$today_end;
-
- $start=$month_start;
- $end=$month_end;
- break;
- }
-
- }else{
- if($start_time){
- $start=strtotime($start_time);
- }
- if($end_time){
- $end=strtotime($end_time) + 60*60*24;
- }
- }
-
- if($start==0){
- exit;
- }
-
- $xlsData=[];
- switch($action){
- case '1':
- $starttime=$start;
- $endtime=$end;
- $start=date("Y-m-d",$starttime);
- $end=date("Y-m-d",($endtime - 60*60*24));
- $congifpri=getConfigPri();
- if($start == $end){
- $periodType='hourly';
- $title=' 基本指标 '.$start;
-
- $date=['00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00',];
- }else{
- $periodType='daily';
- $title=' 基本指标 '.$start.'至'.$end;
- }
- $xlsName = " 基本指标导出";
- $cellName = array('A','B','C','D','E');
-
- $xlsCell = array('date','newUsers','launches','duration','activityUsers');
-
- $xlsData[]=[
- 'date'=>$title,
- 'newUsers'=>'',
- 'launches'=>'',
- 'duration'=>'',
- 'activityUsers'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>'时间',
- 'newUsers'=>'新注册用户(位)',
- 'launches'=>'APP启动次数(次)',
- 'duration'=>'平均使用时长( 分钟)',
- 'activityUsers'=>'活跃用户数(位)',
- 'ismerge'=>'0',
- ];
-
-
- if($congifpri['um_appkey_android']){
- $appkey=$congifpri['um_appkey_android'];
- $newusers_android=$this->getNewUsers($appkey,$start,$end,$periodType);
- $launches_android=$this->getLaunches($appkey,$start,$end,$periodType);
- if($periodType!='hourly'){
- $durations_android=$this->getDurations($appkey,$start,$end,$periodType);
- }
-
- $activeusers_android=$this->getActiveUsers($appkey,$start,$end,$periodType);
- }
-
- if($congifpri['um_appkey_ios']){
- $appkey=$congifpri['um_appkey_ios'];
- $newusers_ios=$this->getNewUsers($appkey,$start,$end,$periodType);
- $launches_ios=$this->getLaunches($appkey,$start,$end,$periodType);
- if($periodType!='hourly'){
- $durations_ios=$this->getDurations($appkey,$start,$end,$periodType);
- }
- $activeusers_ios=$this->getActiveUsers($appkey,$start,$end,$periodType);
- }
-
-
- if($periodType!='hourly'){
- for($i=$starttime,$n=0;$i<$endtime;$i+=60*60*24,$n++){
- $newUsers_a=isset($newusers_android[$n]['value'])?$newusers_android[$n]['value']:0;
- $newUsers_i=isset($newusers_ios[$n]['value'])?$newusers_ios[$n]['value']:0;
-
- $launches_a=isset($launches_android[$n]['value'])?$launches_android[$n]['value']:0;
- $launches_i=isset($launches_ios[$n]['value'])?$launches_ios[$n]['value']:0;
-
- $duration_a=isset($durations_android[$n])?$durations_android[$n]:0;
- $duration_i=isset($durations_ios[$n])?$durations_ios[$n]:0;
-
- $activityUsers_a=isset($activeusers_android[$n]['value'])?$activeusers_android[$n]['value']:0;
- $activityUsers_i=isset($activeusers_ios[$n]['value'])?$activeusers_ios[$n]['value']:0;
-
-
- $info=[];
- $info['date']=date("Y-m-d",$i);
- $info['newUsers']=$newUsers_a + $newUsers_i;
- $info['launches']=$launches_a + $launches_i;
- $info['duration']=floor( ($duration_a + $duration_i)/60);
- $info['activityUsers']=$activityUsers_a + $activityUsers_i;
- $info['ismerge']='0';
- $xlsData[]=$info;
- }
-
- }else{
- for($n=0;$n<24;$n++){
-
- $newUsers_a=isset($newusers_android[0]['hourValue'][$n])?$newusers_android[0]['hourValue'][$n]:0;
- $newUsers_i=isset($newusers_ios[0]['hourValue'][$n])?$newusers_ios[0]['hourValue'][$n]:0;
-
- $launches_a=isset($launches_android[0]['hourValue'][$n])?$launches_android[0]['hourValue'][$n]:0;
- $launches_i=isset($launches_ios[0]['hourValue'][$n])?$launches_ios[0]['hourValue'][$n]:0;
-
-
- $activityUsers_a=isset($activeusers_android[0]['hourValue'][$n])?$activeusers_android[0]['hourValue'][$n]:0;
- $activityUsers_i=isset($activeusers_ios[0]['hourValue'][$n])?$activeusers_ios[0]['hourValue'][$n]:0;
-
- $info=[];
- $info['date']=$date[$n];
- $info['newUsers']=$newUsers_a + $newUsers_i;
- $info['launches']=$launches_a + $launches_i;
- $info['duration']=0;
- $info['activityUsers']=$activityUsers_a + $activityUsers_i;
- $info['ismerge']='0';
- $xlsData[]=$info;
- }
- }
- break;
- case '2':
- //$info=$this->getUsers($start,$end);
- break;
- case '3':
-
- $anchor_live_long_today=Db::query("select sum(endtime - starttime) as times from cmf_live_record");
- $times=0;
- if($anchor_live_long_today){
- $times=$anchor_live_long_today[0]['times'];
- }
- if($times>0){
- $times=number_format(floor($times/60));
- }
-
- $xlsName = "主播数据导出";
- $cellName = array('A','B','C','D','E');
-
- $xlsCell = array('date','anchor_today','anchor_live_today','anchor_live_long_today');
-
- $xlsData[]=[
- 'date'=>'总直播时长 '.$times.' 分钟',
- 'anchor_today'=>'',
- 'anchor_live_today'=>'',
- 'anchor_live_long_today'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>date("Y-m-d",$start).'至'.date("Y-m-d",($end-1)),
- 'anchor_today'=>'',
- 'anchor_live_today'=>'',
- 'anchor_live_long_today'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>'时间',
- 'anchor_today'=>'开播主播数量(位)',
- 'anchor_live_today'=>'直播次数( 次)',
- 'anchor_live_long_today'=>'直播时长(分钟)',
- 'ismerge'=>'0',
- ];
-
- for($i=$start;$i<$end;$i+=60*60*24){
- $i2=$i+60*60*24;
- $info=$this->getAnchorInfo($i,$i2);
- $info['date']=date("Y-m-d",$i);
- $info['ismerge']='0';
- $xlsData[]=$info;
- }
-
- break;
- case '4':
-
- $xlsName = "财务导出";
- $cellName = array('A','B','C','D','E');
-
- $charge_total=Db::name('charge_user')->where("status=1")->sum("money");
- if(!$charge_total){
- $charge_total=0;
- }
- if($charge_total>0){
- $charge_total=number_format($charge_total);
- }
-
- $xlsCell = array('date','total','ali','wx','apple');
-
- $xlsData[]=[
- 'date'=>'历史总收益 '.$charge_total.' 元',
- 'total'=>'',
- 'ali'=>'',
- 'wx'=>'',
- 'apple'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>date("Y-m-d",$start).'至'.date("Y-m-d",($end-1)),
- 'total'=>'',
- 'ali'=>'',
- 'wx'=>'',
- 'apple'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>'时间',
- 'total'=>'充值金额(元)',
- 'ali'=>'支付宝充值( 元)',
- 'wx'=>'微信充值(元)',
- 'apple'=>'苹果充值( 元)',
- 'ismerge'=>'0',
- ];
-
- for($i=$start;$i<$end;$i+=60*60*24){
- $i2=$i+60*60*24;
- $char_info=$this->getCharge($i,$i2);
- $info=[];
- $info['date']=date("Y-m-d",$i);
- $info['total']=$char_info['money'][0];
- $info['ali']=$char_info['money'][1];
- $info['wx']=$char_info['money'][2];
- $info['apple']=$char_info['money'][3];
- $info['ismerge']='0';
- $xlsData[]=$info;
- }
- break;
- case '5':
- $xlsName = "提现导出";
- $cellName = array('A','B','C','D');
-
- $cash_total=Db::name('cash_record')->where("status=1")->sum("money");
- if(!$cash_total){
- $cash_total=0;
- }
- if($cash_total>0){
- $cash_total=number_format($cash_total);
- }
-
- $xlsCell = array('date','cash_apply','cash_adopt','cash_anchor');
-
- $xlsData[]=[
- 'date'=>'总提现金额 '.$cash_total.' 元',
- 'cash_apply'=>'',
- 'cash_adopt'=>'',
- 'cash_anchor'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>date("Y-m-d",$start).'至'.date("Y-m-d",($end-1)),
- 'cash_apply'=>'',
- 'cash_adopt'=>'',
- 'cash_anchor'=>'',
- 'ismerge'=>'1',
- ];
-
- $xlsData[]=[
- 'date'=>'时间',
- 'cash_apply'=>'申请金额(元)',
- 'cash_adopt'=>'已通过金额(元)',
- 'cash_anchor'=>'主播提现数量( 位)',
- 'ismerge'=>'0',
- ];
-
- for($i=$start;$i<$end;$i+=60*60*24){
- $i2=$i+60*60*24;
- $info=$this->getCash($i,$i2);
- $info['date']=date("Y-m-d",$i);
- $info['ismerge']='0';
- $xlsData[]=$info;
- }
- break;
- }
-
- $this->exportExcel($xlsName,$xlsCell,$xlsData,$cellName);
- }
-
- /**导出Excel 表格
- * @param $expTitle 名称
- * @param $expCellName 参数
- * @param $expTableData 内容
- * @throws \PHPExcel_Exception
- * @throws \PHPExcel_Reader_Exception
- */
- protected function exportExcel($xlsName,$expCellName,$expTableData,$cellName)
- {
- $xlsTitle = iconv('utf-8', 'gb2312', $xlsName);//文件名称
- $fileName = $xlsTitle.'_'.date('YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
- $cellNum = count($expCellName);
- $dataNum = count($expTableData);
-
- $path= CMF_ROOT.'sdk/PHPExcel/';
- require_once( $path ."PHPExcel.php");
-
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);
- for($i=0;$i<$dataNum;$i++){
- $cellinfo=$expTableData[$i];
- if($cellinfo['ismerge']==1){
- $objPHPExcel->getActiveSheet()->mergeCells('A'.($i+1).':'.end($cellName).($i+1));//合并单元格(如果要拆分单元格是需要先合并再拆分的,否则程序会报错)
-
- $objPHPExcel->getActiveSheet(0)->setCellValue('A'.($i+1), $cellinfo[$expCellName[0]]);
- }else{
- for($j=0;$j<$cellNum;$j++){
- $key=$expCellName[$j];
- $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+1), $cellinfo[$key]);
- }
- }
-
- }
- header('pragma:public');
- header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
- header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');//Excel5为xls格式,excel2007为xlsx格式
- $objWriter->save('php://output');
- exit;
- }
- }
|