ExportDeleteController.class.php
4.28 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 18/6/6
* Time: 19:56
*/
namespace Apicp\Controller\User;
use Com\PackageValidate;
use Com\PythonExcel;
use Common\Common\ExportDownload;
use Common\Common\User;
use Common\Service\UserService;
class ExportDeleteController extends AbstractController
{
/**
* ExportDelete
* @author liyifei
* @desc 被删除人员导出接口
* @param Int start_time 删除开始时间
* @param Int end_time 删除结束时间
* @param String username 姓名关键字
* @param String mobile 手机号
* @param String email 邮箱
* @param Array dp_ids 部门ID
* @param Array job_ids 岗位ID
* @param Array role_ids 角色ID
* @return mixed
*/
public function Index_post()
{
$role = $this->_login->role;
// 验证规则
$rules = [
'page' => 'integer',
'limit' => 'integer',
'start_time' => 'integer',
'end_time' => 'integer',
'username' => 'max:64',
'mobile' => 'max:64',
'email' => 'max:64',
'dp_ids' => 'array',
'job_ids' => 'array',
'role_ids' => 'array',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// UC查询条件
$conds = [
'eqMemStatus' => User::STATUS_DELETED,
'departmentChildrenFlag' => UserService::DEPT_CHILDREN_FLAG,
];
if (isset($postData['username']) && strlen($postData['username']) > 0) {
$conds['memUsername'] = $postData['username'];
}
if (isset($postData['mobile']) && strlen($postData['mobile']) > 0) {
$conds['memMobile'] = $postData['mobile'];
}
if (isset($postData['email']) && strlen($postData['email']) > 0) {
$conds['memEmail'] = $postData['email'];
}
// 部门
if (!empty($postData['dp_ids'])) {
$conds['dpIdList'] = (array)$postData['dp_ids'];
} elseif (!empty($role['readDpIdList'])) {
$conds['dpIdList'] = $role['readDpIdList'];
}
if (!empty($postData['job_ids'])) {
$conds['jobIdList'] = (array)$postData['job_ids'];
}
if (!empty($postData['role_ids'])) {
$conds['roleIdList'] = (array)$postData['role_ids'];
}
if (!empty($postData['start_time'])) {
$conds['memDeletedStart'] = $postData['start_time'];
}
if (!empty($postData['end_time'])) {
$conds['memDeletedEnd'] = $postData['end_time'];
}
// UC排序规则(不传排序参数时,UC根据姓名全拼排序,如姓名是英文或中英文混合,则英文优先)
$orderList = [
'memDeleted' => 'DESC',
];
$newUser = new User();
$result = $newUser->listAll($conds, $orderList);
$rows = [];
foreach ($result as $user) {
$rows[] = [
$user['memUsername'],
$user['memGender'] == 1 ? '男' : '女',
$user['memMobile'],
$user['memEmail'],
isset($user['memDeleted']) ? rgmdate($user['memDeleted']) : '',
];
}
// 生成 Excel 并输出
$filename = rgmdate(NOW_TIME, 'Y') . rgmdate(NOW_TIME, 'm') . rgmdate(NOW_TIME, 'd') . '_删除员工列表';
// 生成文件路径
$site_dir = ExportDownload::get_down_dir($this->_login->user['eaId'] . microtime(true));
$titles = ['姓名', '性别', '手机号', '邮箱', '删除时间'];
$ret = PythonExcel::instance()->write($site_dir . $filename . '.xls', $titles, $rows);
if ($ret) {
// 数据写入到下载中心
$conditon = [
'title' => $filename,
'ea_id' => $this->_login->user['eaId'],
'type' => ExportDownload::EXCEL_TYPE,
'size' => filesize($site_dir . $filename . '.xls'),
'url' => $site_dir . $filename . '.xls',
'username' => $this->_login->user['eaRealname'],
'app_dir' => APP_DIR
];
ExportDownload::insert_down_load($conditon);
}
}
}