MainController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. class MainController extends AdminbaseController {
  15. public function index(){
  16. $config=getConfigPub();
  17. $this->assign("config",$config);
  18. $nowtime=time();
  19. //当天0点
  20. $today=date("Y-m-d",$nowtime);
  21. $today_start=strtotime($today);
  22. //当天 23:59:59
  23. $today_end=strtotime("{$today} + 1 day");
  24. /* 总注册数 */
  25. $users_total=Db::name('user')->where("user_type=2")->count();
  26. $this->assign("users_total",number_format($users_total));
  27. //设备终端
  28. $source=Db::name('user')
  29. ->field("count(id) as nums,source")
  30. ->where("user_type=2")
  31. ->group("source")
  32. ->select()
  33. ->toArray();
  34. $data_source=[
  35. 'name'=>[],
  36. 'nums'=>[],
  37. 'nums_per'=>[],
  38. 'color'=>[],
  39. ];
  40. $color=['#99ce87','#5ba1f8','#f4a76d','#99ba64'];
  41. if($source){
  42. $nums=array_column($source,'nums');
  43. $nums_totoal=array_sum($nums);
  44. foreach($source as $k=>$v){
  45. $data_source['name'][]=$v['source'];
  46. $data_source['nums'][]=$v['nums'];
  47. $data_source['color'][]=$color[$k];
  48. $data_source['nums_per'][]=round($v['nums']*100/$nums_totoal);
  49. }
  50. }
  51. $this->assign("data_sourcej",json_encode($data_source));
  52. /* 注册渠道 */
  53. $login_type=Db::name('user')
  54. ->field("count(id) as nums,login_type")
  55. ->where("user_type=2")
  56. ->group("login_type")
  57. ->order("nums desc")
  58. ->select()
  59. ->toArray();
  60. $data_type=[
  61. 'name'=>[],
  62. 'v_n'=>[],
  63. ];
  64. $color_v_n=['#0972f4','#3289f6','#65a6f7','#8dbdf9','#b7d1f2'];
  65. if($login_type){
  66. foreach($login_type as $k=>$v){
  67. $data_type['v_n'][]=['value'=>$v['nums'],'name'=>$v['login_type'],'itemStyle'=>['color'=>$color_v_n[$k]]];
  68. $data_type['name'][]=$v['login_type'];
  69. }
  70. }
  71. $this->assign("data_typej",json_encode($data_type));
  72. /* 主播数据 */
  73. $anchor_total=Db::name('user')->where("user_type=2")->count();
  74. $anchor_online=Db::name('live')->where("islive=1")->count();
  75. $anchor_live_long_total=Db::query("select sum(endtime - starttime) as times from cmf_live_record");
  76. //$anchor_live_long_total=Db::name('live_record')->sum("endtime - starttime");
  77. $times=0;
  78. if($anchor_live_long_total){
  79. $times=$anchor_live_long_total[0]['times'];
  80. }
  81. if($times>0){
  82. $times=number_format(floor($times/60));
  83. }
  84. $anchorinfo=$this->getAnchorInfo($today_start,$today_end);
  85. $anchor=[
  86. 'anchor_total'=>$anchor_total,
  87. 'anchor_online'=>$anchor_online,
  88. 'anchor_live_long_total'=>$times,
  89. ];
  90. $anchor=array_merge($anchor,$anchorinfo);
  91. $this->assign("anchor",$anchor);
  92. /* 网红榜 */
  93. $votes_list=Db::name('user')
  94. ->field("id,user_nicename,avatar,avatar_thumb,votestotal")
  95. ->where("user_type=2")
  96. ->order("votestotal desc")
  97. ->limit(0,3)
  98. ->select()
  99. ->toArray();
  100. foreach($votes_list as $k=>$v){
  101. $v['avatar']=get_upload_path($v['avatar']);
  102. $v['avatar_thumb']=get_upload_path($v['avatar_thumb']);
  103. $votes_list[$k]=$v;
  104. }
  105. $this->assign("votes_list",$votes_list);
  106. /* 富豪榜 */
  107. $rich_list=Db::name('user')
  108. ->field("id,user_nicename,avatar,avatar_thumb,consumption")
  109. ->where("user_type=2")
  110. ->order("consumption desc")
  111. ->limit(0,3)
  112. ->select()
  113. ->toArray();
  114. foreach($rich_list as $k=>$v){
  115. $v['avatar']=get_upload_path($v['avatar']);
  116. $v['avatar_thumb']=get_upload_path($v['avatar_thumb']);
  117. $rich_list[$k]=$v;
  118. }
  119. $this->assign("rich_list",$rich_list);
  120. /* 财务 */
  121. $charge_total=Db::name('charge_user')->where("status=1")->sum("money");
  122. if(!$charge_total){
  123. $charge_total=0;
  124. }
  125. if($charge_total>0){
  126. $charge_total=number_format($charge_total);
  127. }
  128. $data_charge=$this->getCharge($today_start,$today_end);
  129. $this->assign("charge_total",$charge_total);
  130. $this->assign("data_chargej",json_encode($data_charge));
  131. /* 提现 */
  132. $cashinfo=$this->getCash($today_start,$today_end);
  133. $cash_total=Db::name('cash_record')->where("status=1")->sum("money");
  134. if(!$cash_total){
  135. $cash_total=0;
  136. }
  137. if($cash_total>0){
  138. $cash_total=number_format($cash_total);
  139. }
  140. $this->assign("cashinfo",$cashinfo);
  141. $this->assign("cash_total",$cash_total);
  142. $stayinfo=[];
  143. //用户认证待审核数量
  144. $stayinfo['auth_count'] = Db::name('user_auth')->where("status=0")->count();
  145. $this->assign("stayinfo",$stayinfo);
  146. return $this->fetch();
  147. }
  148. public function getdata(){
  149. $rs=['code'=>0,'msg'=>'','info'=>[]];
  150. $data = $this->request->param();
  151. $action=isset($data['action']) ? $data['action']: '';
  152. $type=isset($data['type']) ? $data['type']: '';
  153. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  154. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  155. $basic_type=isset($data['basic_type']) ? $data['basic_type']: '';
  156. $start=0;
  157. $end=time();
  158. if($type!=0){
  159. $nowtime=time();
  160. //当天0点
  161. $today=date("Ymd",$nowtime);
  162. $today_start=strtotime($today);
  163. //当天 23:59:59
  164. $today_end=strtotime("{$today} + 1 day");
  165. switch($type){
  166. case '1';
  167. /* 今日 */
  168. $start=$today_start;
  169. $end=$today_end;
  170. break;
  171. case '2';
  172. /* 昨日 */
  173. $yesterday_start=$today_start - 60*60*24;
  174. $yesterday_end=$today_start;
  175. $start=$yesterday_start;
  176. $end=$yesterday_end;
  177. break;
  178. case '3';
  179. /* 近7日 */
  180. $week_start=$today_end - 60*60*24*7;
  181. $week_end=$today_end;
  182. $start=$week_start;
  183. $end=$week_end;
  184. break;
  185. case '4';
  186. /* 近30日 */
  187. $month_start=$today_end - 60*60*24*30;
  188. $month_end=$today_end;
  189. $start=$month_start;
  190. $end=$month_end;
  191. break;
  192. }
  193. }else{
  194. if($start_time){
  195. $start=strtotime($start_time);
  196. }
  197. if($end_time){
  198. $end=strtotime($end_time) + 60*60*24;
  199. }
  200. }
  201. if(!$start){
  202. $rs['code']='1001';
  203. $rs['msg']='请选择开始时间';
  204. echo json_encode($rs);
  205. exit;
  206. }
  207. switch($action){
  208. case '3':
  209. $info=$this->getAnchorInfo($start,$end);
  210. break;
  211. case '4':
  212. $info=$this->getCharge($start,$end);
  213. break;
  214. case '5':
  215. $info=$this->getCash($start,$end);
  216. break;
  217. }
  218. $rs['info']=$info;
  219. echo json_encode($rs);
  220. exit;
  221. }
  222. /* 主播数据 */
  223. protected function getAnchorInfo($start,$end){
  224. $anchor_today=Db::name('live_record')->where("starttime >= {$start} and starttime<{$end}")->group("uid")->count();
  225. if(!$anchor_today){
  226. $anchor_today=0;
  227. }
  228. $anchor_live_today=Db::name('live_record')->where("starttime >= {$start} and starttime<{$end}")->count();
  229. $anchor_live_long_today=Db::query("select sum(endtime - starttime) as times from cmf_live_record where starttime >= {$start} and starttime<{$end}");
  230. $times=0;
  231. if($anchor_live_long_today){
  232. $times=$anchor_live_long_today[0]['times'];
  233. }
  234. if($times>0){
  235. $times=number_format(floor($times/60));
  236. }
  237. $info=[
  238. 'anchor_today'=>$anchor_today,
  239. 'anchor_live_today'=>$anchor_live_today,
  240. 'anchor_live_long_today'=>$times,
  241. ];
  242. return $info;
  243. }
  244. /* 财务 */
  245. protected function getCharge($start,$end){
  246. $data_charge=[
  247. 'name'=>[],
  248. 'money'=>[],
  249. 'color'=>[],
  250. ];
  251. $charge_type=[
  252. '1'=>'支付宝',
  253. '2'=>'微信',
  254. '3'=>'苹果支付',
  255. ];
  256. $charge_ambient=[
  257. '1'=>[
  258. '0'=>'APP',
  259. '1'=>'PC',
  260. ],
  261. '2'=>[
  262. '0'=>'APP',
  263. '1'=>'公众号',
  264. '2'=>'PC',
  265. ],
  266. '3'=>[
  267. '0'=>'沙盒',
  268. '1'=>'生产',
  269. ],
  270. ];
  271. $charge_color=['#f44957','#5bc189','#33c5f1','#f8c299'];
  272. $charge_total_today=Db::name('charge_user')->where("status=1 and addtime>={$start} and addtime<{$end}")->sum("money");
  273. if(!$charge_total_today){
  274. $charge_total_today=0;
  275. }
  276. $data_charge['color']=$charge_color;
  277. $data_charge['name'][]='充值总额';
  278. $data_charge['money'][]=$charge_total_today;
  279. foreach($charge_type as $k=>$v){
  280. $data_charge['name'][]=$v;
  281. $money=Db::name('charge_user')->where("status=1 and type={$k} and addtime>={$start} and addtime<{$end}")->sum("money");
  282. if(!$money){
  283. $money=0;
  284. }
  285. $data_charge['money'][]=$money;
  286. }
  287. return $data_charge;
  288. }
  289. /* 提现 */
  290. protected function getCash($start,$end){
  291. $cash_apply=Db::name('cash_record')->where("status=0 and addtime>={$start} and addtime<{$end}")->sum("money");
  292. if(!$cash_apply){
  293. $cash_apply=0;
  294. }
  295. if($cash_apply>0){
  296. $cash_apply=number_format($cash_apply);
  297. }
  298. $cash_adopt=Db::name('cash_record')->where("status=1 and addtime>={$start} and addtime<{$end}")->sum("money");
  299. if(!$cash_adopt){
  300. $cash_adopt=0;
  301. }
  302. if($cash_adopt>0){
  303. $cash_adopt=number_format($cash_adopt);
  304. }
  305. $cash_anchor=Db::name('cash_record')->where("addtime>={$start} and addtime<{$end}")->group("uid")->count();
  306. if(!$cash_anchor){
  307. $cash_anchor=0;
  308. }
  309. if($cash_anchor>0){
  310. $cash_anchor=number_format($cash_anchor);
  311. }
  312. $info=[
  313. 'cash_apply'=>$cash_apply,
  314. 'cash_adopt'=>$cash_adopt,
  315. 'cash_anchor'=>$cash_anchor,
  316. ];
  317. return $info;
  318. }
  319. /* 导出 */
  320. function export(){
  321. $data = $this->request->param();
  322. $action=isset($data['action']) ? $data['action']: '';
  323. $type=isset($data['type']) ? $data['type']: '';
  324. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  325. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  326. $basic_type=isset($data['basic_type']) ? $data['basic_type']: '';
  327. $start=0;
  328. $end=time();
  329. if($type!=0){
  330. $nowtime=time();
  331. //当天0点
  332. $today=date("Ymd",$nowtime);
  333. $today_start=strtotime($today);
  334. //当天 23:59:59
  335. $today_end=strtotime("{$today} + 1 day");
  336. switch($type){
  337. case '1';
  338. /* 今日 */
  339. $start=$today_start;
  340. $end=$today_end;
  341. break;
  342. case '2';
  343. /* 昨日 */
  344. $yesterday_start=$today_start - 60*60*24;
  345. $yesterday_end=$today_start;
  346. $start=$yesterday_start;
  347. $end=$yesterday_end;
  348. break;
  349. case '3';
  350. /* 近7日 */
  351. $week_start=$today_end - 60*60*24*7;
  352. $week_end=$today_end;
  353. $start=$week_start;
  354. $end=$week_end;
  355. break;
  356. case '4';
  357. /* 近30日 */
  358. $month_start=$today_end - 60*60*24*30;
  359. $month_end=$today_end;
  360. $start=$month_start;
  361. $end=$month_end;
  362. break;
  363. }
  364. }else{
  365. if($start_time){
  366. $start=strtotime($start_time);
  367. }
  368. if($end_time){
  369. $end=strtotime($end_time) + 60*60*24;
  370. }
  371. }
  372. if($start==0){
  373. exit;
  374. }
  375. $xlsData=[];
  376. switch($action){
  377. case '1':
  378. $starttime=$start;
  379. $endtime=$end;
  380. $start=date("Y-m-d",$starttime);
  381. $end=date("Y-m-d",($endtime - 60*60*24));
  382. $congifpri=getConfigPri();
  383. if($start == $end){
  384. $periodType='hourly';
  385. $title=' 基本指标 '.$start;
  386. $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',];
  387. }else{
  388. $periodType='daily';
  389. $title=' 基本指标 '.$start.'至'.$end;
  390. }
  391. $xlsName = " 基本指标导出";
  392. $cellName = array('A','B','C','D','E');
  393. $xlsCell = array('date','newUsers','launches','duration','activityUsers');
  394. $xlsData[]=[
  395. 'date'=>$title,
  396. 'newUsers'=>'',
  397. 'launches'=>'',
  398. 'duration'=>'',
  399. 'activityUsers'=>'',
  400. 'ismerge'=>'1',
  401. ];
  402. $xlsData[]=[
  403. 'date'=>'时间',
  404. 'newUsers'=>'新注册用户(位)',
  405. 'launches'=>'APP启动次数(次)',
  406. 'duration'=>'平均使用时长( 分钟)',
  407. 'activityUsers'=>'活跃用户数(位)',
  408. 'ismerge'=>'0',
  409. ];
  410. if($congifpri['um_appkey_android']){
  411. $appkey=$congifpri['um_appkey_android'];
  412. $newusers_android=$this->getNewUsers($appkey,$start,$end,$periodType);
  413. $launches_android=$this->getLaunches($appkey,$start,$end,$periodType);
  414. if($periodType!='hourly'){
  415. $durations_android=$this->getDurations($appkey,$start,$end,$periodType);
  416. }
  417. $activeusers_android=$this->getActiveUsers($appkey,$start,$end,$periodType);
  418. }
  419. if($congifpri['um_appkey_ios']){
  420. $appkey=$congifpri['um_appkey_ios'];
  421. $newusers_ios=$this->getNewUsers($appkey,$start,$end,$periodType);
  422. $launches_ios=$this->getLaunches($appkey,$start,$end,$periodType);
  423. if($periodType!='hourly'){
  424. $durations_ios=$this->getDurations($appkey,$start,$end,$periodType);
  425. }
  426. $activeusers_ios=$this->getActiveUsers($appkey,$start,$end,$periodType);
  427. }
  428. if($periodType!='hourly'){
  429. for($i=$starttime,$n=0;$i<$endtime;$i+=60*60*24,$n++){
  430. $newUsers_a=isset($newusers_android[$n]['value'])?$newusers_android[$n]['value']:0;
  431. $newUsers_i=isset($newusers_ios[$n]['value'])?$newusers_ios[$n]['value']:0;
  432. $launches_a=isset($launches_android[$n]['value'])?$launches_android[$n]['value']:0;
  433. $launches_i=isset($launches_ios[$n]['value'])?$launches_ios[$n]['value']:0;
  434. $duration_a=isset($durations_android[$n])?$durations_android[$n]:0;
  435. $duration_i=isset($durations_ios[$n])?$durations_ios[$n]:0;
  436. $activityUsers_a=isset($activeusers_android[$n]['value'])?$activeusers_android[$n]['value']:0;
  437. $activityUsers_i=isset($activeusers_ios[$n]['value'])?$activeusers_ios[$n]['value']:0;
  438. $info=[];
  439. $info['date']=date("Y-m-d",$i);
  440. $info['newUsers']=$newUsers_a + $newUsers_i;
  441. $info['launches']=$launches_a + $launches_i;
  442. $info['duration']=floor( ($duration_a + $duration_i)/60);
  443. $info['activityUsers']=$activityUsers_a + $activityUsers_i;
  444. $info['ismerge']='0';
  445. $xlsData[]=$info;
  446. }
  447. }else{
  448. for($n=0;$n<24;$n++){
  449. $newUsers_a=isset($newusers_android[0]['hourValue'][$n])?$newusers_android[0]['hourValue'][$n]:0;
  450. $newUsers_i=isset($newusers_ios[0]['hourValue'][$n])?$newusers_ios[0]['hourValue'][$n]:0;
  451. $launches_a=isset($launches_android[0]['hourValue'][$n])?$launches_android[0]['hourValue'][$n]:0;
  452. $launches_i=isset($launches_ios[0]['hourValue'][$n])?$launches_ios[0]['hourValue'][$n]:0;
  453. $activityUsers_a=isset($activeusers_android[0]['hourValue'][$n])?$activeusers_android[0]['hourValue'][$n]:0;
  454. $activityUsers_i=isset($activeusers_ios[0]['hourValue'][$n])?$activeusers_ios[0]['hourValue'][$n]:0;
  455. $info=[];
  456. $info['date']=$date[$n];
  457. $info['newUsers']=$newUsers_a + $newUsers_i;
  458. $info['launches']=$launches_a + $launches_i;
  459. $info['duration']=0;
  460. $info['activityUsers']=$activityUsers_a + $activityUsers_i;
  461. $info['ismerge']='0';
  462. $xlsData[]=$info;
  463. }
  464. }
  465. break;
  466. case '2':
  467. //$info=$this->getUsers($start,$end);
  468. break;
  469. case '3':
  470. $anchor_live_long_today=Db::query("select sum(endtime - starttime) as times from cmf_live_record");
  471. $times=0;
  472. if($anchor_live_long_today){
  473. $times=$anchor_live_long_today[0]['times'];
  474. }
  475. if($times>0){
  476. $times=number_format(floor($times/60));
  477. }
  478. $xlsName = "主播数据导出";
  479. $cellName = array('A','B','C','D','E');
  480. $xlsCell = array('date','anchor_today','anchor_live_today','anchor_live_long_today');
  481. $xlsData[]=[
  482. 'date'=>'总直播时长 '.$times.' 分钟',
  483. 'anchor_today'=>'',
  484. 'anchor_live_today'=>'',
  485. 'anchor_live_long_today'=>'',
  486. 'ismerge'=>'1',
  487. ];
  488. $xlsData[]=[
  489. 'date'=>date("Y-m-d",$start).'至'.date("Y-m-d",($end-1)),
  490. 'anchor_today'=>'',
  491. 'anchor_live_today'=>'',
  492. 'anchor_live_long_today'=>'',
  493. 'ismerge'=>'1',
  494. ];
  495. $xlsData[]=[
  496. 'date'=>'时间',
  497. 'anchor_today'=>'开播主播数量(位)',
  498. 'anchor_live_today'=>'直播次数( 次)',
  499. 'anchor_live_long_today'=>'直播时长(分钟)',
  500. 'ismerge'=>'0',
  501. ];
  502. for($i=$start;$i<$end;$i+=60*60*24){
  503. $i2=$i+60*60*24;
  504. $info=$this->getAnchorInfo($i,$i2);
  505. $info['date']=date("Y-m-d",$i);
  506. $info['ismerge']='0';
  507. $xlsData[]=$info;
  508. }
  509. break;
  510. case '4':
  511. $xlsName = "财务导出";
  512. $cellName = array('A','B','C','D','E');
  513. $charge_total=Db::name('charge_user')->where("status=1")->sum("money");
  514. if(!$charge_total){
  515. $charge_total=0;
  516. }
  517. if($charge_total>0){
  518. $charge_total=number_format($charge_total);
  519. }
  520. $xlsCell = array('date','total','ali','wx','apple');
  521. $xlsData[]=[
  522. 'date'=>'历史总收益 '.$charge_total.' 元',
  523. 'total'=>'',
  524. 'ali'=>'',
  525. 'wx'=>'',
  526. 'apple'=>'',
  527. 'ismerge'=>'1',
  528. ];
  529. $xlsData[]=[
  530. 'date'=>date("Y-m-d",$start).'至'.date("Y-m-d",($end-1)),
  531. 'total'=>'',
  532. 'ali'=>'',
  533. 'wx'=>'',
  534. 'apple'=>'',
  535. 'ismerge'=>'1',
  536. ];
  537. $xlsData[]=[
  538. 'date'=>'时间',
  539. 'total'=>'充值金额(元)',
  540. 'ali'=>'支付宝充值( 元)',
  541. 'wx'=>'微信充值(元)',
  542. 'apple'=>'苹果充值( 元)',
  543. 'ismerge'=>'0',
  544. ];
  545. for($i=$start;$i<$end;$i+=60*60*24){
  546. $i2=$i+60*60*24;
  547. $char_info=$this->getCharge($i,$i2);
  548. $info=[];
  549. $info['date']=date("Y-m-d",$i);
  550. $info['total']=$char_info['money'][0];
  551. $info['ali']=$char_info['money'][1];
  552. $info['wx']=$char_info['money'][2];
  553. $info['apple']=$char_info['money'][3];
  554. $info['ismerge']='0';
  555. $xlsData[]=$info;
  556. }
  557. break;
  558. case '5':
  559. $xlsName = "提现导出";
  560. $cellName = array('A','B','C','D');
  561. $cash_total=Db::name('cash_record')->where("status=1")->sum("money");
  562. if(!$cash_total){
  563. $cash_total=0;
  564. }
  565. if($cash_total>0){
  566. $cash_total=number_format($cash_total);
  567. }
  568. $xlsCell = array('date','cash_apply','cash_adopt','cash_anchor');
  569. $xlsData[]=[
  570. 'date'=>'总提现金额 '.$cash_total.' 元',
  571. 'cash_apply'=>'',
  572. 'cash_adopt'=>'',
  573. 'cash_anchor'=>'',
  574. 'ismerge'=>'1',
  575. ];
  576. $xlsData[]=[
  577. 'date'=>date("Y-m-d",$start).'至'.date("Y-m-d",($end-1)),
  578. 'cash_apply'=>'',
  579. 'cash_adopt'=>'',
  580. 'cash_anchor'=>'',
  581. 'ismerge'=>'1',
  582. ];
  583. $xlsData[]=[
  584. 'date'=>'时间',
  585. 'cash_apply'=>'申请金额(元)',
  586. 'cash_adopt'=>'已通过金额(元)',
  587. 'cash_anchor'=>'主播提现数量( 位)',
  588. 'ismerge'=>'0',
  589. ];
  590. for($i=$start;$i<$end;$i+=60*60*24){
  591. $i2=$i+60*60*24;
  592. $info=$this->getCash($i,$i2);
  593. $info['date']=date("Y-m-d",$i);
  594. $info['ismerge']='0';
  595. $xlsData[]=$info;
  596. }
  597. break;
  598. }
  599. $this->exportExcel($xlsName,$xlsCell,$xlsData,$cellName);
  600. }
  601. /**导出Excel 表格
  602. * @param $expTitle 名称
  603. * @param $expCellName 参数
  604. * @param $expTableData 内容
  605. * @throws \PHPExcel_Exception
  606. * @throws \PHPExcel_Reader_Exception
  607. */
  608. protected function exportExcel($xlsName,$expCellName,$expTableData,$cellName)
  609. {
  610. $xlsTitle = iconv('utf-8', 'gb2312', $xlsName);//文件名称
  611. $fileName = $xlsTitle.'_'.date('YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
  612. $cellNum = count($expCellName);
  613. $dataNum = count($expTableData);
  614. $path= CMF_ROOT.'sdk/PHPExcel/';
  615. require_once( $path ."PHPExcel.php");
  616. $objPHPExcel = new \PHPExcel();
  617. $objPHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);
  618. for($i=0;$i<$dataNum;$i++){
  619. $cellinfo=$expTableData[$i];
  620. if($cellinfo['ismerge']==1){
  621. $objPHPExcel->getActiveSheet()->mergeCells('A'.($i+1).':'.end($cellName).($i+1));//合并单元格(如果要拆分单元格是需要先合并再拆分的,否则程序会报错)
  622. $objPHPExcel->getActiveSheet(0)->setCellValue('A'.($i+1), $cellinfo[$expCellName[0]]);
  623. }else{
  624. for($j=0;$j<$cellNum;$j++){
  625. $key=$expCellName[$j];
  626. $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+1), $cellinfo[$key]);
  627. }
  628. }
  629. }
  630. header('pragma:public');
  631. header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
  632. header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
  633. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');//Excel5为xls格式,excel2007为xlsx格式
  634. $objWriter->save('php://output');
  635. exit;
  636. }
  637. }