JoinListController.class.php
4.65 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* 【后台】活动参与情况导出
* Created by PhpStorm.
* Date: 2018/6/11
*/
namespace Apicp\Controller\Export;
use Com\PackageValidate;
use Com\PythonExcel;
use Common\Common\Constant;
use Common\Common\ExportDownload;
use Common\Service\ActivityService;
use Common\Service\CommentService;
class JoinListController extends \Apicp\Controller\AbstractController
{
public function Index_post()
{
// 获取参数
$params = I('post.');
// 参数验证
$this->validate_params($params);
// 活动详情
$activity_service = new ActivityService();
$activity_info = $activity_service->get($params['ac_id']);
// 活动不存在或已被删除
if (empty($activity_info)) {
E('_ERR_ACTIVITY_DATA');
}
$list = [];
$comment_service = new CommentService();
// 已参与
if (Constant::ACTIVITY_JOIN_TYPE_TRUE == $params['is_join']) {
// 已参与人数
$join_num = $comment_service->count_join($params);
if ($join_num) {
// 已参与列表
$list = $comment_service->export_join_data($params);
}
} elseif (Constant::ACTIVITY_JOIN_TYPE_FALSE == $params['is_join']) { // 未参与
// 获取未参与人数、人员id集合
$unjoin_result = $comment_service->count_unjoin($params);
if ($unjoin_result['unjoin_num']) {
// 未参与列表
$list = $comment_service->export_join_data($params, $unjoin_result['unjoin_uids']);
}
}
// 生成下载Excel
$this->download($params['is_join'], $list);
}
/**
* 学员导出
*
* @param array $list 导出数据
*
* @return bool
*/
protected function download($is_join, $list = [])
{
$rows = [];
// 已参与
if (Constant::ACTIVITY_JOIN_TYPE_TRUE == $is_join) {
// Excel 表头字段
$title = [
'姓名',
'组织',
'岗位',
'角色',
'手机',
'最后参与时间'
];
// 数据处理
foreach ($list as $v) {
// 赋值
$rows[] = [
$v['memUsername'],
$v['dpName'],
$v['jobName'],
$v['roleName'],
$v['telephone'],
$v['last_join_time']
];
}
// 文件名称
$file_name = '员圈活动-已参与人员' . rgmdate(MILLI_TIME, 'YmdHis');
} elseif (Constant::ACTIVITY_JOIN_TYPE_FALSE == $is_join) { // 未参与
// Excel 表头字段
$title = [
'姓名',
'组织',
'岗位',
'角色',
'手机'
];
// 数据处理
foreach ($list as $v) {
// 赋值
$rows[] = [
$v['memUsername'],
$v['dpName'],
$v['jobName'],
$v['roleName'],
$v['telephone']
];
}
// 文件名称
$file_name = '员圈活动-未参与人员' . rgmdate(MILLI_TIME, 'YmdHis');
}
// 路径
$real_path = ExportDownload::get_down_dir($this->_login->user['eaId'] . microtime(true)) . NOW_TIME . '.xls';
// 生成Excel、下载
$ret = PythonExcel::instance()->write($real_path, $title, $rows);
if ($ret) {
$conditions = [
'title' => $file_name,
'ea_id' => $this->_login->user['eaId'],
'username' => $this->_login->user['eaRealname'],
'type' => ExportDownload::EXCEL_TYPE,
'url' => $real_path
];
ExportDownload::insert_down_load($conditions);
}
return true;
}
/**
* 参数验证
*
* @param $params
*/
protected function validate_params($params)
{
// 验证规则
$rules = [
'ac_id' => 'require',
'is_join' => 'require|between:1,2',
];
$msg = [
'ac_id.require' => L('_EMPTY_ACTIVITY_ID'),
'is_join.require' => L('_ERR_JOIN_STATUS_PARAMS'),
'is_join.between' => L('_ERR_JOIN_STATUS_PARAMS'),
];
// 验证数据
$validate = new PackageValidate();
$validate->postData = $params;
$validate->validateParams($rules, $msg);
}
}