ListController.class.php
5.38 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
141
142
143
144
145
146
147
148
149
150
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/7/12
* Time: 15:33
*/
namespace Apicp\Controller\Exam;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\User;
use Common\Service\ArticleService;
use Common\Service\ExamService;
class ListController extends \Apicp\Controller\AbstractController
{
/**
* List
* @author liyifei
* @desc 课程、素材测评明细列表
* @param Int page:1 当前页
* @param Int limit:20 每页数据总数
* @param Int article_id:true 课程ID(article_id>0,article_chapter_id=0时,查询课程测评)
* @param Int article_chapter_id:false:0 素材所在章节ID
* @param Int source_id:false:0 素材ID
* @return array 题库列表
array(
'page' => 1, // 当前页
'limit' => 20, // 当前页条数
'total' => 100, // 总条数
'article_name' => '音频单课程', // 课程名称
'update_time' => '1494495893272', // 更新时间
'list' => array( // 列表数据
array(
'username' => '张三', // 姓名
'dp_name' => array('技术部', '产品部'), // 部门
'job' => 'CTO', // 职位
'mobile' => 13167166666, // 手机号
'exam_total' => 2, // 测评次数
'pass_total' => 1, // 通过次数
'timestamp' => 1494495893272, // 测评时间
),
),
),
*/
public function Index_post()
{
// 验证规则
$rules = [
'page' => 'integer',
'limit' => 'integer',
'article_id' => 'require|integer',
'article_chapter_id' => 'integer',
'source_id' => 'integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 查询课程信息
$articleServ = new ArticleService();
$article = $articleServ->get($postData['article_id']);
if (empty($article)) {
E('课程不存在');
}
// 分页默认值
$postData['page'] = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE;
$postData['limit'] = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT;
list($start, $perpage) = page_limit($postData['page'], $postData['limit']);
// 组合搜索条件
$conds = [];
if ($postData['article_id'] > 0) {
$conds['source_id'] = 0;
$conds['article_chapter_id'] = 0;
$conds['article_id'] = $postData['article_id'];
}
if ($postData['article_chapter_id'] > 0 && $postData['source_id'] > 0) {
if (isset($conds['article_id'])) {
unset($conds['article_id']);
}
$conds['source_id'] = $postData['source_id'];
$conds['article_chapter_id'] = $postData['article_chapter_id'];
}
// 课程列表
$examServ = new ExamService();
$uidList = $examServ->listUidByConds($conds, [$start, $perpage]);
$formatList = [];
if (!empty($uidList)) {
// 从UC获取人员详情
$uids = array_column($uidList, 'uid');
$userServ = &User::instance();
$users = $userServ->listByConds(['memUids' => $uids]);
$uidUser = [];
if (isset($users) && !empty($users['list'])) {
$uidUser = array_combine_by_key($users['list'], 'memUid');
}
// 获取相应人员所有测评列表
$conds['uid'] = $uids;
$list = $examServ->list_by_conds($conds, null, ['created' => 'ASC']);
if (!empty($list)) {
foreach ($uids as $uid) {
foreach ($list as $v) {
if ($uid == $v['uid']) {
$formatList[$uid] = [
'username' => $uidUser[$uid]['memUsername'],
'dp_name' => $uidUser[$uid]['dpName'] ? array_column($uidUser[$uid]['dpName'], 'dpName') : [],
'job' => isset($uidUser[$uid]['memJob']) ? $uidUser[$uid]['memJob'] : '',
'mobile' => isset($uidUser[$uid]['memMobile']) ? $uidUser[$uid]['memMobile'] : '',
'exam_total' => $formatList[$uid]['exam_total'] + 1,
'pass_total' => $v['is_pass'] == Constant::ARTICLE_EXAM_IS_PASS ? $formatList[$uid]['pass_total'] + 1 : intval($formatList[$uid]['pass_total']),
'timestamp' => $v['created'],
];
}
}
}
}
}
// 数据总数
$total = $examServ->countUidByConds($conds);
$this->_result = [
'page' => $postData['page'],
'limit' => $postData['limit'],
'total' => intval($total),
'article_name' => $article['article_title'],
'update_time' => $article['update_time'],
'list' => array_values($formatList),
];
}
}