RemindController.class.php
2.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
107
108
109
110
<?php
/**
* 直播观看批量提醒接口
* Created by PhpStorm.
* User: yingcai
* Date: 2018/1/15
* Time: 下午3:15
*/
namespace Apicp\Controller\Room;
use Common\Common\Constant;
use Common\Service\MainService;
use Common\Service\RangeService;
class RemindController extends AbstractController
{
/** @var MainService */
protected $mainServ;
/** @var RangeService */
protected $rangeServ;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化直播表
$this->mainServ = new MainService();
// 实例化观看直播权限范围表
$this->rangeServ = new RangeService();
return true;
}
/**
* Remind
* @author houyingcai
* @desc 直播间登陆页面接口
* @param Int lm_id:true:1 直播活动ID
* @return bool
*/
public function Index_post()
{
$lmId = I('post.lm_id', 0, 'rintval');
// 直播ID不能为空
if (!$lmId) {
E('_EMPTY_LIVE_ID');
}
// 获取直播信息
$mainDetail = $this->mainServ->get($lmId);
// 直播信息不存在
if (empty($mainDetail)) {
E('_ERR_LIVE_IS_NOT_EXIST');
}
// 格式化直播状态
$live_status = $this->mainServ->live_status(
$mainDetail['live_status'],
$mainDetail['start_time']
);
// 不是未开始和进行中的直播,不能提醒
if (!in_array($live_status, [
Constant::LIVE_WEB_STATUS_NOT_START,
Constant::LIVE_WEB_STATUS_ING
])) {
E('_ERR_LIVE_REMIND_STATUS');
}
// 批量发布提醒消息
$this->remind_live($mainDetail);
return true;
}
/**
* 批量发布提醒消息
* @param array $mainDetail 直播详情数组
* @return bool
*/
protected function remind_live($mainDetail)
{
// 获取未参与列表
list(, $uids_unwatch) = $this->rangeServ->getWatchDataUids($mainDetail['lm_id']);
$params = [
'uids' => $uids_unwatch,
'lm_id' => $mainDetail['lm_id'],
'name' => $mainDetail['name'],
'start_time' => $mainDetail['start_time'],
'estimated_duration' => $mainDetail['estimated_duration'],
'desc' => $mainDetail['desc'],
];
// 发送消息
$this->mainServ->sendMsg($params, MainService::MSG_REMAIND_NO_JOIN_USERS);
return true;
}
}