UnJoinListController.class.php
3.11 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
<?php
/**
* 导出未参与人员列表
* User: daijun
* Date: 18/3/24
* Time: 下午3:44
*/
namespace Apicp\Controller\Export;
use Common\Common\ExportDownload;
use Common\Common\UserCache;
use Com\PythonExcel;
use Common\Service\ActivityService;
use Common\Service\RecordService;
use Common\Service\RightService;
class UnJoinListController extends \Apicp\Controller\AbstractController
{
public function Index()
{
// 获取参数
$ac_id = I('post.ac_id');
if (empty($ac_id)) {
// 活动ID不能为空
E('_EMPTY_ACTIVITY_ID');
}
$activity_serv = new ActivityService();
$detail = $activity_serv->get($ac_id);
if (empty($detail)) {
// 活动信息不存在
E('_ERR_ACTIVITY_DATA');
}
$record_serv = new RecordService();
$record_list = $record_serv->list_by_conds(['ac_id' => $ac_id], null, [], 'uid');
// 已参与的人员uid集合
$uids = [];
if (!empty($record_list)) {
$uids = array_filter(array_unique(array_column($record_list, 'uid')));
}
// 查询权限人员集合
$right = new RightService();
$all_right_users = $right->get_uids_by_right($detail);
// 获取未参与人员uid集合
$un_join_uids = array_diff($all_right_users, $uids);
// 从缓存获取用户列表
$list = UserCache::get_all_user_by_cache_list($un_join_uids);
$rand_str = substr(md5(QY_DOMAIN), 0, 1) . substr(md5(QY_DOMAIN), -1);
$file_name = $detail['title'] . '未参与记录_' . rgmdate(strval(MILLI_TIME), 'YmdHis') . $rand_str; // 导出文件名称
// 生成下载Excel
$this->_download($list, $file_name);
return true;
}
/**
* 导出模板
*
* @param array $list 导出数据
* @param string $file_name 文件名称
*
* @return bool
*/
protected function _download($list = [], $file_name)
{
// Excel 表头字段
$title = [
'姓名',
'组织',
'岗位',
'角色',
'手机号',
];
$rows = [];
// 数据处理
foreach ($list as $v) {
$rows[] = [
$v['memUsername'],
implode(',', array_column($v['dpName'], 'dpName')),
$v['memJob'],
$v['memRole'],
" " . $v['memMobile'],
];
}
unset($list);
$dir = DATA_PATH;
// 生成Excel 下载
$real_path = $dir . D_S . $file_name . '.xls';
$ret = PythonExcel::instance()->write($real_path, $title, $rows);
if ($ret) {
$data = [
'title' => $file_name,
'ea_id' => $this->_login->user['eaId'],
'type' => ExportDownload::EXCEL_TYPE,
'username' => $this->_login->user['eaRealname'],
'url' => $real_path,
'app_dir' => APP_DIR
];
ExportDownload::insert_down_load($data);
}
return true;
}
}