ListController.class.php
3.48 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 16/9/18
* Time: 11:52
*/
namespace Api\Controller\Invite;
use Common\Common\Department;
use Common\Common\User;
use Common\Service\InviteUserService;
class ListController extends AbstractController
{
/**
* 我的邀请、审核列表
* @author zhonglei
*/
public function Index_post()
{
$checkStatus = I('post.check_status', 0, 'intval');
$page = I('post.page', 1, 'Intval');
$pageSize = I('post.limit', 15, 'Intval');
// 验证传参
if (empty($checkStatus)) {
E('_ERR_PARAM_IS_NULL');
return false;
}
// 审核状态是否存在
$status = [
InviteUserService::CHECK_STATUS_WAIT,
InviteUserService::CHECK_STATUS_PASS,
];
if (!in_array($checkStatus, $status)) {
E('_ERR_INVITE_INVALID_STATUS');
}
// 已审核、未审核条件
$conds = [
'`u`.`check_status`' => InviteUserService::CHECK_STATUS_WAIT,
];
if ($checkStatus == InviteUserService::CHECK_STATUS_PASS) {
unset($conds['`u`.`check_status`']);
$conds['`u`.`check_uid`'] = $this->_login->user['memUid'];
}
// 我的邀请列表
$conds['`r`.`udtid`'] = array($this->uid);
$myDpIds = $this->_getMyDpId($this->uid);
if (!empty($myDpIds)) {
$conds['`r`.`udtid`'] = array_merge($myDpIds, $conds['`r`.`udtid`']);
}
list($start, $limit, $page) = page_limit($page, $pageSize);
$inviteUserServ = new InviteUserService();
list($inviteIds, $count) = $inviteUserServ->listByRight($conds, [
$start,
$limit,
], ['`u`.`created`' => 'DESC'], 'DISTINCT `r`.`invite_id`');
$invites = $inviteUserServ->list_by_pks(array_column($inviteIds, 'invite_id'), ['created' => 'DESC']);
$list = [];
if ($invites) {
$uids = array_column($invites, 'uid');
$userServ = new User();
$users = $userServ->listByUid($uids);
foreach ($invites as $v) {
$user = $v['uid'] && isset($users[$v['uid']]) ? $users[$v['uid']] : null;
$is_follow = InviteUserService::USER_IS_FOLLOW_FALSE;
if ($user && $user['memSubscribeStatus'] == InviteUserService::USER_IS_FOLLOW_TRUE) {
$is_follow = InviteUserService::USER_IS_FOLLOW_TRUE;
}
$list[] = [
'invite_id' => $v['invite_id'],
'type' => $v['type'],
'username' => $user ? $user['memUsername'] : $v['username'],
'face' => $user ? $user['memFace'] : '',
'is_follow' => $is_follow,
'check_status' => $v['check_status'],
'time' => $v['created'],
];
}
}
$this->_result = [
'page' => $page,
'limit' => $pageSize,
'total' => intval($count),
'list' => $list,
];
}
/**
* 获取我负责的部门
* @param $uid
* @return array
*/
protected function _getMyDpId($uid)
{
$dpIds = array();
$departments = Department::instance()->listAll();
foreach ($departments as $_dp) {
if ($_dp['dpLead'] == $uid) {
$dpIds[] = $_dp['dpId'];
}
}
return $dpIds;
}
}