DeleteController.class.php
3.45 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
<?php
/*
* 直播-删除
* 2018.07.19
*
*/
namespace Apicp\Controller\VhLiveOperate;
use Com\LiveSDK;
use Common\Common\Constant;
use Common\Common\Vhall;
use Common\Service\CronService;
use Common\Service\MainService;
use Common\Service\MsgLogService;
use Common\Service\ParticipateService;
use Common\Service\RangeService;
use Common\Service\RoleService;
use Common\Service\StudioService;
use Common\Service\VhallService;
class DeleteController extends AbstractController
{
public function Index_post()
{
$ids = I('post.liveId');
if (empty($ids)) {
E('_EMPTY_LIVE_ID');
}
$lm_ids = [];
$liveIds = [];
foreach ($ids as $id) {
if (strlen($id) < 32) {
$lm_ids[] = $id;
} else {
$liveIds[] = $id;
}
}
// 删除新数据
if (!empty($liveIds)) {
Vhall::instance()->delete($liveIds);
$this->vhall_service->delete_by_conds(['vh_id' => $liveIds]);
}
// 批量取消首页推荐
foreach ($liveIds as $v) {
$params['id'] = $v;
// 移动端取消推荐
$this->vhall_service->openOrCloseRecommender($params, false);
}
if (empty($lm_ids)) {
return true;
}
try {
$mainServ = new MainService();
$mainServ->start_trans();
// 删除直播主表数据
$mainServ->delete($lm_ids);
$del_conds = ['lm_id' => $lm_ids];
// 删除直播范围表数据
$rangeServ = new RangeService();
$rangeServ->delete_by_conds($del_conds);
// 删除直播角色表数据
$roleServ = new RoleService();
$roleServ->delete_by_conds($del_conds);
// 删除直播参与表数据
$participateServ = new ParticipateService();
$participateServ->delete_by_conds($del_conds);
// 删除直播消息通知记录表数据
$msgLogServ = new MsgLogService();
$msgLogServ->delete_by_conds($del_conds);
$liveCronServ = new CronService();
// 获取计划任务
$liveCrons = $liveCronServ->list_by_conds($del_conds, [], [], 'cron_id, type');
// 存在计划任务
if (!empty($liveCrons)) {
// 删除业务计划任务表数据
$liveCronServ->delete_by_conds($del_conds);
}
// 禁止推流
$studioServ = new StudioService();
$studioList = $studioServ->list_by_conds(['lm_id' => $lm_ids]);
$liveSdk = new LiveSDK();
foreach ($studioList as $item) {
$liveSdk->channelSetStatus($item['stream_id'], $liveSdk::CHANNEL_STATUS_DISABLED);
}
// 删除聊天室
$studioServ->update_by_conds(['lm_id' => $lm_ids], ['stream_status' => Constant::STREAM_TYPE_STATUS_DISABLED]);
$mainServ->commit();
} catch (\Exception $e) {
\Think\Log::record('删除错误:' . $e->getMessage());
$mainServ->rollback();
E($e->getCode() . ':' . $e->getMessage());
}
// 批量取消首页推荐
foreach ($lm_ids as $v) {
$params['id'] = $v;
// 移动端取消推荐
$this->vhall_service->openOrCloseRecommender($params, false);
}
return true;
}
}