QuestionListController.class.php
8.17 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
* 提问列表接口
* User: tangxingguo
* Date: 2017/4/11
* Time: 18:36
*/
namespace Apicp\Controller\Answer;
use Com\PackageValidate;
use Common\Common\AnswerHelper;
use Common\Common\Constant;
use Common\Common\User;
use Common\Service\ClassService;
use Common\Service\QuestionService;
use Common\Service\SettingService;
class QuestionListController extends \Apicp\Controller\AbstractController
{
/**
* QuestionList
* @author
* @desc 提问列表
*
* @param Int page:1 当前页
* @param Int limit:20 每页数据总数
* @param String question_title 提问标题(max:20)
* @param Int class_id 分类ID
* @param String username 提问人姓名
* @param Int is_very 是否精品(0=全部 1=是 2=否)
* @param Int is_anonymous 是否匿名(0=全部 1=是 2=否)
* @param Array dp_ids 部门ID(一维数组)
* @param Int check_status 审核状态(1=未审核;2=审核通过;3=审核未通过)
* @param Int is_solve 解决状态(1=未解决;2=已解决)
* @param Int start_time 起始时间
* @param Int end_time 结束时间
*
* @return array 提问列表
array(
'total' => 3, // 数据总数
'wait_total' => 1, // 待审核提问数
'pass_total' => 1, // 通过审核提问数
'fail_total' => 1, // 未通过审核提问数
'list' => array( // 提问列表
'is_anonymous' => 1, // 是否匿名 (0=否 1=是)
'question_id' => 1, // 提问ID
'question_title' => '第一个提问', // 提问标题
'class_id' => 1, // 分类ID
'class_name' => '分类', // 分类名称
'username' => '张三', // 提问人姓名
'dp_name' => '技术部', // 提问人所属部门
'check_status' => 1, // 审核状态(1=未审核;2=审核通过;3=审核未通过)
'is_solve' => 1, // 解决状态(1=未解决;2=已解决)
'answer_pass_total' => 10, // 审核通过数
'answer_wait_total' => 10, // 等等审核数
'created' => 1491897290000, // 提问时间
)
)
*/
public function Index_post()
{
// 验证规则
$rules = [
'page' => 'integer',
'limit' => 'integer',
'question_title' => 'max:20',
'class_id' => 'integer',
'username' => 'max:50',
'dp_ids' => 'array',
'check_status' => 'integer|in:1,2,3',
'is_solve' => 'integer|in:1,2',
'start_time' => 'integer',
'end_time' => 'integer',
'is_very' => 'integer',
'is_anonymous' => 'integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 分页默认值
$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 (isset($postData['question_title'])) {
// 问题标题
$conds['question_title like ?'] = '%' . $postData['question_title'] . '%';
}
if (isset($postData['class_id'])) {
// 分类id
$conds['class_id'] = $postData['class_id'];
}
if (isset($postData['username'])) {
// 用户姓名
$conds['username like ?'] = '%' . $postData['username'] . '%';
}
if (isset($postData['dp_ids'])) {
// 取部门内所有人员,根据人员列表获取提问列表
$userServ = &User::instance();
$users = $userServ->listAll([
'dpIdList' => $postData['dp_ids'],
'departmentChildrenFlag' => $userServ::DEPARTMENT_CHILDREN_TRUE,
]);
if (!empty($users)) {
$uids = array_column($users, 'memUid');
$conds['uid'] = $uids;
}
}
if (isset($postData['check_status'])) {
// 审核状态
$conds['check_status'] = $postData['check_status'];
}
if (isset($postData['is_solve'])) {
// 解决状态
$conds['is_solve'] = $postData['is_solve'];
}
if (isset($postData['start_time'])) {
// 开始时间
$conds['created >= ?'] = $postData['start_time'];
}
if (isset($postData['end_time'])) {
// 结束时间
$conds['created <= ?'] = $postData['end_time'];
}
// 如果是精品
if($postData['is_very']==Constant::QUESTION_SELECT_VERY_OPEN){
$conds['very_time > ?'] = 0;
}
// 如果是不是精品
if($postData['is_very']==Constant::QUESTION_SELECT_VERY_CLOSE){
$conds['very_time'] = 0;
}
// 如果是匿名
if($postData['is_anonymous']==Constant::QUESTION_SELECT_ANONYMOUS_OPEN){
$conds['is_anonymous'] = 1;
}
// 如果不是匿名
if($postData['is_anonymous']==Constant::QUESTION_SELECT_ANONYMOUS_CLOSE){
$conds['is_anonymous'] = 0;
}
// 排序
$order_option = [
'top_time' => 'DESC',
'created' => 'DESC'
];
// 提问列表
$questionServ = new QuestionService();
$list = $questionServ->list_by_conds($conds, [$start, $perpage], $order_option);
if (!empty($list)) {
// 部门信息
$uids = array_values(array_column($list, 'uid'));
$answerHelper = &AnswerHelper::instance();
list($dpNames, $faceList, $usernameList) = $answerHelper->getUserInfo($uids);
// 分类信息
$classIds = array_values(array_column($list, 'class_id'));
$classServ = new ClassService();
$classList = $classServ->list_by_conds(['class_id' => $classIds]);
if (!empty($classList)) {
// 将分类列表转换成以分类id为主键的二维数组
$classList = array_combine_by_key($classList, 'class_id');
}
// 组合部门、分类名
foreach ($list as $k => $v) {
$list[$k]['username'] = isset($usernameList[$v['uid']]) ? $usernameList[$v['uid']] : $v['username'];
$list[$k]['dp_name'] = isset($dpNames[$v['uid']]) ? $dpNames[$v['uid']] : '';
$list[$k]['class_name'] = isset($classList[$v['class_id']]) ? $classList[$v['class_id']]['class_name'] : Constant::DEFAULT_CLASS_NAME;
}
}
// 数据总数量
$total = $questionServ->count_by_conds($conds);
// 待审核数量
$waitConds = $conds;
$waitConds['check_status'] = Constant::QUESTION_CHECK_STATUS_WAIT;
$waitTotal = $questionServ->count_by_conds($waitConds);
// 审核通过数量
$passConds = $conds;
$passConds['check_status'] = Constant::QUESTION_CHECK_STATUS_PASS;
$passTotal = $questionServ->count_by_conds($passConds);
// 未通过数量
$failConds = $conds;
$failConds['check_status'] = Constant::QUESTION_CHECK_STATUS_FAIL;
$failTotal = $questionServ->count_by_conds($failConds);
// 获取是否开启审核权限
$setting = new SettingService();
$is_check = $setting->get_is_check();
$this->_result = [
'total' => $total,
'wait_total' => $waitTotal,
'pass_total' => $passTotal,
'fail_total' => $failTotal,
'is_check' => $is_check,
'list' => $list,
];
}
}