MapPathListController.class.php
3.39 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
<?php
/**
* 学习地图选择学习路径列表
* Created by PhpStorm.
* User: daixiong
* Date: 18/5/31
* Time: 10:49
*/
namespace Apicp\Controller\Path;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Service\PathService;
use Common\Service\MapPathService;
class MapPathListController extends \Apicp\Controller\AbstractController
{
/**
* List
* @author daxiong
* @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' => '苏三', // 创建人
)
),
)
*/
public function Index_post()
{
$rules = [
'page' => 'integer',
'limit' => 'integer',
'path_name' => 'max:64',
'start_time' => 'integer|gt:0',
'end_time' => 'integer|gt:0',
'map_id' => 'integer'
];
// 参数校验
$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'];
}
// 获取已被使用的路径ID集合
$mapPathServ = new MapPathService();
$usePathList = $mapPathServ->list_by_conds([], null, [], 'path_id', ['withOutStatus' => true]);
$usePathIds = array_column($usePathList, 'path_id');
if (!empty($usePathIds)) {
// 获取当前地图使用的路径ID集合
$mapUsePathIds = $mapPathServ->list_by_conds(['map_id' => $postData['map_id']]);
$mapUsePathIds = array_column($mapUsePathIds, 'path_id');
$conds['path_id NOT IN (?)'] = array_diff($usePathIds, $mapUsePathIds);
}
// 路径列表
$pathServ = new PathService();
$pathList = $pathServ->list_by_conds($conds, [$start, $perpage], ['update_time' => 'DESC']);
if (!empty($pathList)) {
$total = $pathServ->count_by_conds($conds);
}
$this->_result = [
'page' => $page,
'limit' => $limit,
'total' => isset($total) ? (int)$total : 0,
'list' => $pathList,
];
}
}