ClassListController.class.php
1.7 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 18/4/24
* Time: 11:57
*/
namespace Rpc\Controller\OtherClass;
use Common\Common\Constant;
use Common\Service\CategoryService;
class ClassListController extends AbstractController
{
/**
* ClassList
* @author pw
* @desc 考试分类列表接口
* @return array(
* array(
* 'class_id' => '分类 ID', // 分类 ID
* 'class_name' => '分类名称', // 分类名称
* 'parent_id' => '上级分类 ID,为 0 则表示顶级' // 上级分类 ID,为 0 则表示顶级
* )
* )
*/
public function Index()
{
// 排序规则
$order_option = ['created' => 'desc'];
// 分类列表数据
$classServ = new CategoryService();
$classList = $classServ->list_by_conds([], [], $order_option);
$classList = array_combine_by_key($classList, 'ec_id');
// 格式化数据
$res = [];
if (!empty($classList)) {
foreach ($classList as $k => $v) {
// 分类状态为未开启
if ($v['ec_status'] == Constant::CATEGORY_IS_OPEN_FALSE) {
continue;
}
// 父级分类状态为未开启
if (isset($classList[$v['parent_id']]) && $classList[$v['parent_id']]['ec_status'] == Constant::CATEGORY_IS_OPEN_FALSE) {
continue;
}
$res[] = [
'class_id' => $v['ec_id'],
'class_name' => $v['ec_name'],
'parent_id' => $v['parent_id'],
];
}
}
$list['list'] = $res;
return $list;
}
}