ListController.class.php
2.84 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
<?php
/**
* 【后台】员工激励列表
* ListController.class.php
* @author:daijun
* @date:2017-08-31
*/
namespace Apicp\Controller\Incentives;
use Common\Service\IncentivesService;
use Common\Service\EducationService;
class ListController extends \Apicp\Controller\AbstractController
{
/**
* 员工激励列表接口
* @author daijun
*/
public function Index_post()
{
// 获取参数
$params = I('post.');
if (empty($params['ed_id'])) {
E('_EMPTY_ED_ID');
}
$education_server = new EducationService();
$education = $education_server->get($params['ed_id']);
// 培训不存在
if (empty($education)) {
E('_ERR_EDUCATION_NOT_EXIST');
}
// 获取培训状态
$ed_status = $education_server->get_ed_status($education);
$incentives_serv = new IncentivesService();
// 默认值
$page = !empty($params['page']) ? intval($params['page']) : self::PAGE_DEFAULT;
$limit = !empty($params['limit']) ? intval($params['limit']) : self::PAGE_LIMIT_DEFAULT;
list($start, $limit) = page_limit($page, $limit);
// 分页参数
$page_option = [$start, $limit];
//排序参数
$order_option = ['updated' => 'DESC', 'sr_id' => 'DESC'];
$uids = [];
// 如果部门、岗位、角色、用户姓名有一项不为空
if (!empty($params['dpIDs']) || !empty($params['jobID']) || !empty($params['roleID']) || !empty($params['memUsername'])) {
// 根据搜索条件获取用户ID集合(此处为各条件获取的用户uid的交集)
$uids = $incentives_serv->list_uids_by_dp_job_role($params['dpIDs'], $params['roleID'], $params['jobID'],
$params['memUsername']);
if (empty($uids)) {
// 表示搜索条件的交集为空,则意味着搜索结果为空,此处直接返回
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => 0,
'list' => []
];
return true;
}
}
// 组装查询条件
$conds['ed_id'] = $params['ed_id'];
if (!empty($uids)) {
$conds['sr_uid'] = $uids;
}
// 获取总数
$total = $incentives_serv->count_by_conds($conds);
$list = [];
if ($total > 0) {
// 查询列表
$list = $incentives_serv->list_by_conds($conds, $page_option, $order_option);
}
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => $total,
'ed_status' => $ed_status,
'list' => $incentives_serv->format_list_data($list)
];
return true;
}
}