AbstractController.class.php
8.67 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
/**
* Created by PhpStorm.
* User: zhoutao
* Date: 2018/1/8
* Time: 下午3:54
*/
namespace Apicp\Controller\VhLiveOperate;
use Common\Common\Constant;
use Common\Common\Vhall;
use Common\Model\CronModel;
use Common\Service\VhallService;
use Common\Service\VhMsgLogService;
use VcySDK\Cron;
use VcySDK\Exception;
use VcySDK\Service;
class AbstractController extends \Apicp\Controller\AbstractController
{
/** @var VhMsgLogService */
protected $vhMsgLogServ;
/** @var VhallService */
protected $vhall_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->vhall_service = new VhallService();
// 微吼直播日志
$this->vhMsgLogServ = new VhMsgLogService();
return true;
}
public function getLiveSetting($params = [], $field = [])
{
$setting = [];
//校验提醒时间 时候大于当前时间
if ($params['notice_will_type'] == Constant::NOTICE_WILL_TYPE_ON) {
$times = $params['liveStartTime'] - to_milli_time($params['notice_will_start']);
if ($times < MILLI_TIME) {
E('_ERR_SEND_WILL_TIME_MAX_NOW_TIME');
}
}
// 直播开始前 (分钟)推送消息提醒
if (isset($params['notice_will_type']) && $params['notice_will_type'] == Constant::NOTICE_START_TRUE) {
if (isset($params['notice_will_start']) && $params['notice_will_start'] <= 0) {
E('_ERR_SEND_WILL_TIME_MUST_ABOVE');
}
}
if (empty($params)) {
E('_ERR_PARAMS_CAN_NOT_EMPTY');
}
foreach ($field as $item) {
if (array_key_exists($item, $params)) {
$setting[$item] = $params[$item];
}
}
if (empty($setting)) {
E('_ERR_SETTING_FILED_IS_EMPTY');
}
return $setting;
}
/**
* 更新发送消息
* @param array $params
* @param array $uc_info UC详情
* @param array $vh_set_info 数据表详情
*/
public function update_send_msg($params = [], $uc_info = [], $vh_set_info = [])
{
// 初始化微吼直播类
$vh_class = Vhall::instance();
// 获取微吼直播详情
$info = $vh_class->details($params['id']);
$params['liveVhallId'] = $info['liveVhallId'];
//如果内部讲师 推送消息
if ($params['teacher_type'] == Constant::INSIDE_TEACHER_TYPE && $uc_info['liveType'] == Constant::LIVE_WEB_STATUS_DRAFT_TYPE) {
//复制数据 导师发送消息过程需 去除权限数据
$data = $params;
$this->vhMsgLogServ->send_teacher_msg($data, Constant::MSG_LECTURER_APPOINTMENT);
}
// 如果选择了推送消息
if (Constant::NOTICE_POSTING_TRUE == $params['notice_posting'] && $uc_info['liveType'] == Constant::LIVE_WEB_STATUS_DRAFT_TYPE) {
// 如果是全公司
if (!empty($params['liveScopeAll'])) {
// 写入记录
$this->vhMsgLogServ->sendMsgRangeDiffUids($params['id'], [], true);
} else {
// 获取有权限的用户UIDS集合
$uids = $this->vhMsgLogServ->get_auth_uids($params);
// 组装发消息数据
$params['liveScopeUsers'] = $this->vhMsgLogServ->sendMsgRangeDiffUids($params['id'], $uids);
}
// 直播开始发送消息
$this->vhMsgLogServ->send_vh_Msg($params, Constant::MSG_LIVE_PUBLISH);
}
$Cron = new Cron(Service::instance());
// 更新条件
$conds = [
'vh_id' => $params['id']
];
// 直播开始前分钟数开关选中
if ($params['notice_will_type'] == Constant::NOTICE_START_TRUE) {
if ($params['notice_will_start'] != $vh_set_info['notice_will_start']
||
$uc_info['liveType'] == Constant::LIVE_WEB_STATUS_DRAFT_TYPE) {
// 如果存在计划任务就删除
if (!empty($vh_set_info['notice_will_start_cron_id'])) {
try {
$Cron->delete($vh_set_info['notice_will_start_cron_id']);
} catch (Exception $exception) {
}
}
// 更新为没有定时任务
$this->vhall_service->update_by_conds($conds, ['notice_will_start_cron_id' => '']);
$this->vhMsgLogServ->createCron(
$params['id'],
'live_notice_will_start',
Constant::TYPE_LIVE_WILL_START,
$params['liveStartTime'] - $params['notice_will_start'] * 60 * 1000
);
}
} else {
// 删除任务
if (!empty($vh_set_info['notice_will_start_cron_id'])) {
try {
$Cron->delete($vh_set_info['notice_will_start_cron_id']);
} catch (Exception $exception) {
}
$this->vhall_service->update_by_conds($conds, ['notice_will_start_cron_id' => '']);
}
}
// 直播开始时推送消息
if (Constant::NOTICE_START_TRUE == $params['notice_start']) {
if ($params['liveStartTime'] != $uc_info['liveStartTime']
||
$uc_info['liveType'] == Constant::LIVE_WEB_STATUS_DRAFT_TYPE
) {
if (!empty($vh_set_info['notice_notice_start_cron_id'])) {
$Cron->delete($vh_set_info['notice_notice_start_cron_id']);
$this->vhall_service->update_by_conds($conds, ['notice_notice_start_cron_id' => '']);
}
// 直播开始时
$this->vhMsgLogServ->createCron(
$params['id'],
'live_notice_start',
Constant::TYPE_LIVE_START,
$params['liveStartTime']
);
}
}
// 首页推荐
if (Constant::RECOMEND_TRUE == $params['recomend']) {
//移除之前推荐
$this->vhall_service->openOrCloseRecommender($params, false);
// 新建移动端首页推荐
$this->vhall_service->openOrCloseRecommender($params);
}
// 首页取消推荐
if (Constant::RECOMEND_FALSE == $params['recomend'] && $params['recomend'] != $vh_set_info['recomend']) {
// 移动端取消推荐
$this->vhall_service->openOrCloseRecommender($params, false);
}
}
/**
* 处理 "更多设置"
* @param $data
* @return bool
*/
protected function dealWithMoreSetting($data = [])
{
// 发布时推送消息提醒
if (isset($data['notice_posting']) && $data['notice_posting'] == Constant::NOTICE_POSTING_TRUE) {
// 如果是全公司
if (!empty($data['liveScopeAll'])) {
// 写入记录
$this->vhMsgLogServ->sendMsgRangeDiffUids($data['id'], [], true);
} else {
// 获取有权限的用户UIDS集合
$uids = $this->vhMsgLogServ->get_auth_uids($data);
// 组装发消息数据
$data['liveScopeUsers'] = $this->vhMsgLogServ->sendMsgRangeDiffUids($data['id'], $uids);
}
// 直播地址
$this->vhMsgLogServ->send_vh_Msg($data, Constant::MSG_LIVE_PUBLISH);
}
// 直播开始前 (分钟)推送消息提醒
if (isset($data['notice_will_type']) && $data['notice_will_type'] == Constant::NOTICE_START_TRUE) {
if (isset($data['notice_will_start']) && $data['notice_will_start'] > 0) {
// 直播开始前 推送消息的时间点
$this->vhMsgLogServ->createCron(
$data['id'],
'live_notice_will_start',
CronModel::TYPE_LIVE_WILL_START,
$data['liveStartTime'] - $data['notice_will_start'] * 60 * 1000
);
}
}
// 直播开始时推送消息
if (isset($data['notice_start']) && $data['notice_start'] == Constant::NOTICE_START_TRUE) {
$this->vhMsgLogServ->createCron(
$data['id'],
'live_notice_start',
CronModel::TYPE_LIVE_START,
$data['liveStartTime']
);
}
if (isset($data['recomend']) && $data['recomend'] == Constant::RECOMEND_TRUE) {
// 移动端首页推荐
$this->vhall_service->openOrCloseRecommender($data);
}
return true;
}
}