ListController.class.php
3.9 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
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 18/4/24
* Time: 11:57
*/
namespace Rpc\Controller\OtherClass;
use Com\PackageValidate;
use Common\Service\BaseinfoService;
use Common\Service\ClassifyService;
class ListController extends AbstractController
{
/**
* List
* @author tangxingguo
* @desc 获取课程列表接口
* @param Int page:1 页码
* @param Int limit:20 每页记录数
* @param Int class_id 分类ID
* @param String keyword 标题关键字
* @return array
array(
'page' => 1, // 页码
'limit' => 20, // 每页记录数
'total' => 200, // 记录总数
'list' => array(
array(
'app_data_id' => '8852ce5784c43e6dddd942ae12d78fad', // 数据ID
'title' => '冰糖雪梨', // 标题
'class_name' => '企业文化', // 分类名称
'author' => '张三', // 作者
'status' => '已发布', // 状态
),
),
)
*/
public function Index()
{
$postData = $this->get_arguments();
// 验证规则
$rules = [
'page' => 'integer',
'limit' => 'integer',
'class_id' => 'integer',
'keyword' => 'max:64',
'app_data_ids' => 'array'
];
// 验证请求数据
$validate = new PackageValidate();
$validate->postData = $postData;
$validate->validateParams($rules);
// 分页
$postData['page'] = isset($postData['page']) ? $postData['page'] : BaseinfoService::DEFAULT_PAGE_NUM;
$postData['limit'] = isset($postData['limit']) ? $postData['limit'] : BaseinfoService::DEFAULT_PAGE_LIMIT;
list($start, $perpage) = page_limit($postData['page'], $postData['limit']);
// 条件
$conds = [
'qu_type' => BaseinfoService::OTHER_TYPE,
'release_status' => BaseinfoService::PUBLISH_STATUS,
];
if (strlen($postData['keyword']) > 0) {
$conds['title like ?'] = '%' . $postData['keyword'] . '%';
}
if (isset($postData['class_id']) && $postData['class_id'] != 0) {
$conds['qc_id'] = $postData['class_id'];
}
if (!empty($postData['app_data_ids'])) {
$conds['qu_id NOT IN (?)'] = $postData['app_data_ids'];
}
// 排序条件
$order_option = ['qu_id' => 'desc'];
// 调研列表
$list = [];
$baseInfoService = new BaseinfoService();
$baseInfoList = $baseInfoService->list_by_conds($conds, [$start, $perpage], $order_option);
if (!empty($baseInfoList)) {
// 分类数据
$classIds = array_column($baseInfoList, 'qc_id');
$classService = new ClassifyService();
$classList = $classService->list_by_conds(['qc_id' => $classIds]);
if (!empty($classList)) {
$classList = array_combine_by_key($classList, 'qc_id');
}
foreach ($baseInfoList as $article) {
$list[] = [
'app_data_id' => $article['qu_id'],
'title' => $article['title'],
'class_name' => isset($classList[$article['qc_id']]) ? $classList[$article['qc_id']]['qc_name'] : '',
'author' => '',
'status' => '已发布',
];
}
// 总数
$total = $baseInfoService->count_by_conds($conds);
}
return [
'page' => $postData['page'],
'limit' => $postData['limit'],
'total' => isset($total) ? $total : 0,
'list' => $list,
];
}
}