AuthRangeController.class.php
2.15 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
<?php
/**
* 【考试中心-手机端】获取考试范围接口
* AuthRangeController.class.php
*/
namespace Api\Controller\Paper;
use Common\Common\Cache;
use Common\Service\PaperService;
use Common\Service\RightService;
class AuthRangeController extends AbstractController
{
public function Index_post()
{
// 接收post参数
$ep_id = I('post.ep_id');
// 试卷id为空
if (empty($ep_id)) {
E('_EMPTY_EP_ID');
}
// 实例化缓存
$cache =&Cache::instance();
// 初始化缓存信息
$auth_info = [];
try {
// 获取当前试卷缓存信息
$auth_info = $cache->get('Common.Exam_wx_' . $ep_id . '_auth');
} catch (\Think\Exception $e) {
\Think\Log::record($e);
} catch (\Exception $e) {
\Think\Log::record($e);
}
// 实例化试卷service
$paper_s = new PaperService();
// 根据试卷id查询试卷信息
$data = $paper_s->get($ep_id);
// 试卷信息不存在
if (empty($data)) {
E('_EMPTY_PAPER_DATA');
}
// 如果缓存不存在
if (empty($auth_info)) {
// 试卷权限
$right_data = [];
// 非全公司
if (PaperService::NO_AUTH_ALL == $data['is_all']) {
// 实例化权限service
$right_s = new RightService();
// 权限查询条件:试卷id,权限表类型标识(试卷权限)
$right_conds = [
'epc_id' => $ep_id,
'er_type' => PaperService::RIGHT_PAPER
];
// 格式化权限数据
list($list, $right_data) = $right_s->get_right_data($right_conds, true);
}
$auth_info = [
'right' => $right_data,
'is_all' => (int)$data['is_all']
];
// 如果没有缓存新增缓存
$cache->set('Common.Exam_wx_' . $ep_id . '_auth', $auth_info, 600);
}
// 返回结果
$this->_result = $auth_info;
}
}