ListController.class.php
3.55 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 18/4/24
* Time: 11:23
*/
namespace Apicp\Controller\Path;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Service\PathService;
use Common\Service\MapPathService;
class ListController extends \Apicp\Controller\AbstractController
{
/**
* List
* @author liyifei
* @desc 路径列表接口
* @param Int page:1 当前页
* @param Int limit:20 当前页条数
* @param String path_name 路径名称
* @param String start_time 开始时间
* @param String end_time 结束时间
* @return mixed
array(
'page' => 1, // 当前页
'limit' => 20, // 当前页条数
'total' => 100, // 总条数
'list' => array( // 列表数据
array(
'path_id' => 1, // 讲师ID
'path_name' => '新员工岗位学习', // 路径名称
'update_time' => '1524540866000', // 更新时间
'ea_name' => '苏三', // 创建人
'is_used' => 1, // 是否被地图引用(1=否;2=是)
),
),
)
*/
public function Index_post()
{
$rules = [
'page' => 'integer',
'limit' => 'integer',
'path_name' => 'max:64',
'start_time' => 'integer|gt:0',
'end_time' => 'integer|gt:0',
];
// 参数校验
$postData = I('post.');
$validate = new PackageValidate();
$validate->postData = $postData;
$validate->validateParams($rules);
// 分页
$page = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE;
$limit = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT;
list($start, $perpage) = page_limit($page, $limit);
$conds = [];
if (isset($postData['path_name']) && strlen($postData['path_name']) > 0) {
$conds['path_name like ?'] = "%{$postData['path_name']}%";
}
if (isset($postData['start_time'])) {
$conds['update_time >= ?'] = $postData['start_time'];
}
if (isset($postData['end_time'])) {
$conds['update_time <= ?'] = $postData['end_time'];
}
// 路径列表
$pathServ = new PathService();
$pathList = $pathServ->list_by_conds($conds, [$start, $perpage], ['update_time' => 'DESC']);
if (!empty($pathList)) {
$total = $pathServ->count_by_conds($conds);
// 路径关联地图列表
$pathIds = array_column($pathList, 'path_id');
$mapPathServ = new MapPathService();
$mapPathList = $mapPathServ->list_by_conds(['path_id' => $pathIds]);
$usedIds = [];
if (!empty($mapPathList)) {
$usedIds = array_column($mapPathList, 'path_id');
}
// 被地图引用的路径,不可被选中批量删除
foreach ($pathList as $k => $path) {
if (in_array($path['path_id'], $usedIds)) {
$pathList[$k]['is_used'] = Constant::PATH_IS_USED_TRUE;
} else {
$pathList[$k]['is_used'] = Constant::PATH_IS_USED_FALSE;
}
}
}
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => isset($total) ? (int)$total : 0,
'list' => $pathList,
];
}
}