DeleteController.class.php
6.85 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
<?php
/**
* 【后台】删除直播活动接口
* Created by PhpStorm.
* User: yingcai
* Date: 2018/1/11
* Time: 下午3:21
*/
namespace Apicp\Controller\Room;
use Com\LiveSDK;
use Com\QcloudApi\QcloudApi;
use Common\Common\AttachOperation;
use Common\Common\Constant;
use Common\Model\StudioModel;
use Common\Service\MainService;
use Common\Service\ParticipateService;
use Common\Service\RangeService;
use Common\Service\RoleService;
use Common\Service\CronService;
use Common\Service\MsgLogService;
use Common\Service\StudioFileService;
use Common\Service\StudioService;
use Org\Net\Snoopy;
use VcySDK\Cron;
use VcySDK\FileConvert;
use VcySDK\Service;
class DeleteController extends AbstractController
{
/**
* Delete
* @author houyingcai
* @desc 删除直播活动接口
* @param Array lm_ids:true 直播活动ID
* @return bool
*/
public function Index_post()
{
$lm_ids = I('post.lm_ids');
if (empty($lm_ids) || !is_array($lm_ids)) {
E('_ERR_LIVE_ID_PARAM_FORMAT');
}
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());
}
// 删除首页推荐feed流
foreach ($lm_ids as $lm_id) {
$url = rpcUrl('/Public/Rpc/Recommender/ArticleDelete');
$params = [
'app' => APP_DIR,
'dataCategoryId' => '',
'dataId' => $lm_id,
];
\Com\Rpc::phprpc($url)->invoke('Index', $params);
}
// 删除计划任务
if (!empty($liveCrons)) {
$ucCronServ = new Cron(Service::instance());
foreach ($liveCrons as $cron) {
// 不需要UC删除的计划任务
if (in_array($cron['type'], Constant::CRON_TYPE_NOT_DELETE)) {
continue;
}
try {
// 根据cron_id获取UC的计划任务
$ucCron = $ucCronServ->get($cron['cron_id']);
if (!empty($ucCron)) {
// 删除计划任务
$ucCronServ->delete($cron['cron_id']);
}
} catch (\Exception $e) {
// 不处理
}
}
}
// 删除点播视频资源
$fileServ = new StudioFileService();
$fileList = $fileServ->list_by_conds(['lm_id' => $lm_ids], null, [], 'file_id');
$fileSdk = new FileConvert(Service::instance());
$fileIds = array_unique(array_column($fileList, 'file_id'));
foreach ($fileIds as $fileId) {
// 提交删除
$vodUtilInstance = (QcloudApi::load('Vod', [
'SecretId' => cfg('TENCENT_VOD_SECREAT_ID'),
'SecretKey' => cfg('TENCENT_VOD_SECREAT_KEY'),
'DefaultRegion' => 'sh',
]));
$vodDelUrl = $vodUtilInstance->generateUrl('DeleteVodFile', [
'fileId' => $fileId,
// 可填0;优先级0:中 1:高 2:低
'priority' => 0,
]);
$this->request($vodDelUrl);
// 删除 UC 那视频信息
$fileSdk->videoDelete($fileId);
}
// 删除UC附件
$attach_serv = new AttachOperation();
$attach_serv->delete_attach(APP_DIR, 'main', $lm_ids);
return true;
}
/**
* 请求接口数据
* @param string $url 请求URL
* @param string|array $reqParams 请求数据
* @param array $headers 请求头部
* @param string $method 请求方式, 如: GET/POST/DELETE/PUT
* @param mixed $files 文件路径
* @param bool $retry 是否重试
* @return bool
*/
private function request($url, $reqParams = [], $headers = [], $method = 'GET', $files = null, $retry = false)
{
$snoopy = new Snoopy();
// 使用自定义的头字段,格式为 array(字段名 => 值, ... ...)
$snoopy->rawheaders = $headers;
// 非 GET 协议, 需要设置
$method = rstrtoupper($method);
$methods = array('GET', 'POST', 'PUT', 'DELETE');
if (!in_array($method, $methods)) {
$method = 'GET';
}
// 设置协议
if (!empty($files)) {
// 如果需要传文件
$method = 'POST';
$snoopy->set_submit_multipart();
} else {
$snoopy->set_submit_normal('application/json');
}
// 判断协议
$snoopy->set_submit_method($method);
switch (rstrtoupper($method)) {
case 'POST' :
case 'PUT' :
case 'DELETE' :
$result = $snoopy->submit($url, $reqParams, $files);
break;
default :
$result = $snoopy->fetch($url);
break;
}
// 如果读取错误
if (!$result || 200 != $snoopy->status) {
\Think\Log::record('请求错误::' . var_export($snoopy, true));
}
return $snoopy->results;
}
}