UsageController.class.php
4.13 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
<?php
/**
* Created by PhpStorm.
* User: zhoutao
* Date: 2018/2/5
* Time: 下午5:02
*/
namespace Apicp\Controller\Room;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Service\MainService;
class UsageController extends AbstractController
{
/**
* Usage
* @author zhoutao
* @desc 并发人数使用情况
* @param Int page:false:1 页码
* @param Int limit:false:20 每页记录数
* @param String name:false 名称关键词
* @param Int start_time_begin:false 起始开始时间
* @param Int start_time_end:false 终止开始时间
* @return array|bool 使用情况
array(
'page' => 1, // 页码
'limit' => 5, // 每页记录数
'total' => 20, // 列表记录总数
'list' => array(
array(
'lm_id' => 1, // 直播ID
'name' => '产品培训讲解', // 直播名称
'watched_total' => 150, // 已观看直播人数
'range_total' => 200, // 可观看直播总人数
'start_time' => 1515207667910, // 开始时间
'end_time' => 1515207667910, // 结束时间
'online_peak' => 21, // 消耗并发
'end_concurrent_member_number' => 122 // 结束时企业还剩余并发人数 (-1 为还未统计)
),
),
)
*/
public function Index_post()
{
// 验证规则
$rules = [
'page' => 'integer',
'limit' => 'integer',
'name' => 'max:30',
'start_time_begin' => 'integer',
'start_time_end' => 'integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 分页默认值
$page = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE;
$limit = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT;
list($start, $limit) = page_limit($page, $limit);
// 组合搜索条件
$conds = $this->assemble_where($postData);
// 获取记录总数
$mainService = new MainService();
$total = $mainService->count_by_conds($conds, '*', false, true);
$list = [];
// 记录总数不为空:有数据
if ($total) {
// 分页参数
$pageOption = [$start, $limit];
// 排序
$orderOption = [
'updated'=> 'DESC',
'created' => 'DESC',
];
// 查询字段
$fields = [
'lm_id',
'name',
'start_time',
'end_time',
'watched_total',
'range_total',
'end_concurrent_member_number',
'online_peak',
'live_status'
];
// 获取列表数据
$list = $mainService->list_by_conds(
$conds,
$pageOption,
$orderOption,
implode(',', $fields),
['withOutStatus' => true]);
}
// 返回结果
$this->_result = [
'page' => intval($page),
'limit' => intval($limit),
'total' => intval($total),
'list' => $list
];
return true;
}
/**
* @desc 组合搜索条件
* @param array $postData 搜索条件
* @return array
*/
private function assemble_where($postData)
{
$conds = [];
if (isset($postData['name'])) {
$postData['name'] = str_replace("%", '\%', $postData['name']);
$conds['name like ?'] = '%' . $postData['name'] . '%';
}
if (isset($postData['start_time_begin']) && isset($postData['start_time_end'])) {
$conds['start_time >= ?'] = $postData['start_time_begin'];
$conds['start_time <= ?'] = $postData['start_time_end'];
}
return $conds;
}
}