RankListCacheController.class.php
2.37 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
<?php
/**
* 考试排名列表定时回调
*/
namespace Frontend\Controller\Callback;
use Think\Log;
use VcySDK\Cron;
use VcySDK\Service;
use Common\Common\Cache;
use Common\Service\AnswerService;
use Common\Service\PaperService;
class RankListCacheController extends AbstractController
{
/** @var PaperService 试卷信息表 */
protected $paper_s;
/** @var AnswerService 回答信息表 */
protected $answer_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化试卷表
$this->paper_s = new PaperService();
// 实例化回答表
$this->answer_s = new AnswerService();
return true;
}
public function Index()
{
// 获取需要发送的试卷id
$back = I('get.');
$ep_id = $back['ep_id'];
Log::record('=========进入考试排名定时任务=======ep_id:' . $ep_id);
// 非空判断
if (empty($ep_id)) {
return true;
}
// 获取试卷基本详情
$data = $this->paper_s->get($ep_id);
// 如果试卷不存在或者试卷不是发布或者已终止状态
if (empty($data) || $data['exam_status'] < 2) {
return true;
}
// 考试尚未开始
if ($data['begin_time'] > MILLI_TIME) {
return true;
}
$cron_serv = new Cron(Service::instance());
$crid = $data['cron_rank_id'];
Log::record('=========进入考试排名定时任务=======任务ID:' . $crid);
if ($data['end_time'] < $data['makeup_end_time']) {
$end_time = $data['makeup_end_time'];
} else {
$end_time = $data['end_time'];
}
// 结束时间延后30分钟
$del_time = $end_time + 30 * 60 * 1000;
if ($del_time < MILLI_TIME && !empty($crid)) {
// 考试结束后30分钟删除统计任务
$cron_serv->delete($crid);
return true;
}
// 实例化缓存
$cache = &Cache::instance();
// 查询考试成绩列表
$rank_list = $this->answer_s->get_rank_all_list($ep_id);
$cache->set('Common.Exam_Rank_List_' . $ep_id, $rank_list);
Log::record('=========结束考试排名定时任务=======ep_id:' . $ep_id);
return true;
}
}