RemindBeginController.class.php
3.06 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
<?php
/**
* 考试开始前定时提醒回调
*/
namespace Frontend\Controller\Callback;
use Common\Common\Msg;
use Common\Service\AnswerService;
use Common\Service\RightService;
use VcySDK\Cron;
use VcySDK\Logger;
use VcySDK\Service;
use Common\Service\PaperService;
class RemindBeginController extends AbstractController
{
/** @var PaperService 试卷信息表 */
protected $paper_s;
/** @var RightService 用户回复信息表 */
protected $right_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化试卷表
$this->paper_s = new PaperService();
// 实例化权限表
$this->right_s = new RightService();
return true;
}
public function Index()
{
// 获取需要发送的试卷id
$back = $this->callBackData;
$ep_id = $back['ep_id'];
Logger::write('=========进入开始前提醒定时任务=======ep_id' . $ep_id);
// 非空判断
if (empty($ep_id)) {
return true;
}
// 获取试卷基本详情
$data = $this->paper_s->get($ep_id);
if (empty($data)) {
return true;
}
$conds = array(
'epc_id' => $ep_id,
'er_type' => AnswerService::RIGHT_PAPER
);
// 参与考试的权限范围
if ($data['is_all'] != RightService::AUTH_ALL) {
$rights = $this->right_s->list_by_conds($conds);
// 格式化权限范围
$right_view = $this->right_s->format_db_data($rights);
}
$right_view['is_all'] = $data['is_all'];
// 获取要参加考试的全部人员
$all_join = $this->right_s->list_uids_by_right($right_view);
// 如果还没有发送过消息
if (count($all_join) > 0) {
Logger::write('用户ID集合存在');
sort($all_join);
// 分割成多个元素分组
$uid_groups = array_chunk($all_join, Msg::USER_MAX_COUNT);
$params['id'] = $ep_id;
$params['name'] = $data['ep_name'];
$params['description'] = $data['intro'];
$params['begin_time'] = $data['begin_time'];
$params['end_time'] = $data['end_time'];
$params['img_id'] = $data['cover_id'];
$params['is_cover_open'] = $data['is_cover_open'];
// 分批发送
foreach ($uid_groups as $uid_group) {
$params['uids'] = $uid_group;
// 推送消息
$this->paper_s->send_msg($params, PaperService::ANSWER_START);
}
}
$crId = strval($data['cron_send_msg']);
Logger::write('删除任务ID:' . $crId);
// 一次执行的定时任务已经执行,所以删除paper表中储存的cronId
$this->paper_s->update($ep_id,
array(
'begin_corn' => ''
));
Logger::write('=========结束开始前提醒定时任务=======');
return true;
}
}