ConcurrentController.class.php
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* User: zoulongbo
* Date: 2018/7/26
* Time: 11:18
*/
namespace Apicp\Controller\Export;
use Com\PythonExcel;
use Common\Common\ExportDownload;
use Common\Common\Vhall;
class ConcurrentController extends AbstractController
{
public function Index_post()
{
$params = I('post.');
if (!$params) {
E('_ERR_PARAMS_CAN_NOT_EMPTY');
}
$params['orderList'] = [
[
"column" => "onTime",
"orderType" => "DESC"
]
];
// 获取当前直播数据全部列表
$concurrentTotals = Vhall::instance()->concurrencyNum($params);
$this->_download($concurrentTotals, $params);
return true;
}
/**
* 导出模板
* @param array $watchTotals 详情
* @param array $params 请求参数
* @return bool
*/
private function _download($concurrentTotals = [], $params = [])
{
// 初始化导出数据
$file_name = '';
$row_data = [];
$file_name = $params['title'] . '_并发数' . date('_YmdHi');
$title = [
'直播名称',
'时间点',
'人数',
];
//组装直播用户数据,添加title
foreach ($concurrentTotals as $key => $value) {
$row_data[] = [
$params['title'],
rgmdate($value['onTime'], 'Y-m-d H:i'),
$value['onNum'],
];
}
// Python导出excel
$realpath = ExportDownload::get_down_dir($this->_login->user['eaId'] . microtime(true)) . $file_name . ".xls";
$ret = PythonExcel::instance()->write($realpath, $title, $row_data);
if ($ret) {
$conditon = [
'title' => $file_name,
'ea_id' => $this->_login->user['eaId'],
'username' => $this->_login->user['eaRealname'],
'type' => ExportDownload::EXCEL_TYPE,
'url' => $realpath
];
ExportDownload::insert_down_load($conditon);
}
return true;
}
}