AuditController.class.php
4.49 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
<?php
/**
*【线下培训-后台】报名审核
*
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-08-29 10:07:24
*/
namespace Apicp\Controller\Team;
use Common\Service\EducationService;
use Common\Service\RightUsersService;
class AuditController extends \Apicp\Controller\AbstractController
{
public function Index_post()
{
$params = I('post.');
$ed_id = intval($params['ed_id']);
if (!$ed_id) {
E('_EMPTY_ED_ID');
}
// 获取培训数据
$education_server = new EducationService();
$education = $education_server->get($ed_id);
if (empty($education)) {
E('_ERR_EDUCATION_NOT_EXIST');
}
$ru_ids = $params['ru_ids'];
// 人员参数不能为空
if (empty($ru_ids)) {
E('_EMPTY_RU_IDS');
}
// 人员参数无效
if (!is_array($ru_ids)) {
E('_ERR_RU_IDS_INVALID');
}
$ru_check_status = intval($params['ru_check_status']);
// 审核参数不能为空
if (empty($ru_check_status)) {
E('_EMPTY_RU_CHECK_STATUS');
}
// 审核参数无效
if (!in_array($ru_check_status, [RightUsersService::SIGN_CHECK_PASS, RightUsersService::SIGN_CHECK_UN_PASS])) {
E('_ERR_RU_CHECK_STATUS_INVALID');
}
$right_users_service = new RightUsersService();
// 开启审核
if ($education['ed_is_sign_up'] == EducationService::EDUCATION_SIGN_OPEN
&& $education['ed_is_check'] == EducationService::EDUCATION_CHECK
&& RightUsersService::SIGN_CHECK_PASS == $params['ru_check_status']) {
$where = [
'ru_check_status' => RightUsersService::SIGN_CHECK_PASS,
'ed_id' => $ed_id
];
$count = $right_users_service->count_by_conds($where);
$count_ru_ids = count($params['ru_ids']) + $count;
if ($education['ed_sign_up_number'] > 0 && $count_ru_ids > $education['ed_sign_up_number']) {
// 报名人数超过限额
E('_ERR_EDU_USER_COUNT');
}
}
// 审核内容
$params['ru_comments'] = raddslashes($params['ru_comments']);
unset($params['ed_id'], $params['ru_ids']);
$conds['ru_id'] = $ru_ids;
// 查询已经审核过的人员
$e_joined_count = $right_users_service->count_by_conds([
'ru_id' => $ru_ids,
'ru_check_status' => RightUsersService::SIGN_CHECK_PASS
]);
try {
$right_users_service->start_trans();
// 更新要进行审核的人员
$res = $right_users_service->update_by_conds($conds, $params);
if ($res) {
// 通过
if (RightUsersService::SIGN_CHECK_PASS == $params['ru_check_status']) {
// 更新培训已参与人数(增) 减掉之前通过的
$education_server->update(
$ed_id,
['ed_joined_count' => $education['ed_joined_count'] + count($ru_ids) - $e_joined_count]
);
} elseif (RightUsersService::SIGN_CHECK_UN_PASS == $params['ru_check_status']) {
// 更新培训已参与人数(减) 前去之前通过的
$education_server->update(
$ed_id,
['ed_joined_count' => $education['ed_joined_count'] - $e_joined_count]
);
}
}
$right_users_service->commit();
} catch (\Exception $e) {
$right_users_service->rollback();
return false;
}
// 组装消息通知参数数组
$check_status = '';
if (RightUsersService::SIGN_CHECK_PASS == $ru_check_status) {
$check_status = '已通过';
} elseif (RightUsersService::SIGN_CHECK_UN_PASS == $ru_check_status) {
$check_status = '未通过';
}
$right_users = $right_users_service->list_by_conds($conds);
$ru_uids = array_column($right_users, 'ru_uid');
$msg_params = [
'ed_id' => $ed_id,
'name' => $education['ed_name'],
'content' => $params['ru_comments'],
'uids' => $ru_uids,
'check_status' => $check_status
];
// 发送提醒消息
$right_users_service->send_msg($msg_params, EducationService::MSG_CHECK_STATUS);
}
}