Commit c5e32fc4 by 杨昕

将获取截屏数据修改为异步

parent 857ea5b6
Pipeline #18750 passed with stages
in 1 minute 16 seconds
...@@ -326,7 +326,6 @@ class MediaController extends Controller ...@@ -326,7 +326,6 @@ class MediaController extends Controller
*/ */
public function getMediaListByMediaIds(Request $request) public function getMediaListByMediaIds(Request $request)
{ {
$data = handler_drive(function () use ($request) { $data = handler_drive(function () use ($request) {
SrsHookValidate::srsHookCallback($request, [ SrsHookValidate::srsHookCallback($request, [
'media_ids' => 'required', 'media_ids' => 'required',
...@@ -336,30 +335,22 @@ class MediaController extends Controller ...@@ -336,30 +335,22 @@ class MediaController extends Controller
return success($data); return success($data);
} }
/** /**
* @param Request $request * @param Request $request
* @param $id * @return mixed
* @return \Illuminate\Http\JsonResponse * @throws FormException
* @throws \App\Exceptions\ControllerException * @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\DatabaseException
*/ */
public function getScreeShotInfo(Request $request) public function screenShotCallback(Request $request){
{
$data = handler_drive(function () use ($request) { $data = handler_drive(function () use ($request) {
SrsHookValidate::srsHookCallback($request, [ SrsHookValidate::srsHookCallback($request, [
'media_id' => 'required', 'media_id' => 'required',
'secret_key' => '', 'secret_key' => '',
'media_url' => '', 'media_url' => 'required',
]); ]);
return MediaModel::UpdateScreenShotInfo($request);
return array(
"media_id" => $request->media_id,
"secret_key" => $request->secret_key,
"media_url" => $request->media_url,
);
//return MediaModel::getScreeShotInfo($request);
}); });
return success($data); return success($data);
} }
......
...@@ -27,7 +27,6 @@ class MediaModel extends Eloquent ...@@ -27,7 +27,6 @@ class MediaModel extends Eloquent
public static $max_page_size = 500; public static $max_page_size = 500;
public function media_category() public function media_category()
{ {
return $this->belongsTo('MediaCategoryModel'); return $this->belongsTo('MediaCategoryModel');
...@@ -39,25 +38,26 @@ class MediaModel extends Eloquent ...@@ -39,25 +38,26 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function mediaList($request){ public static function mediaList($request)
{
try{ try {
$medias = MediaModel::query()->raw(function ($collection) use($request){ $medias = MediaModel::query()->raw(function ($collection) use ($request) {
$limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER) ; $limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER);
if ($limit >self::$max_page_size){ if ($limit > self::$max_page_size) {
$limit = self::$max_page_size; $limit = self::$max_page_size;
} }
$page = $request->page??1; $page = $request->page ?? 1;
$aggregate = []; $aggregate = [];
/** /**
* 默认降序 * 默认降序
*/ */
$sort = -1; $sort = -1;
if ($request->sort == 'asc'){ if ($request->sort == 'asc') {
$sort = 1; $sort = 1;
} }
...@@ -66,36 +66,36 @@ class MediaModel extends Eloquent ...@@ -66,36 +66,36 @@ class MediaModel extends Eloquent
// "media_url" => ["\$ne" => 'null'] // "media_url" => ["\$ne" => 'null']
]; ];
if (isset($request->media_id) && !empty($request->media_id)){ if (isset($request->media_id) && !empty($request->media_id)) {
$match['_id'] = $request->media_id; $match['_id'] = $request->media_id;
} }
if (isset($request->category_id) && !empty($request->category_id)){ if (isset($request->category_id) && !empty($request->category_id)) {
$match['media_type_id'] = $request->category_id; $match['media_type_id'] = $request->category_id;
} }
// $aggregate[]['$match']['_id'] = 'mda-864371b9a82d1e21'; // $aggregate[]['$match']['_id'] = 'mda-864371b9a82d1e21';
if (isset($request->media_name) && !empty($request->media_name)){ if (isset($request->media_name) && !empty($request->media_name)) {
$match['media_name'] = ['$regex' => addslashes($request->media_name) ]; $match['media_name'] = ['$regex' => addslashes($request->media_name)];
} }
if (isset($request->username) && !empty($request->username)){ if (isset($request->username) && !empty($request->username)) {
$match['username'] = ['$regex' => addslashes($request->username) ]; $match['username'] = ['$regex' => addslashes($request->username)];
} }
if (isset($request->description) && !empty($request->description)){ if (isset($request->description) && !empty($request->description)) {
$match['description'] = ['$regex' => $request->description ]; $match['description'] = ['$regex' => $request->description];
} }
if (isset($request->start_time)&& !empty($request->start_time)){ if (isset($request->start_time) && !empty($request->start_time)) {
$start_time = new UTCDateTime(strtotime($request->start_time) * 1000); $start_time = new UTCDateTime(strtotime($request->start_time) * 1000);
$match['start_time'] = ['$gt' => $start_time ]; $match['start_time'] = ['$gt' => $start_time];
} }
if (isset($request->end_time)&& !empty($request->end_time)){ if (isset($request->end_time) && !empty($request->end_time)) {
$end_time = new UTCDateTime(strtotime($request->end_time) * 1000);; $end_time = new UTCDateTime(strtotime($request->end_time) * 1000);;
$match['end_time'] = ['$lt' => $end_time ]; $match['end_time'] = ['$lt' => $end_time];
} }
$aggregate[]['$match'] = $match; $aggregate[]['$match'] = $match;
...@@ -104,7 +104,7 @@ class MediaModel extends Eloquent ...@@ -104,7 +104,7 @@ class MediaModel extends Eloquent
$count = MediaModel::where($match)->count(); $count = MediaModel::where($match)->count();
$skip = ((empty($request->page) ? 1 : $request->page)-1) * $limit; $skip = ((empty($request->page) ? 1 : $request->page) - 1) * $limit;
$aggregate[]['$skip'] = $skip; $aggregate[]['$skip'] = $skip;
$aggregate[]['$limit'] = $limit; $aggregate[]['$limit'] = $limit;
...@@ -116,10 +116,10 @@ class MediaModel extends Eloquent ...@@ -116,10 +116,10 @@ class MediaModel extends Eloquent
/** /**
* 将mongoDate 转化为普通时间 * 将mongoDate 转化为普通时间
*/ */
foreach ($tmp_arr as $media){ foreach ($tmp_arr as $media) {
$tz = new \DateTimeZone("Asia/Shanghai"); $tz = new \DateTimeZone("Asia/Shanghai");
if (is_object($media['start_time'])){ if (is_object($media['start_time'])) {
$start_time = $media['start_time']->toDateTime(); $start_time = $media['start_time']->toDateTime();
$start_time->setTimezone($tz); $start_time->setTimezone($tz);
...@@ -128,19 +128,19 @@ class MediaModel extends Eloquent ...@@ -128,19 +128,19 @@ class MediaModel extends Eloquent
$media['start_time'] = $start_time; $media['start_time'] = $start_time;
} }
if (is_object($media['end_time'])){ if (is_object($media['end_time'])) {
$end_time = $media['end_time']->toDateTime(); $end_time = $media['end_time']->toDateTime();
$end_time->setTimezone($tz); $end_time->setTimezone($tz);
$media['end_time'] = $end_time->format('Y-m-d H:i:s'); $media['end_time'] = $end_time->format('Y-m-d H:i:s');
} }
if (is_object($media['create_time'])){ if (is_object($media['create_time'])) {
$create_time = $media['create_time']->toDateTime(); $create_time = $media['create_time']->toDateTime();
$create_time->setTimezone($tz); $create_time->setTimezone($tz);
$media['create_time'] = $create_time->format('Y-m-d H:i:s'); $media['create_time'] = $create_time->format('Y-m-d H:i:s');
} }
} }
return new LengthAwarePaginator($tmp_arr, $count, $limit, $page,[ return new LengthAwarePaginator($tmp_arr, $count, $limit, $page, [
'path' => Paginator::resolveCurrentPath(), 'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page', 'pageName' => 'page',
]); ]);
...@@ -148,7 +148,7 @@ class MediaModel extends Eloquent ...@@ -148,7 +148,7 @@ class MediaModel extends Eloquent
}); });
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
...@@ -162,9 +162,10 @@ class MediaModel extends Eloquent ...@@ -162,9 +162,10 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function hookRestoreMedia($request,$category = "media"){ public static function hookRestoreMedia($request, $category = "media")
{
try{ try {
/** /**
* 判断媒资ID是否存在 * 判断媒资ID是否存在
...@@ -172,32 +173,32 @@ class MediaModel extends Eloquent ...@@ -172,32 +173,32 @@ class MediaModel extends Eloquent
$media_id = $request->media_id; $media_id = $request->media_id;
$media_type = $request->media_type; $media_type = $request->media_type;
$mediaCatg = MediaCategoryModel::where('_id',$media_type)->first(); $mediaCatg = MediaCategoryModel::where('_id', $media_type)->first();
if (empty($mediaCatg)){ if (empty($mediaCatg)) {
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
//replace 不为空的时候代表做视频替换操作,1.需要清空CDN缓存,2.将原来的视频保存至回收站,3.更新视频信息 //replace 不为空的时候代表做视频替换操作,1.需要清空CDN缓存,2.将原来的视频保存至回收站,3.更新视频信息
if ($request->replace){ if ($request->replace) {
$recycleId = RecycleModel::addRecycle($media_id); $recycleId = RecycleModel::addRecycle($media_id);
$call_back = $mediaCatg['call_back']; $call_back = $mediaCatg['call_back'];
#清空CND缓存 #清空CND缓存
$url = getRbac($request,$call_back,$mediaCatg['media_category_id'] ,$type='clear_cache'); $url = getRbac($request, $call_back, $mediaCatg['media_category_id'], $type = 'clear_cache');
http_request_code($url,null,'POST',['mediaId'=>$media_id]); http_request_code($url, null, 'POST', ['mediaId' => $media_id]);
#更新视频信息 #更新视频信息
self::updatehookMedia($request,$media_id); self::updatehookMedia($request, $media_id);
if (!$recycleId){ if (!$recycleId) {
throw new \Exception('回收站保存失败'); throw new \Exception('回收站保存失败');
} }
return $media_id; return $media_id;
}else{ } else {
$media = MediaModel::where("_id",$media_id)->first(); $media = MediaModel::where("_id", $media_id)->first();
if (!empty($media)){ if (!empty($media)) {
throw new \Exception("媒资编号已被使用"); throw new \Exception("媒资编号已被使用");
} }
} }
...@@ -206,11 +207,11 @@ class MediaModel extends Eloquent ...@@ -206,11 +207,11 @@ class MediaModel extends Eloquent
/** /**
* 媒资名称是由课程编号与课程名称组成 * 媒资名称是由课程编号与课程名称组成
*/ */
$media_info = explode("&",$request->media_name); $media_info = explode("&", $request->media_name);
$media_url = $request->media_url; $media_url = $request->media_url;
$media_url = str_replace("http:","https:",$media_url); $media_url = str_replace("http:", "https:", $media_url);
/** /**
...@@ -224,7 +225,7 @@ class MediaModel extends Eloquent ...@@ -224,7 +225,7 @@ class MediaModel extends Eloquent
/** /**
* 处理文件名称,确认是否包含"&"符合 * 处理文件名称,确认是否包含"&"符合
*/ */
if (count($media_info)>=2){ if (count($media_info) >= 2) {
$data = [ $data = [
'_id' => $media_id, '_id' => $media_id,
...@@ -243,11 +244,11 @@ class MediaModel extends Eloquent ...@@ -243,11 +244,11 @@ class MediaModel extends Eloquent
'mis_uid' => $request->mis_uid,//员工工号 'mis_uid' => $request->mis_uid,//员工工号
'start_time' => $start_time, 'start_time' => $start_time,
'end_time' => $end_time, 'end_time' => $end_time,
'duration' => $request->duration??"0", 'duration' => $request->duration ?? "0",
'status' => $request->status??"0", 'status' => $request->status ?? "0",
]; ];
}else{ } else {
$data = [ $data = [
'_id' => $media_id, '_id' => $media_id,
...@@ -266,17 +267,17 @@ class MediaModel extends Eloquent ...@@ -266,17 +267,17 @@ class MediaModel extends Eloquent
'mis_uid' => $request->mis_uid,//员工工号 'mis_uid' => $request->mis_uid,//员工工号
'start_time' => $start_time, 'start_time' => $start_time,
'end_time' => $end_time, 'end_time' => $end_time,
'duration' => $request->duration??"0", 'duration' => $request->duration ?? "0",
'status' => $request->status??"0", 'status' => $request->status ?? "0",
]; ];
} }
$id = MediaModel::insertGetId($data); $id = MediaModel::insertGetId($data);
//处理封面图片以及分辨率 //处理封面图片以及分辨率
//self::getScreeShotInfo($media_id); self::getScreeShotInfo($media_id);
LogModel::addlog(["添加媒资信息"=> $data,['媒资ID为:=> '.$id]]); LogModel::addlog(["添加媒资信息" => $data, ['媒资ID为:=> ' . $id]]);
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $id; return $id;
...@@ -289,12 +290,13 @@ class MediaModel extends Eloquent ...@@ -289,12 +290,13 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function updatehookMedia($request,$id){ public static function updatehookMedia($request, $id)
{
try{ try {
$media = MediaModel::find($id); $media = MediaModel::find($id);
if (empty($media)){ if (empty($media)) {
throw new \Exception("媒资不存在"); throw new \Exception("媒资不存在");
} }
...@@ -302,10 +304,10 @@ class MediaModel extends Eloquent ...@@ -302,10 +304,10 @@ class MediaModel extends Eloquent
/** /**
* 媒资名称是由课程编号与课程名称组成 * 媒资名称是由课程编号与课程名称组成
*/ */
$media_info = explode("&",$request->media_name); $media_info = explode("&", $request->media_name);
$mediaCatg = MediaCategoryModel::where('_id',$request->media_type)->first(); $mediaCatg = MediaCategoryModel::where('_id', $request->media_type)->first();
if (empty($mediaCatg)){ if (empty($mediaCatg)) {
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
...@@ -316,7 +318,7 @@ class MediaModel extends Eloquent ...@@ -316,7 +318,7 @@ class MediaModel extends Eloquent
/** /**
* 处理文件名称,确认是否包含"&"符合 * 处理文件名称,确认是否包含"&"符合
*/ */
if (count($media_info)>=2){ if (count($media_info) >= 2) {
$data = [ $data = [
// '_id' => $id, // '_id' => $id,
...@@ -325,17 +327,17 @@ class MediaModel extends Eloquent ...@@ -325,17 +327,17 @@ class MediaModel extends Eloquent
'media_type_id' => $mediaCatg['_id'], 'media_type_id' => $mediaCatg['_id'],
'book_num' => $media_info[0], 'book_num' => $media_info[0],
'book_name' => $media_info[1], 'book_name' => $media_info[1],
'media_url' => $request->media_url?$request->media_url:$media['media_url'], 'media_url' => $request->media_url ? $request->media_url : $media['media_url'],
// 'access_key' => $request->access_key, // 'access_key' => $request->access_key,
'secret_key' => $request->secret_key?$request->secret_key:$media['secret_key'], 'secret_key' => $request->secret_key ? $request->secret_key : $media['secret_key'],
// 'create_time' => $media['create_time'], // 'create_time' => $media['create_time'],
'description' => $request->description, 'description' => $request->description,
'start_time' => $request->start_time?$start_time:$media['start_time'], 'start_time' => $request->start_time ? $start_time : $media['start_time'],
'end_time' => $request->end_time?$end_time:$media['start_time'], 'end_time' => $request->end_time ? $end_time : $media['start_time'],
//'duration' => $request->duration??"0", //'duration' => $request->duration??"0",
]; ];
}else{ } else {
$data = [ $data = [
// '_id' => $id, // '_id' => $id,
'media_name' => $request->media_name, 'media_name' => $request->media_name,
...@@ -343,31 +345,30 @@ class MediaModel extends Eloquent ...@@ -343,31 +345,30 @@ class MediaModel extends Eloquent
'media_type_id' => $mediaCatg['_id'], 'media_type_id' => $mediaCatg['_id'],
'book_num' => '', 'book_num' => '',
'book_name' => $request->media_name, 'book_name' => $request->media_name,
'media_url' => $request->media_url?$request->media_url:$media['media_url'], 'media_url' => $request->media_url ? $request->media_url : $media['media_url'],
// 'access_key' => $request->access_key, // 'access_key' => $request->access_key,
'secret_key' => $request->secret_key?$request->secret_key:$media['secret_key'], 'secret_key' => $request->secret_key ? $request->secret_key : $media['secret_key'],
// 'create_time' => date('Y-m-d H:i:s',time()), // 'create_time' => date('Y-m-d H:i:s',time()),
'description' => $request->description, 'description' => $request->description,
'start_time' => $request->start_time?$start_time:$media['start_time'], 'start_time' => $request->start_time ? $start_time : $media['start_time'],
'end_time' => $request->end_time?$end_time:$media['start_time'], 'end_time' => $request->end_time ? $end_time : $media['start_time'],
// 'duration' => $request->duration??"0", // 'duration' => $request->duration??"0",
]; ];
} }
$media_duration=$request->duration??"0"; $media_duration = $request->duration ?? "0";
if($media_duration!=0) if ($media_duration != 0) {
{ $data['duration'] = $request->duration;
$data['duration']=$request->duration;
} }
$flag = MediaModel::where("_id",$id)->update($data); $flag = MediaModel::where("_id", $id)->update($data);
if (!$flag){ if (!$flag) {
throw new \Exception("更新失败"); throw new \Exception("更新失败");
} }
//处理封面图片以及分辨率 //处理封面图片以及分辨率
//self::getScreeShotInfo($id); self::getScreeShotInfo($id);
LogModel::addlog(["更新媒资信息=>".$id,$data]); LogModel::addlog(["更新媒资信息=>" . $id, $data]);
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $flag; return $flag;
...@@ -380,16 +381,17 @@ class MediaModel extends Eloquent ...@@ -380,16 +381,17 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getMediaDetail($id){ public static function getMediaDetail($id)
{
try{ try {
$media = MediaModel::find($id); $media = MediaModel::find($id);
if (empty($media)){ if (empty($media)) {
throw new \Exception('媒资不存在'); throw new \Exception('媒资不存在');
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
...@@ -403,43 +405,44 @@ class MediaModel extends Eloquent ...@@ -403,43 +405,44 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getMediaList($request){ public static function getMediaList($request)
{
try{ try {
/** /**
*[{"bookNum":["hb15011","2"],"mediaCatg":"一题一码"}] *[{"bookNum":["hb15011","2"],"mediaCatg":"一题一码"}]
*/ */
$params = json_decode($request->params,true); $params = json_decode($request->params, true);
if (empty($params)){ if (empty($params)) {
throw new \Exception("参数格式有误"); throw new \Exception("参数格式有误");
} }
$tmp = []; $tmp = [];
foreach ($params as $param){ foreach ($params as $param) {
if (!isset($param['mediaCatg']) || !isset($param['bookNum'])){ if (!isset($param['mediaCatg']) || !isset($param['bookNum'])) {
throw new \Exception("格式有误"); throw new \Exception("格式有误");
} }
$media_name= $param['mediaCatg']; $media_name = $param['mediaCatg'];
$media_ids = $param['bookNum']; $media_ids = $param['bookNum'];
$media_catg = MediaCategoryModel::where('name',trim($media_name))->first(); $media_catg = MediaCategoryModel::where('name', trim($media_name))->first();
if (empty($media_catg)){ if (empty($media_catg)) {
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
$tmp[] = MediaModel::select("_id","book_num","book_name","secret_key","media_url")->where("media_type_id",$media_catg['_id'])->whereIn('book_num',$media_ids)->get(); $tmp[] = MediaModel::select("_id", "book_num", "book_name", "secret_key", "media_url")->where("media_type_id", $media_catg['_id'])->whereIn('book_num', $media_ids)->get();
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
$res = []; $res = [];
foreach ($tmp as $item){ foreach ($tmp as $item) {
$res = $item->groupBy("book_num"); $res = $item->groupBy("book_num");
} }
...@@ -452,11 +455,12 @@ class MediaModel extends Eloquent ...@@ -452,11 +455,12 @@ class MediaModel extends Eloquent
* @return int * @return int
* @throws \Exception * @throws \Exception
*/ */
public static function deleteMediaById($request,$id){ public static function deleteMediaById($request, $id)
{
try{ try {
$media = MediaModel::where('_id',$id)->first(); $media = MediaModel::where('_id', $id)->first();
if (empty($media)){ if (empty($media)) {
throw new \Exception('媒资不存在!'); throw new \Exception('媒资不存在!');
} }
...@@ -470,20 +474,20 @@ class MediaModel extends Eloquent ...@@ -470,20 +474,20 @@ class MediaModel extends Eloquent
$recycleId = RecycleModel::addRecycle($id); $recycleId = RecycleModel::addRecycle($id);
if (!$recycleId){ if (!$recycleId) {
$session->abortTransaction(); $session->abortTransaction();
throw new \Exception('回收站保存失败'); throw new \Exception('回收站保存失败');
} }
$flag = MediaModel::destroy($id); $flag = MediaModel::destroy($id);
if (!$flag){ if (!$flag) {
LogModel::addlog(["删除媒资失败"=> $id]); LogModel::addlog(["删除媒资失败" => $id]);
$session->abortTransaction(); $session->abortTransaction();
throw new \Exception('删除失败'); throw new \Exception('删除失败');
} }
$session->commitTransaction(); $session->commitTransaction();
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new \Exception($exception->getMessage()); throw new \Exception($exception->getMessage());
...@@ -497,26 +501,27 @@ class MediaModel extends Eloquent ...@@ -497,26 +501,27 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function playUrl($media_id){ public static function playUrl($media_id)
{
try{ try {
$media = MediaModel::select('media_url','secret_key','duration','media_name','status','height','width','screen_shot')->find($media_id); $media = MediaModel::select('media_url', 'secret_key', 'duration', 'media_name', 'status', 'height', 'width', 'screen_shot')->find($media_id);
if (empty($media)){ if (empty($media)) {
throw new \Exception("媒资不存在"); throw new \Exception("媒资不存在");
} }
if (!isset($media['duration'])){ if (!isset($media['duration'])) {
$media['duration'] = "0"; $media['duration'] = "0";
} }
if (!isset($media['status'])){ if (!isset($media['status'])) {
$media['status'] = "1"; $media['status'] = "1";
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
...@@ -529,60 +534,61 @@ class MediaModel extends Eloquent ...@@ -529,60 +534,61 @@ class MediaModel extends Eloquent
* @return \Illuminate\Database\Query\Expression * @return \Illuminate\Database\Query\Expression
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function handleMediaUrl($request){ public static function handleMediaUrl($request)
{
try{ try {
$medias = MediaModel::query()->raw(function ($collection) use($request){ $medias = MediaModel::query()->raw(function ($collection) use ($request) {
$limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER) ; $limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER);
$page = $request->page??1; $page = $request->page ?? 1;
/** /**
* 默认降序 * 默认降序
*/ */
$sort = -1; $sort = -1;
if ($request->sort == 'asc'){ if ($request->sort == 'asc') {
$sort = 1; $sort = 1;
} }
if (isset($request->media_id) && !empty($request->media_id)){ if (isset($request->media_id) && !empty($request->media_id)) {
$aggregate[]['$match']['_id'] = $request->media_id; $aggregate[]['$match']['_id'] = $request->media_id;
} }
$aggregate[]['$match']['media_url'] = ['$regex' => 'qcoenfz67.bkt.clouddn.com' ]; $aggregate[]['$match']['media_url'] = ['$regex' => 'qcoenfz67.bkt.clouddn.com'];
if (isset($request->username) && !empty($request->username)){ if (isset($request->username) && !empty($request->username)) {
$aggregate[]['$match']['username'] = $request->username; $aggregate[]['$match']['username'] = $request->username;
} }
$aggregate[]['$sort'] = ['start_time' => $sort]; $aggregate[]['$sort'] = ['start_time' => $sort];
$aggregate1=$aggregate; $aggregate1 = $aggregate;
$aggregate1[]['$group'] = [ $aggregate1[]['$group'] = [
'_id' => array(),//更具性别进行分组 '_id' => array(),//更具性别进行分组
'count'=>array('$sum'=>1) 'count' => array('$sum' => 1)
]; ];
$count = $collection->aggregate($aggregate1)->toArray(); $count = $collection->aggregate($aggregate1)->toArray();
if (isset($count[0])){ if (isset($count[0])) {
$count = $count[0]['count']; $count = $count[0]['count'];
}else{ } else {
$count = 0; $count = 0;
} }
// //
//$count = sizeof($collection->aggregate($aggregate)->toArray()); //$count = sizeof($collection->aggregate($aggregate)->toArray());
$skip = ((empty($request->page) ? 1 : $request->page)-1) * $limit; $skip = ((empty($request->page) ? 1 : $request->page) - 1) * $limit;
$aggregate[]['$skip'] = $skip; $aggregate[]['$skip'] = $skip;
$aggregate[]['$limit'] = $limit; $aggregate[]['$limit'] = $limit;
return new LengthAwarePaginator($collection->aggregate($aggregate)->toArray(), $count, $limit, $page,[ return new LengthAwarePaginator($collection->aggregate($aggregate)->toArray(), $count, $limit, $page, [
'path' => Paginator::resolveCurrentPath(), 'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page', 'pageName' => 'page',
]); ]);
...@@ -591,17 +597,16 @@ class MediaModel extends Eloquent ...@@ -591,17 +597,16 @@ class MediaModel extends Eloquent
}); });
if (!empty($medias)) {
if (!empty($medias)){
foreach ($medias as $media) {
foreach ($medias as $media){
$data = [ $data = [
'media_url' => "https://vod-mam.eoffcn.com/".$media->_id.'/index.m3u8', 'media_url' => "https://vod-mam.eoffcn.com/" . $media->_id . '/index.m3u8',
]; ];
$flag = MediaModel::where("_id",$media->_id)->update($data); $flag = MediaModel::where("_id", $media->_id)->update($data);
if ($flag==0){ if ($flag == 0) {
throw new \Exception("更新失败"); throw new \Exception("更新失败");
} }
} }
...@@ -609,8 +614,7 @@ class MediaModel extends Eloquent ...@@ -609,8 +614,7 @@ class MediaModel extends Eloquent
} }
} catch (\Exception $exception) {
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $medias; return $medias;
...@@ -624,14 +628,15 @@ class MediaModel extends Eloquent ...@@ -624,14 +628,15 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function updateMediaStatus($request,$media_id){ public static function updateMediaStatus($request, $media_id)
try{ {
try {
$media = MediaModel::where('_id',$media_id)->first(); $media = MediaModel::where('_id', $media_id)->first();
if (empty($media)){ if (empty($media)) {
$mediaCatg = MediaCategoryModel::where('_id',$request->media_type)->first(); $mediaCatg = MediaCategoryModel::where('_id', $request->media_type)->first();
if (empty($mediaCatg)){ if (empty($mediaCatg)) {
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
...@@ -639,41 +644,41 @@ class MediaModel extends Eloquent ...@@ -639,41 +644,41 @@ class MediaModel extends Eloquent
$data = [ $data = [
'_id' => $media_id, '_id' => $media_id,
'media_name' => $request->media_name??"", 'media_name' => $request->media_name ?? "",
'media_type' => $mediaCatg['name'], 'media_type' => $mediaCatg['name'],
'media_type_id' => $mediaCatg['_id'], 'media_type_id' => $mediaCatg['_id'],
'media_url' => $request->media_url??"", 'media_url' => $request->media_url ?? "",
'access_key' => $request->access_key??"", 'access_key' => $request->access_key ?? "",
'secret_key' => $request->secret_key??"", 'secret_key' => $request->secret_key ?? "",
'create_time' => $create_time, 'create_time' => $create_time,
'description' => $request->description??"", 'description' => $request->description ?? "",
'start_time' => $create_time, 'start_time' => $create_time,
'end_time' => $create_time, 'end_time' => $create_time,
'duration' => $request->duration??"0", 'duration' => $request->duration ?? "0",
"username" => "offcn", "username" => "offcn",
"mis_uid" => "admin" "mis_uid" => "admin"
]; ];
$id = MediaModel::insertGetId($data); $id = MediaModel::insertGetId($data);
LogModel::addlog(["添加媒资信息"=> $data,['媒资ID为:=> '.$id]]); LogModel::addlog(["添加媒资信息" => $data, ['媒资ID为:=> ' . $id]]);
return $id; return $id;
} }
if ($request->status){ if ($request->status) {
$data = [ $data = [
'media_url' => $request->media_url??"", 'media_url' => $request->media_url ?? "",
'media_name' => $request->media_name??"", 'media_name' => $request->media_name ?? "",
'duration' => $request->duration??"0", 'duration' => $request->duration ?? "0",
'access_key' => $request->access_key??"", 'access_key' => $request->access_key ?? "",
'secret_key' => $request->secret_key??"", 'secret_key' => $request->secret_key ?? "",
'status' => $request->status??'' 'status' => $request->status ?? ''
]; ];
LogModel::addlog(["原media信息为"=>json_encode($media),"更新为"=>json_encode($data)]); LogModel::addlog(["原media信息为" => json_encode($media), "更新为" => json_encode($data)]);
}else{ } else {
$data['status'] = "0"; $data['status'] = "0";
} }
...@@ -687,15 +692,15 @@ class MediaModel extends Eloquent ...@@ -687,15 +692,15 @@ class MediaModel extends Eloquent
// } // }
// } // }
$flag = MediaModel::where("_id",$media_id)->update($data); $flag = MediaModel::where("_id", $media_id)->update($data);
if (!$flag){ if (!$flag) {
LogModel::addlog("Status更新失败"); LogModel::addlog("Status更新失败");
//throw new \Exception("Status更新失败"); //throw new \Exception("Status更新失败");
} }
LogModel::addlog(["更新媒资信息Status=>".$media_id,$data]); LogModel::addlog(["更新媒资信息Status=>" . $media_id, $data]);
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $media_id; return $media_id;
...@@ -708,24 +713,25 @@ class MediaModel extends Eloquent ...@@ -708,24 +713,25 @@ class MediaModel extends Eloquent
* @return \Illuminate\Database\Query\Expression * @return \Illuminate\Database\Query\Expression
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function updateDatetime($request){ public static function updateDatetime($request)
{
try{ try {
$medias = MediaModel::query()->raw(function ($collection) use($request){ $medias = MediaModel::query()->raw(function ($collection) use ($request) {
$limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER) ; $limit = (isset($request->page_size) ? (int)($request->page_size) : Constant::PAGE_NUMBER);
$page = $request->page??1; $page = $request->page ?? 1;
/** /**
* 默认降序 * 默认降序
*/ */
$sort = -1; $sort = -1;
if ($request->sort == 'asc'){ if ($request->sort == 'asc') {
$sort = 1; $sort = 1;
} }
if (isset($request->media_id) && !empty($request->media_id)){ if (isset($request->media_id) && !empty($request->media_id)) {
$aggregate[]['$match']['_id'] = $request->media_id; $aggregate[]['$match']['_id'] = $request->media_id;
} }
...@@ -739,30 +745,30 @@ class MediaModel extends Eloquent ...@@ -739,30 +745,30 @@ class MediaModel extends Eloquent
$aggregate[]['$sort'] = ['start_time' => $sort]; $aggregate[]['$sort'] = ['start_time' => $sort];
$aggregate1=$aggregate; $aggregate1 = $aggregate;
$aggregate1[]['$group'] = [ $aggregate1[]['$group'] = [
'_id' => array(),//更具性别进行分组 '_id' => array(),//更具性别进行分组
'count'=>array('$sum'=>1) 'count' => array('$sum' => 1)
]; ];
$count = $collection->aggregate($aggregate1)->toArray(); $count = $collection->aggregate($aggregate1)->toArray();
if (isset($count[0])){ if (isset($count[0])) {
$count = $count[0]['count']; $count = $count[0]['count'];
}else{ } else {
$count = 0; $count = 0;
} }
//$count = sizeof($collection->aggregate($aggregate)->toArray()); //$count = sizeof($collection->aggregate($aggregate)->toArray());
$skip = ((empty($request->page) ? 1 : $request->page)-1) * $limit; $skip = ((empty($request->page) ? 1 : $request->page) - 1) * $limit;
$aggregate[]['$skip'] = $skip; $aggregate[]['$skip'] = $skip;
$aggregate[]['$limit'] = $limit; $aggregate[]['$limit'] = $limit;
return new LengthAwarePaginator($collection->aggregate($aggregate)->toArray(), $count, $limit, $page,[ return new LengthAwarePaginator($collection->aggregate($aggregate)->toArray(), $count, $limit, $page, [
'path' => Paginator::resolveCurrentPath(), 'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page', 'pageName' => 'page',
]); ]);
...@@ -770,19 +776,19 @@ class MediaModel extends Eloquent ...@@ -770,19 +776,19 @@ class MediaModel extends Eloquent
}); });
if (!empty($medias)){ if (!empty($medias)) {
foreach ($medias as $media){ foreach ($medias as $media) {
/** /**
* 构造开始时间,结束时间 * 构造开始时间,结束时间
*/ */
$tmp_medias = MediaModel::where("media_name",$media['media_name'])->count(); $tmp_medias = MediaModel::where("media_name", $media['media_name'])->count();
if ($tmp_medias>1){ if ($tmp_medias > 1) {
MediaModel::deleteMediaById($request,$media['_id']); MediaModel::deleteMediaById($request, $media['_id']);
var_dump($tmp_medias); var_dump($tmp_medias);
} }
...@@ -792,7 +798,7 @@ class MediaModel extends Eloquent ...@@ -792,7 +798,7 @@ class MediaModel extends Eloquent
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $medias; return $medias;
...@@ -803,20 +809,21 @@ class MediaModel extends Eloquent ...@@ -803,20 +809,21 @@ class MediaModel extends Eloquent
* @return string * @return string
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getMediaId(){ public static function getMediaId()
{
try{ try {
$i = 0; $i = 0;
do { do {
$media_id = "mda-".generateRandomNum(16); $media_id = "mda-" . generateRandomNum(16);
$media = MediaModel::find($media_id); $media = MediaModel::find($media_id);
$i ++; $i++;
} while ($i < 3 && !empty($media) ); } while ($i < 3 && !empty($media));
if ($i == 3){ if ($i == 3) {
throw new \Exception('获取媒资编号失败'); throw new \Exception('获取媒资编号失败');
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $media_id; return $media_id;
...@@ -828,37 +835,35 @@ class MediaModel extends Eloquent ...@@ -828,37 +835,35 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function setMediaNum($request){ public static function setMediaNum($request)
try{ {
try {
$media_id = $request->media_id; $media_id = $request->media_id;
$data = [ $data = [
'media_num' => md5(md5($media_id)), 'media_num' => md5(md5($media_id)),
]; ];
$flag = MediaModel::where("_id",$media_id)->update($data); $flag = MediaModel::where("_id", $media_id)->update($data);
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $flag; return $flag;
} }
public static function multiplySetMediaNum($request){ public static function multiplySetMediaNum($request)
{
try{ try {
$media_ids = $request->media_ids; $media_ids = $request->media_ids;
//$flag = MediaModel::whereIn("_id",$media_ids)->get($data,['multiple'=>true]); //$flag = MediaModel::whereIn("_id",$media_ids)->get($data,['multiple'=>true]);
$medias = MediaModel::whereIn("_id",$media_ids)->limit(self::$max_page_size)->get(); $medias = MediaModel::whereIn("_id", $media_ids)->limit(self::$max_page_size)->get();
$multiplied = collect($medias)->map(function ($item, $key) { $multiplied = collect($medias)->map(function ($item, $key) {
return $item * 2; return $item * 2;
}); });
...@@ -873,8 +878,8 @@ class MediaModel extends Eloquent ...@@ -873,8 +878,8 @@ class MediaModel extends Eloquent
$data = [ $data = [
'media_num' => md5(md5($media_id)), 'media_num' => md5(md5($media_id)),
]; ];
$flag = MediaModel::whereIn("_id",$media_id)->update($data,['multiple'=>true]); $flag = MediaModel::whereIn("_id", $media_id)->update($data, ['multiple' => true]);
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $flag; return $flag;
...@@ -882,21 +887,20 @@ class MediaModel extends Eloquent ...@@ -882,21 +887,20 @@ class MediaModel extends Eloquent
} }
/** /**
* 根据媒资编号获取媒资随机码 * 根据媒资编号获取媒资随机码
* @param $request * @param $request
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getMediaInfoByNum($request){ public static function getMediaInfoByNum($request)
try{ {
$media = MediaModel::select('_id','secret_key','duration','media_name','status')->where("media_num",$request->media_num)->first(); try {
if (empty($media)){ $media = MediaModel::select('_id', 'secret_key', 'duration', 'media_name', 'status')->where("media_num", $request->media_num)->first();
if (empty($media)) {
throw new \Exception("媒资信息不存在"); throw new \Exception("媒资信息不存在");
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $media; return $media;
...@@ -907,32 +911,30 @@ class MediaModel extends Eloquent ...@@ -907,32 +911,30 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function clearCdnCache($request,$media_id){ public static function clearCdnCache($request, $media_id)
{
try{ try {
/** /**
* 判断媒资ID是否存在 * 判断媒资ID是否存在
*/ */
$media = MediaModel::where("media_num",$request->media_num)->first(); $media = MediaModel::where("media_num", $request->media_num)->first();
if (empty($media)){ if (empty($media)) {
throw new \Exception("媒资信息不存在"); throw new \Exception("媒资信息不存在");
} }
$media_type = $media['media_type_id']; $media_type = $media['media_type_id'];
$mediaCatg = MediaCategoryModel::where('_id',$media_type)->first(); $mediaCatg = MediaCategoryModel::where('_id', $media_type)->first();
if (empty($mediaCatg)){ if (empty($mediaCatg)) {
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
$call_back = $mediaCatg['call_back']; $call_back = $mediaCatg['call_back'];
$url = getRbac($request,$call_back,$mediaCatg['media_category_id'] ,$type='clear_cache'); $url = getRbac($request, $call_back, $mediaCatg['media_category_id'], $type = 'clear_cache');
http_request_code($url,null,'POST',['mediaId'=>$media_id]); http_request_code($url, null, 'POST', ['mediaId' => $media_id]);
} catch (\Exception $exception) {
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
return $media; return $media;
...@@ -946,37 +948,38 @@ class MediaModel extends Eloquent ...@@ -946,37 +948,38 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getMediaForeverM3u8($request){ public static function getMediaForeverM3u8($request)
{
try{ try {
$media_id = $request->media_id; $media_id = $request->media_id;
/** /**
* 判断媒资ID是否存在 * 判断媒资ID是否存在
*/ */
$media = MediaModel::where("_id",$media_id)->first(); $media = MediaModel::where("_id", $media_id)->first();
if (empty($media)){ if (empty($media)) {
throw new \Exception("媒资信息不存在"); throw new \Exception("媒资信息不存在");
} }
$media_type = $media['media_type_id']; $media_type = $media['media_type_id'];
$mediaCatg = MediaCategoryModel::where('_id',$media_type)->first(); $mediaCatg = MediaCategoryModel::where('_id', $media_type)->first();
if (empty($mediaCatg)){ if (empty($mediaCatg)) {
throw new \Exception("媒资类别不存在"); throw new \Exception("媒资类别不存在");
} }
$url = getRbac($request,'video/info',$media_id ,$type='play_m3u8'); $url = getRbac($request, 'video/info', $media_id, $type = 'play_m3u8');
$res = http_request_code($url,null,'GET'); $res = http_request_code($url, null, 'GET');
$result = json_decode($res,true); $result = json_decode($res, true);
if ($result['code'] != 0){ if ($result['code'] != 0) {
LogModel::addlog($result); LogModel::addlog($result);
throw new \Exception("获取数据失败"); throw new \Exception("获取数据失败");
} }
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
...@@ -989,31 +992,32 @@ class MediaModel extends Eloquent ...@@ -989,31 +992,32 @@ class MediaModel extends Eloquent
* @return array * @return array
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function batchGetMediaForverM3u8($request,array $orginal_data){ public static function batchGetMediaForverM3u8($request, array $orginal_data)
{
try{ try {
$ids = implode(',',array_keys($orginal_data)); $ids = implode(',', array_keys($orginal_data));
#生成批量处理地址 #生成批量处理地址
$url = getRbac($request,'video/infos','' ,$type='mul_play_m3u8'); $url = getRbac($request, 'video/infos', '', $type = 'mul_play_m3u8');
$res = http_request_code($url,null,'POST',array('mediaIds'=>$ids)); $res = http_request_code($url, null, 'POST', array('mediaIds' => $ids));
$result = json_decode($res,true); $result = json_decode($res, true);
if (empty($result)){ if (empty($result)) {
return []; return [];
} }
if ($result['code'] != 0){ if ($result['code'] != 0) {
LogModel::addlog($result); LogModel::addlog($result);
throw new \Exception("获取数据失败"); throw new \Exception("获取数据失败");
} }
return self::mediaExportFormat($result['data'],$orginal_data); return self::mediaExportFormat($result['data'], $orginal_data);
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
} }
...@@ -1024,22 +1028,23 @@ class MediaModel extends Eloquent ...@@ -1024,22 +1028,23 @@ class MediaModel extends Eloquent
* @param $media_ids * @param $media_ids
* @return mixed * @return mixed
*/ */
private static function mediaExportFormat(array $data,$orginal_data){ private static function mediaExportFormat(array $data, $orginal_data)
{
foreach ($orginal_data as $key => &$item){ foreach ($orginal_data as $key => &$item) {
if (empty($data[$key])){ if (empty($data[$key])) {
$item['media_id'] = $key; $item['media_id'] = $key;
$item['media_name'] = '未查到相关数据'; $item['media_name'] = '未查到相关数据';
$item['forvery_url'] = '未查到相关数据'; $item['forvery_url'] = '未查到相关数据';
$item['is_full_url'] = "未查到相关数据"; $item['is_full_url'] = "未查到相关数据";
}else{ } else {
$media_id = $item['media_id']; $media_id = $item['media_id'];
$media = MediaModel::select('media_name')->where('_id',$media_id)->first(); $media = MediaModel::select('media_name')->where('_id', $media_id)->first();
$media_num = md5(md5($media_id)); $media_num = md5(md5($media_id));
...@@ -1048,11 +1053,11 @@ class MediaModel extends Eloquent ...@@ -1048,11 +1053,11 @@ class MediaModel extends Eloquent
$tmp = [ $tmp = [
'media_num' => $media_num, 'media_num' => $media_num,
]; ];
MediaModel::where("_id",$media_id)->update($tmp); MediaModel::where("_id", $media_id)->update($tmp);
$url = getenv('preview_domain')?getenv('preview_domain'):"https://xue.t.eoffcn.com/preview/temp/"; $url = getenv('preview_domain') ? getenv('preview_domain') : "https://xue.t.eoffcn.com/preview/temp/";
$item['forvery_url'] = $data[$key]['url']; $item['forvery_url'] = $data[$key]['url'];
$item['is_full_url'] = $url."player".'/'.$media_num; $item['is_full_url'] = $url . "player" . '/' . $media_num;
} }
...@@ -1067,12 +1072,13 @@ class MediaModel extends Eloquent ...@@ -1067,12 +1072,13 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getMediaListByMediaIds($request){ public static function getMediaListByMediaIds($request)
{
try{ try {
$media_ids = $request->media_ids; $media_ids = $request->media_ids;
$medias = MediaModel::select("_id","media_name","duration","secret_key","media_url")->where("status","1")->where("duration",">","0")->where("media_url","!=","")->whereIn('_id',$media_ids)->limit(100)->get(); $medias = MediaModel::select("_id", "media_name", "duration", "secret_key", "media_url")->where("status", "1")->where("duration", ">", "0")->where("media_url", "!=", "")->whereIn('_id', $media_ids)->limit(100)->get();
}catch (\Exception $exception){ } catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
...@@ -1085,45 +1091,59 @@ class MediaModel extends Eloquent ...@@ -1085,45 +1091,59 @@ class MediaModel extends Eloquent
* @return mixed * @return mixed
* @throws DatabaseException * @throws DatabaseException
*/ */
public static function getScreeShotInfo($request){ public static function GetScreeShotInfo($media_id)
{
try{ LogModel::addlog(["向第三方发送获取 screenshot 数据请求",$media_id]);
$media = MediaModel::select("_id","media_name","duration","secret_key","media_url")->where('_id',$media_id)->first(); try {
}catch (\Exception $exception){ $media = MediaModel::select("_id", "media_name", "duration", "secret_key", "media_url")->where('_id', $media_id)->first();
} catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage()); throw new DatabaseException($exception->getMessage());
} }
//获取媒资截图数据 //获取媒资截图数据
//http://test-playback.offcncloud.com/api/v1/vodRecordInfo //http://test-playback.offcncloud.com/api/v1/vodRecordInfo
$playbackUrl = getenv('playback')?getenv('playback'):'http://test-playback.offcncloud.com'; $playbackUrl = getenv('playback') ? getenv('playback') : 'http://test-playback.offcncloud.com';
$params = array( $params = array(
"url" => $media["media_url"], "url" => $media["media_url"],
"key" => $media["secret_key"] "key" => $media["secret_key"],
"media_id" => $media_id,
); );
$data = json_encode($params); $data = json_encode($params);
$header = array( $header = array(
"Content-Type: application/json", "Content-Type: application/json",
"Content-Length: ".strlen($data) "Content-Length: " . strlen($data)
); );
$url = $playbackUrl."/api/v1/vodRecordInfo"; $url = $playbackUrl . "/api/v1/vodRecordInfo";
LogModel::addlog(["第三方获取媒资 screenshot 请求路径"=>$url,"请求参数"=>$data,"请求头"=>$header]); LogModel::addlog(["第三方获取媒资 screenshot 请求路径" => $url, "请求参数" => $data, "请求头" => $header]);
$res = http_request_code($url,$header,'POST',$data,15); $res = http_request_code($url, $header, 'POST', $data);
$result = json_decode($res,true); LogModel::addlog(["第三方获取媒资 screenshot 数据" => $res, "请求路径" => $url, "请求参数" => $data, "请求头" => $header]);
LogModel::addlog(["第三方获取媒资 screenshot 数据"=>$res,"请求路径"=>$url,"请求参数"=>$data,"请求头"=>$header]);
$item = array();
if (isset($result["data"])){
$item["screen_shot"]["height"] = $result["data"]["height"];
$item["screen_shot"]["width"] = $result["data"]["width"];
$item["screen_shot"]["url"] = $result["data"]["screenshot"];
$flag = MediaModel::where("_id",$media_id)->update($item);
if (!$flag){
LogModel::addlog(["更新 screenshot 数据失败 第三方screenshot数据"=>$res,"请求路径"=>$url,"请求参数"=>$data,"请求头"=>$header]);
throw new DatabaseException("更新媒资 screenshot 数据失败");
} }
LogModel::addlog(["媒资 screenshot 数据成功 最终screenshot结果"=>$result,"请求参数"=>$params]);
/**
* @param $request
* @return array
* @throws DatabaseException
*/
public static function UpdateScreenShotInfo($request)
{
LogModel::addlog(["接收到更新 screenshot 数据回调 " => $request->all()]);
$media_id = $request->media_id;
try {
MediaModel::select("_id", "media_name", "duration", "secret_key", "media_url")->where('_id', $media_id)->first();
} catch (\Exception $exception) {
throw new DatabaseException($exception->getMessage());
}
$item["screen_shot"]["height"] = $request->height;
$item["screen_shot"]["width"] = $request->width;
$item["screen_shot"]["url"] = $request->screenshot;
$flag = MediaModel::where("_id", $media_id)->update($item);
if (!$flag) {
throw new DatabaseException("更新媒资 screenshot 数据失败");
} }
return $item; LogModel::addlog(["更新媒资 screenshot 数据成功 " => $item]);
} }
} }
...@@ -53,6 +53,5 @@ Route::group(['namespace' => 'Api', 'prefix' => 'user','middleware' => ['api']], ...@@ -53,6 +53,5 @@ Route::group(['namespace' => 'Api', 'prefix' => 'user','middleware' => ['api']],
Route::post("getMediaListByMediaIds","MediaController@getMediaListByMediaIds"); Route::post("getMediaListByMediaIds","MediaController@getMediaListByMediaIds");
//Route::get("media_url_change","MediaController@handleMediaUrl"); //Route::get("media_url_change","MediaController@handleMediaUrl");
Route::post("screenShot","MediaController@getScreeShotInfo"); Route::post("screenShotCallback","MediaController@screenShotCallback");
Route::post("screenShotCallback","MediaController@updateScreeShotInfo");
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment