IndexController.class.php
4.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*/**
* 【员圈直播】导出直播情况
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-06-01 09:41:09
* @version $Id$
*/
namespace Apicp\Controller\Export;
use Common\Common\Constant;
use Common\Common\ExportDownload;
use Common\Service\MainService;
use Common\Service\ParticipateService;
use Common\Service\RangeService;
use Com\PythonExcel;
class IndexController extends \Apicp\Controller\AbstractController
{
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
return true;
}
public function Index()
{
$lm_id = I('lm_id');
$watch_type = I('watch_type');
if (empty($lm_id)) {
E('_EMPTY_DOWN__LIVE_ID');
}
if (!in_array($watch_type, array(Constant::LIVE_WATCH_TYPE_FALSE, Constant::LIVE_WATCH_TYPE_TRUE))) {
E('_ERR_DOWN__WATCH_TYPE_INVALID');
}
$postData = array('lm_id' => $lm_id, 'watch_type' => $watch_type);
// 获取直播信息
$mainService = new MainService();
$mainDetail = $mainService->get($lm_id);
// 直播信息不存在
if (empty($mainDetail)) {
E('_ERR_DOWN_LIVE_IS_NOT_EXIST');
}
// 直播已观看、未观看、可观看人员UID
$rangeServ = new RangeService();
list($uids_watched, $uids_unwatch, $uids_all) = $rangeServ->getWatchDataUids($lm_id);
// 初始化数据
$list = [];
$participateService = new ParticipateService();
// 已观看人员列表
if (Constant::LIVE_WATCH_TYPE_TRUE == $watch_type) {
$list = $participateService->DownWatchedData($postData);
} elseif (Constant::LIVE_WATCH_TYPE_FALSE == $postData['watch_type']) {
$list = $participateService->DownUnwatchData($uids_unwatch);
}
// 执行导出
$this->_download($list, $watch_type);
return true;
}
/**
* 导出模板
*
* @param array $list 列表数据
* @param int $watch_type 导出类型
*/
private function _download($list = [], $watch_type = 0)
{
$row_data = [];
// 直播人员(已参与)
if (Constant::LIVE_WATCH_TYPE_TRUE == $watch_type) {
$file_name = '导出参与直播人员' . date('_YmdHi');
$title = array(
'姓名',
'组织',
'岗位',
'角色',
'手机',
'最后参与时间',
);
foreach ($list as $k => $v) {
$row_data[] = array(
$v['memUsername'],
$v['dpName'],
$v['jobName'],
$v['roleName'],
$v['telephone'],
rgmdate($v['last_watched_time'], "'Y-m-d H:i"),
);
}
} else {
$file_name = '导出未参与直播人员' . date('_YmdHi');
$title = array(
'姓名',
'组织',
'岗位',
'角色',
'手机'
);
foreach ($list as $k => $v) {
$row_data[] = array(
$v['memUsername'],
$v['dpName'],
$v['jobName'],
$v['roleName'],
$v['telephone']
);
}
}
// 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;
}
}