WatchDetailsController.class.php
5.21 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
137
138
<?php
/**
* User: zoulongbo
* Date: 2018/7/26
* Time: 11:18
*/
namespace Apicp\Controller\VhLiveTotal;
use Common\Common\Constant;
use Common\Common\User;
use Common\Common\UserCache;
use Common\Common\Vhall;
class WatchDetailsController extends AbstractController
{
public function Index_post()
{
$params = I('post.');
if (!$params) {
E('_ERR_PARAMS_CAN_NOT_EMPTY');
}
//获取 直播数据详情
$watchTotals = Vhall::instance()->watchDetails($params);
//print_r($watchTotals);die();
$this->_result = $this->formatWatchTotals($watchTotals, $params);
return true;
}
public function formatWatchTotals($watchTotals, $params)
{
//处理 otherTotal1/2/3
switch ($params['type']) {
case Constant::TYPE_LIVE_WATCH:
$watchTotals['watchTotal'] = $watchTotals['total'];
$watchTotals['playBackTotal'] = $watchTotals['otherTotal1'];
$watchTotals['unWatchTotal'] = $watchTotals['otherTotal2'];
$watchTotals['signInTotal'] = $watchTotals['otherTotal3'];
break;
case Constant::TYPE_LIVE_PLAY_BACK:
$watchTotals['watchTotal'] = $watchTotals['otherTotal1'];
$watchTotals['playBackTotal'] = $watchTotals['total'];
$watchTotals['unWatchTotal'] = $watchTotals['otherTotal2'];
$watchTotals['signInTotal'] = $watchTotals['otherTotal3'];
break;
case Constant::TYPE_LIVE_UNWATCH:
$watchTotals['watchTotal'] = $watchTotals['otherTotal1'];
$watchTotals['playBackTotal'] = $watchTotals['otherTotal2'];
$watchTotals['unWatchTotal'] = $watchTotals['total'];
$watchTotals['signInTotal'] = $watchTotals['otherTotal3'];
break;
case Constant::TYPE_LIVE_SIGN_IN:
$watchTotals['watchTotal'] = $watchTotals['otherTotal1'];
$watchTotals['playBackTotal'] = $watchTotals['otherTotal2'];
$watchTotals['unWatchTotal'] = $watchTotals['otherTotal3'];
$watchTotals['signInTotal'] = $watchTotals['total'];
}
// 格式化数据
$watchTotals['watchTotal'] = intval($watchTotals['watchTotal']);
$watchTotals['playBackTotal'] = intval($watchTotals['playBackTotal']);
$watchTotals['unWatchTotal'] = intval($watchTotals['unWatchTotal']);
$watchTotals['signInTotal'] = intval($watchTotals['signInTotal']);
//分页字段转换
$watchTotals['page'] = intval($params['page']);
$watchTotals['limit'] = intval($params['limit']);
$userList = $this->getUserList($watchTotals, $params);
return $this->dataPackaging($watchTotals, $userList, $params);
}
/**
* 组装前端需要 数据格式
* @param array $watchTotals
* @param array $userList
* @param array $params
* @return array
*/
public function dataPackaging($watchTotals = [], $userList = [], $params = [])
{
if ($params['type'] == Constant::TYPE_LIVE_UNWATCH) {
$uids = $watchTotals['list'];
$watchTotals['list'] = [];
foreach ($uids as $value) {
$watchTotals['list'][] = [
'title' => $params['title'],
'memMobile' => $userList[$value]['memMobile'],
'memUsername' => $userList[$value]['memUsername'],
'jobName' => $userList[$value]['memJob'],
'dpName' => implode(',', array_column($userList[$value]['dpName'], 'dpName')),
'roleName' => $userList[$value]['memRole'],
];
}
} else {
foreach ($watchTotals['list'] as $key => $value) {
$watchTotals['list'][$key]['title'] = $params['title'];
$watchTotals['list'][$key]['memMobile'] = $userList[$value['memUid']]['memMobile'];
$watchTotals['list'][$key]['memUsername'] = $userList[$value['memUid']]['memUsername'];
$watchTotals['list'][$key]['jobName'] = $userList[$value['memUid']]['memJob'];
$watchTotals['list'][$key]['dpName'] = implode(',', array_column($userList[$value['memUid']]['dpName'], 'dpName'));
$watchTotals['list'][$key]['roleName'] = $userList[$value['memUid']]['memRole'];
}
}
unset($watchTotals['otherTotal1'], $watchTotals['otherTotal2'], $watchTotals['otherTotal3'], $watchTotals['pageNum'], $watchTotals['pageSize']);
return $watchTotals;
}
/**
* 获取uid 对应memUsername、jobName、dpName、roleName、memMobile
* type=3 格式改变
* @param array $watchTotals
* @param array $params
* @return array
*/
public function getUserList($watchTotals = [], $params = [])
{
if ($params['type'] == Constant::TYPE_LIVE_UNWATCH) {
$uids = $watchTotals['list'];
} else {
$uids = array_column($watchTotals['list'], 'memUid');
}
$users = new UserCache();
$users::update_all_user_by_cache();
$userList = $users::get_all_user_by_cache_list($uids);
return $userList;
}
}