Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media-resource
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨昕
media-resource
Commits
ecb58233
Commit
ecb58233
authored
Jul 12, 2022
by
杨昕
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' into 'master'
Test See merge request
!40
parents
1314b32c
b811f2fc
Pipeline
#18848
passed with stages
in 58 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
474 additions
and
323 deletions
+474
-323
functions.php
app/Helpers/functions.php
+4
-7
MediaController.php
app/Http/Controllers/Api/MediaController.php
+107
-54
MediaModel.php
app/Model/MediaModel.php
+358
-261
api.php
routes/api.php
+5
-1
No files found.
app/Helpers/functions.php
View file @
ecb58233
...
@@ -45,8 +45,6 @@ function handler_drive($callback)
...
@@ -45,8 +45,6 @@ function handler_drive($callback)
function
http_request_code
(
$url
,
$isHearder
=
null
,
$post
=
'GET'
,
$data
=
null
,
$timeout
=
1
)
function
http_request_code
(
$url
,
$isHearder
=
null
,
$post
=
'GET'
,
$data
=
null
,
$timeout
=
1
)
{
{
// 初始化curl
// 初始化curl
$ch
=
curl_init
();
$ch
=
curl_init
();
//设置URL地址
//设置URL地址
...
@@ -58,27 +56,26 @@ function http_request_code($url, $isHearder = null, $post = 'GET', $data = null,
...
@@ -58,27 +56,26 @@ function http_request_code($url, $isHearder = null, $post = 'GET', $data = null,
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$isHearder
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$isHearder
);
}
}
//如果是post,则把data的数据传递过去
//如果是post,则把data的数据传递过去
if
((
$post
==
'POST'
)
)
{
if
((
$post
==
'POST'
)
)
{
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
//要求结果为字符串且输出到屏幕上
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
//要求结果为字符串且输出到屏幕上
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$data
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$data
);
}
}
//如果是删除方法,则是以delete请求或者Post请求
//如果是删除方法,则是以delete请求或者Post请求
if
(
$post
==
'DELETE'
||
$post
==
'POST'
)
{
if
(
$post
==
'DELETE'
||
$post
==
'POST'
)
{
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
$post
);
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
$post
);
}
}
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
0
);
//
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
//设置超时时间,毫秒
//设置超时时间,毫秒
// curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout * 100);
if
(
$timeout
){
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT_MS
,
$timeout
*
1000
);
}
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
//执行CURL时间
//执行CURL时间
$result
=
curl_exec
(
$ch
);
$result
=
curl_exec
(
$ch
);
//如果有异常,记录到日志当中
//如果有异常,记录到日志当中
$curl_errno
=
curl_errno
(
$ch
);
$curl_errno
=
curl_errno
(
$ch
);
if
(
$curl_errno
>
0
)
{
if
(
$curl_errno
>
0
)
{
...
...
app/Http/Controllers/Api/MediaController.php
View file @
ecb58233
...
@@ -27,11 +27,12 @@ class MediaController extends Controller
...
@@ -27,11 +27,12 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
media_list
(
Request
$request
){
public
function
media_list
(
Request
$request
)
{
$result
=
handler_drive
(
function
()
use
(
$request
){
$result
=
handler_drive
(
function
()
use
(
$request
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,[
SrsHookValidate
::
srsHookCallback
(
$request
,
[
'params'
=>
'required'
'params'
=>
'required'
]);
]);
...
@@ -49,9 +50,10 @@ class MediaController extends Controller
...
@@ -49,9 +50,10 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
play_url
(
Request
$request
,
$media_id
){
public
function
play_url
(
Request
$request
,
$media_id
)
{
$result
=
handler_drive
(
function
()
use
(
$request
,
$media_id
)
{
$result
=
handler_drive
(
function
()
use
(
$request
,
$media_id
)
{
return
MediaModel
::
playUrl
(
$media_id
);
return
MediaModel
::
playUrl
(
$media_id
);
});
});
...
@@ -60,18 +62,18 @@ class MediaController extends Controller
...
@@ -60,18 +62,18 @@ class MediaController extends Controller
}
}
/**
/**
* 获取媒资列表
* 获取媒资列表
* @param Request $request
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
mediaListOnce
(
Request
$request
){
public
function
mediaListOnce
(
Request
$request
)
{
$res
=
handler_drive
(
function
()
use
(
$request
)
{
$res
=
handler_drive
(
function
()
use
(
$request
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,[
SrsHookValidate
::
srsHookCallback
(
$request
,
[
'page'
=>
'integer'
,
'page'
=>
'integer'
,
'sort'
=>
''
,
'sort'
=>
''
,
'page_size'
=>
'integer'
,
'page_size'
=>
'integer'
,
...
@@ -80,8 +82,8 @@ class MediaController extends Controller
...
@@ -80,8 +82,8 @@ class MediaController extends Controller
'category_id'
=>
''
'category_id'
=>
''
]);
]);
if
(
!
isset
(
$request
->
category_id
)){
if
(
!
isset
(
$request
->
category_id
))
{
$request
->
replace
(
array_merge
(
$request
->
all
(),
[
'category_id'
=>
'5efa9cb5d16f5a214671fd86'
]));
$request
->
replace
(
array_merge
(
$request
->
all
(),
[
'category_id'
=>
'5efa9cb5d16f5a214671fd86'
]));
}
}
return
MediaModel
::
mediaList
(
$request
);
return
MediaModel
::
mediaList
(
$request
);
...
@@ -92,30 +94,31 @@ class MediaController extends Controller
...
@@ -92,30 +94,31 @@ class MediaController extends Controller
}
}
public
function
test
(
Request
$request
){
public
function
test
(
Request
$request
)
{
$res
=
[];
$res
=
[];
for
(
$i
=
0
;
$i
<=
5
;
$i
++
)
{
for
(
$i
=
0
;
$i
<=
5
;
$i
++
)
{
$url
=
"http://eoffcn.com/api/user/media_list_once?page="
.
$i
.
'&page_size=1000'
;
$url
=
"http://eoffcn.com/api/user/media_list_once?page="
.
$i
.
'&page_size=1000'
;
$result
=
http_request_code
(
$url
,
null
,
'GET'
);
$result
=
http_request_code
(
$url
,
null
,
'GET'
);
$medias
=
json_decode
(
$result
,
true
);
$medias
=
json_decode
(
$result
,
true
);
if
(
isset
(
$medias
[
'data'
][
'data'
])
&&
!
empty
(
$medias
[
'data'
][
'data'
])){
if
(
isset
(
$medias
[
'data'
][
'data'
])
&&
!
empty
(
$medias
[
'data'
][
'data'
]))
{
$data
=
$medias
[
'data'
][
'data'
];
$data
=
$medias
[
'data'
][
'data'
];
if
(
!
empty
(
$data
)){
if
(
!
empty
(
$data
))
{
foreach
(
$data
as
$media
){
foreach
(
$data
as
$media
)
{
$tmp_arr
=
MediaModel
::
where
(
"media_name"
,
$media
[
'media_name'
])
->
where
(
"media_type_id"
,
"5efa9ca25b742508e81f2d55"
)
->
get
();
$tmp_arr
=
MediaModel
::
where
(
"media_name"
,
$media
[
'media_name'
])
->
where
(
"media_type_id"
,
"5efa9ca25b742508e81f2d55"
)
->
get
();
if
(
count
(
$tmp_arr
)
>=
2
)
{
if
(
count
(
$tmp_arr
)
>=
2
)
{
var_dump
(
$media
);
var_dump
(
$media
);
MediaModel
::
deleteMediaById
(
$request
,
$media
[
"_id"
]);
MediaModel
::
deleteMediaById
(
$request
,
$media
[
"_id"
]);
}
}
...
@@ -131,15 +134,17 @@ class MediaController extends Controller
...
@@ -131,15 +134,17 @@ class MediaController extends Controller
}
}
/**
/**
* @param Request $request
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
handleMediaUrl
(
Request
$request
){
public
function
handleMediaUrl
(
Request
$request
)
{
$res
=
handler_drive
(
function
()
use
(
$request
)
{
$res
=
handler_drive
(
function
()
use
(
$request
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,[
SrsHookValidate
::
srsHookCallback
(
$request
,
[
'media_name'
=>
''
,
'media_name'
=>
''
,
'username'
=>
''
,
'username'
=>
''
,
'page'
=>
'integer'
,
'page'
=>
'integer'
,
...
@@ -160,11 +165,12 @@ class MediaController extends Controller
...
@@ -160,11 +165,12 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
hookRestoreMedia
(
Request
$request
){
public
function
hookRestoreMedia
(
Request
$request
)
{
$id
=
handler_drive
(
function
()
use
(
$request
)
{
$id
=
handler_drive
(
function
()
use
(
$request
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,
array_merge
([
SrsHookValidate
::
srsHookCallback
(
$request
,
array_merge
([
'media_name'
=>
'required'
,
'media_name'
=>
'required'
,
'secret_key'
=>
''
,
'secret_key'
=>
''
,
'media_url'
=>
'required'
,
'media_url'
=>
'required'
,
...
@@ -179,21 +185,21 @@ class MediaController extends Controller
...
@@ -179,21 +185,21 @@ class MediaController extends Controller
$params
=
array
(
$params
=
array
(
'media_id'
=>
MediaModel
::
getMediaId
(),
'media_id'
=>
MediaModel
::
getMediaId
(),
'media_type'
=>
'5efa9cb5d16f5a214671fd86'
,
//默认,中公网校
'media_type'
=>
'5efa9cb5d16f5a214671fd86'
,
//默认,中公网校
'start_time'
=>
$data_time
,
'start_time'
=>
$data_time
,
'end_time'
=>
$data_time
,
'end_time'
=>
$data_time
,
'access_key'
=>
''
,
'access_key'
=>
''
,
'description'
=>
$request
->
description
??
''
,
'description'
=>
$request
->
description
??
''
,
);
);
//shop_id为100时,代表的是北大学堂的视频
//shop_id为100时,代表的是北大学堂的视频
if
(
$request
->
shop_id
==
'100'
)
{
if
(
$request
->
shop_id
==
'100'
)
{
$catg
=
MediaCategoryModel
::
getCategoryByName
(
"北大学堂"
);
$catg
=
MediaCategoryModel
::
getCategoryByName
(
"北大学堂"
);
$params
[
'media_type'
]
=
$catg
[
'_id'
];
$params
[
'media_type'
]
=
$catg
[
'_id'
];
}
}
$request
->
replace
(
array_merge
(
$request
->
all
(),
$params
));
$request
->
replace
(
array_merge
(
$request
->
all
(),
$params
));
$id
=
MediaModel
::
hookRestoreMedia
(
$request
);
$id
=
MediaModel
::
hookRestoreMedia
(
$request
);
...
@@ -208,12 +214,13 @@ class MediaController extends Controller
...
@@ -208,12 +214,13 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
updateMediaStatus
(
Request
$request
,
$media_id
){
public
function
updateMediaStatus
(
Request
$request
,
$media_id
)
{
$id
=
handler_drive
(
function
()
use
(
$request
,
$media_id
)
{
$id
=
handler_drive
(
function
()
use
(
$request
,
$media_id
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,[
SrsHookValidate
::
srsHookCallback
(
$request
,
[
'status'
=>
''
,
'status'
=>
''
,
'secret_key'
=>
''
,
'secret_key'
=>
''
,
'media_url'
=>
''
,
'media_url'
=>
''
,
...
@@ -224,13 +231,13 @@ class MediaController extends Controller
...
@@ -224,13 +231,13 @@ class MediaController extends Controller
'media_type'
=>
''
,
'media_type'
=>
''
,
'shop_id'
=>
''
,
'shop_id'
=>
''
,
],
function
(
$items
)
{
],
function
(
$items
)
{
$request
=
$items
;
$request
=
$items
;
if
(
$request
->
status
){
if
(
$request
->
status
)
{
if
(
!
$request
->
media_url
)
{
if
(
!
$request
->
media_url
)
{
throw
new
FormException
(
"参数缺失"
);
throw
new
FormException
(
"参数缺失"
);
}
}
}
}
...
@@ -241,20 +248,20 @@ class MediaController extends Controller
...
@@ -241,20 +248,20 @@ class MediaController extends Controller
* 设置开始时间与结束时间
* 设置开始时间与结束时间
*/
*/
$params
=
array
(
$params
=
array
(
'media_type'
=>
'5efa9cb5d16f5a214671fd86'
,
//默认,中公网校
'media_type'
=>
'5efa9cb5d16f5a214671fd86'
,
//默认,中公网校
'access_key'
=>
''
,
'access_key'
=>
''
,
'description'
=>
$request
->
description
??
''
,
'description'
=>
$request
->
description
??
''
,
);
);
if
(
$request
->
shop_id
==
'100'
)
{
if
(
$request
->
shop_id
==
'100'
)
{
$params
[
'media_type'
]
=
"5f3d073a033f5a336b2b4346"
;
$params
[
'media_type'
]
=
"5f3d073a033f5a336b2b4346"
;
}
}
$request
->
replace
(
array_merge
(
$request
->
all
(),
$params
));
$request
->
replace
(
array_merge
(
$request
->
all
(),
$params
));
LogModel
::
addlog
([
'media_id'
=>
$media_id
,
"更新媒资状态"
=>
json_encode
(
$request
->
all
())]);
LogModel
::
addlog
([
'media_id'
=>
$media_id
,
"更新媒资状态"
=>
json_encode
(
$request
->
all
())]);
$id
=
MediaModel
::
updateMediaStatus
(
$request
,
$media_id
);
$id
=
MediaModel
::
updateMediaStatus
(
$request
,
$media_id
);
return
$id
;
return
$id
;
});
});
...
@@ -268,7 +275,8 @@ class MediaController extends Controller
...
@@ -268,7 +275,8 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
updateDatetime
(
Request
$request
){
public
function
updateDatetime
(
Request
$request
)
{
$id
=
handler_drive
(
function
()
use
(
$request
)
{
$id
=
handler_drive
(
function
()
use
(
$request
)
{
...
@@ -286,7 +294,8 @@ class MediaController extends Controller
...
@@ -286,7 +294,8 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
getMediaInfoByNum
(
Request
$request
){
public
function
getMediaInfoByNum
(
Request
$request
)
{
$data
=
handler_drive
(
function
()
use
(
$request
)
{
$data
=
handler_drive
(
function
()
use
(
$request
)
{
return
MediaModel
::
getMediaInfoByNum
(
$request
);
return
MediaModel
::
getMediaInfoByNum
(
$request
);
...
@@ -300,13 +309,12 @@ class MediaController extends Controller
...
@@ -300,13 +309,12 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
getMediaForeverM3u8
(
Request
$request
)
{
public
function
getMediaForeverM3u8
(
Request
$request
)
{
$data
=
handler_drive
(
function
()
use
(
$request
)
{
$data
=
handler_drive
(
function
()
use
(
$request
)
{
return
MediaModel
::
getMediaForeverM3u8
(
$request
);
return
MediaModel
::
getMediaForeverM3u8
(
$request
);
});
});
return
success
(
$data
);
return
success
(
$data
);
}
}
/**
/**
...
@@ -314,10 +322,10 @@ class MediaController extends Controller
...
@@ -314,10 +322,10 @@ class MediaController extends Controller
* @return \Illuminate\Http\JsonResponse
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
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'
,
]);
]);
return
MediaModel
::
getMediaListByMediaIds
(
$request
);
return
MediaModel
::
getMediaListByMediaIds
(
$request
);
...
@@ -325,5 +333,50 @@ class MediaController extends Controller
...
@@ -325,5 +333,50 @@ class MediaController extends Controller
return
success
(
$data
);
return
success
(
$data
);
}
}
/**
* @param Request $request
* @return mixed
* @throws FormException
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\DatabaseException
*/
public
function
screenShotCallback
(
Request
$request
)
{
LogModel
::
addlog
([
"接受screen_shot_rollback信号"
=>
$request
->
all
()]);
$data
=
handler_drive
(
function
()
use
(
$request
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,
[
'media_id'
=>
'required'
,
'screenshot'
=>
''
,
'width'
=>
''
,
'height'
=>
''
,
'type'
=>
'required'
,
]);
return
MediaModel
::
UpdateScreenShotInfo
(
$request
);
});
return
success
(
$data
);
}
/**
* @throws FormException
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\DatabaseException
*/
public
function
runScreenShot
(
Request
$request
){
$data
=
handler_drive
(
function
()
use
(
$request
)
{
SrsHookValidate
::
srsHookCallback
(
$request
,[
'media_id'
=>
''
,
'start_time'
=>
'required|date'
,
'end_time'
=>
'required|date|after_or_equal:start_time'
,
],
null
,[
'start_time.date'
=>
'开始时间格式错误'
,
'start_time.required'
=>
'开始时间不能为空'
,
'end_time.required'
=>
'结束时间不能为空'
,
'end_time.date'
=>
'结束时间格式错误'
,
'end_time.after_or_equal'
=>
'结束时间不能小于开始时间'
]);
return
MediaModel
::
runScreenShotMedia
(
$request
);
});
return
success
(
$data
);
}
}
}
app/Model/MediaModel.php
View file @
ecb58233
...
@@ -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,26 +38,26 @@ class MediaModel extends Eloquent
...
@@ -39,26 +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
;
}
}
...
@@ -67,36 +66,36 @@ class MediaModel extends Eloquent
...
@@ -67,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
;
...
@@ -105,7 +104,7 @@ class MediaModel extends Eloquent
...
@@ -105,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
;
...
@@ -117,10 +116,10 @@ class MediaModel extends Eloquent
...
@@ -117,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
);
...
@@ -129,19 +128,19 @@ class MediaModel extends Eloquent
...
@@ -129,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'
,
]);
]);
...
@@ -149,7 +148,7 @@ class MediaModel extends Eloquent
...
@@ -149,7 +148,7 @@ class MediaModel extends Eloquent
});
});
}
catch
(
\Exception
$exception
)
{
}
catch
(
\Exception
$exception
)
{
throw
new
DatabaseException
(
$exception
->
getMessage
());
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
}
...
@@ -163,9 +162,10 @@ class MediaModel extends Eloquent
...
@@ -163,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是否存在
...
@@ -173,32 +173,32 @@ class MediaModel extends Eloquent
...
@@ -173,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
(
"媒资编号已被使用"
);
}
}
}
}
...
@@ -207,11 +207,11 @@ class MediaModel extends Eloquent
...
@@ -207,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
);
/**
/**
...
@@ -225,7 +225,7 @@ class MediaModel extends Eloquent
...
@@ -225,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
,
...
@@ -244,11 +244,11 @@ class MediaModel extends Eloquent
...
@@ -244,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
,
...
@@ -267,16 +267,17 @@ class MediaModel extends Eloquent
...
@@ -267,16 +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
);
LogModel
::
addlog
([
"添加媒资信息"
=>
$data
,[
'媒资ID为:=> '
.
$id
]]);
//处理封面图片以及分辨率
}
catch
(
\Exception
$exception
){
self
::
getScreeShotInfo
(
$media_id
);
LogModel
::
addlog
([
"添加媒资信息"
=>
$data
,
[
'媒资ID为:=> '
.
$id
]]);
}
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
);
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
'
)
->
find
(
$media_id
);
$media
=
MediaModel
::
select
(
'media_url'
,
'secret_key'
,
'duration'
,
'media_name'
,
'status'
,
'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,42 +644,42 @@ class MediaModel extends Eloquent
...
@@ -639,42 +644,42 @@ 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"
;
}
}
...
@@ -688,15 +693,15 @@ class MediaModel extends Eloquent
...
@@ -688,15 +693,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
;
...
@@ -709,24 +714,25 @@ class MediaModel extends Eloquent
...
@@ -709,24 +714,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
;
}
}
...
@@ -740,30 +746,30 @@ class MediaModel extends Eloquent
...
@@ -740,30 +746,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'
,
]);
]);
...
@@ -771,20 +777,19 @@ class MediaModel extends Eloquent
...
@@ -771,20 +777,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
);
}
}
...
@@ -794,7 +799,7 @@ class MediaModel extends Eloquent
...
@@ -794,7 +799,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
;
...
@@ -805,20 +810,21 @@ class MediaModel extends Eloquent
...
@@ -805,20 +810,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
;
...
@@ -830,37 +836,35 @@ class MediaModel extends Eloquent
...
@@ -830,37 +836,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
;
});
});
...
@@ -875,8 +879,8 @@ class MediaModel extends Eloquent
...
@@ -875,8 +879,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
;
...
@@ -884,21 +888,20 @@ class MediaModel extends Eloquent
...
@@ -884,21 +888,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
;
...
@@ -909,32 +912,30 @@ class MediaModel extends Eloquent
...
@@ -909,32 +912,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
;
...
@@ -948,37 +949,38 @@ class MediaModel extends Eloquent
...
@@ -948,37 +949,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
());
}
}
...
@@ -991,31 +993,32 @@ class MediaModel extends Eloquent
...
@@ -991,31 +993,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
());
}
}
}
}
...
@@ -1026,40 +1029,30 @@ class MediaModel extends Eloquent
...
@@ -1026,40 +1029,30 @@ 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
));
$item
[
'media_name'
]
=
$media
[
'media_name'
];
$item
[
'media_name'
]
=
$media
[
'media_name'
];
$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
;
}
}
}
}
return
$orginal_data
;
return
$orginal_data
;
}
}
...
@@ -1069,16 +1062,120 @@ class MediaModel extends Eloquent
...
@@ -1069,16 +1062,120 @@ 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
());
}
}
return
$medias
;
return
$medias
;
}
}
/**
* 获取媒资数据截屏图片
* @param $media_id
* @return mixed
* @throws DatabaseException
*/
private
static
function
getScreeShotInfo
(
$media_id
)
{
LogModel
::
addlog
([
"向第三方发送获取 screenshot 数据请求"
,
$media_id
]);
try
{
$media
=
MediaModel
::
select
(
"_id"
,
"media_name"
,
"duration"
,
"secret_key"
,
"media_url"
)
->
where
(
'_id'
,
$media_id
)
->
first
();
}
catch
(
\Exception
$exception
)
{
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
//获取媒资截图数据
//http://test-playback.offcncloud.com/api/v1/vodRecordInfo
$playbackUrl
=
getenv
(
'playback'
)
?
getenv
(
'playback'
)
:
'http://ofc-record-svc'
;
$params
=
array
(
"url"
=>
$media
[
"media_url"
],
"key"
=>
$media
[
"secret_key"
],
"media_id"
=>
$media_id
,
);
$data
=
json_encode
(
$params
);
$header
=
array
(
"Content-Type: application/json"
,
"Content-Length: "
.
strlen
(
$data
)
);
$url
=
$playbackUrl
.
"/api/v1/vodRecordInfo"
;
LogModel
::
addlog
([
"第三方获取媒资 screenshot 请求路径"
=>
$url
,
"请求参数"
=>
$data
,
"请求头"
=>
$header
]);
$res
=
http_request_code
(
$url
,
$header
,
'POST'
,
$data
);
LogModel
::
addlog
([
"第三方获取媒资 screenshot 数据"
=>
$res
,
"请求路径"
=>
$url
,
"请求参数"
=>
$data
,
"请求头"
=>
$header
]);
}
/**
* @param $request
* @return void
* @throws DatabaseException
*/
public
static
function
UpdateScreenShotInfo
(
$request
)
{
LogModel
::
addlog
([
"接收到更新 screenshot 数据回调 "
=>
$request
->
all
()]);
$media_id
=
$request
->
media_id
;
if
(
$request
->
type
!=
'video'
){
$data
[
"media_audio"
]
=
"audio"
;
//资源类型,audio音频文件,video视频文件
LogModel
::
addlog
([
"接收到更新 screenshot 数据回调 ,更新音频文件"
=>
$request
->
all
(),
"更新数据为"
=>
$data
]);
MediaModel
::
where
(
"_id"
,
$media_id
)
->
update
(
$data
);
return
;
}
try
{
MediaModel
::
select
(
"_id"
,
"media_name"
,
"duration"
,
"secret_key"
,
"media_url"
)
->
where
(
'_id'
,
$media_id
)
->
first
();
}
catch
(
\Exception
$exception
)
{
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
//资源类型,audio音频文件,video视频文件
$item
[
"media_audio"
]
=
"video"
;
$item
[
"screen_shot"
][
"height"
]
=
$request
->
height
;
$item
[
"screen_shot"
][
"width"
]
=
$request
->
width
;
$item
[
"screen_shot"
][
"url"
]
=
$request
->
screenshot
;
MediaModel
::
where
(
"_id"
,
$media_id
)
->
update
(
$item
);
LogModel
::
addlog
([
"更新媒资 screenshot 数据成功 "
=>
$item
]);
}
/**
* @param $request
* @return mixed
* @throws DatabaseException
*/
public
static
function
runScreenShotMedia
(
$request
)
{
try
{
$match
=
[
'status'
=>
"1"
,
"screen_shot"
=>
null
,
"media_audio"
=>
[
"
\$
ne"
=>
'audio'
]
];
if
(
isset
(
$request
->
media_id
)
&&
!
empty
(
$request
->
media_id
))
{
$match
[
'_id'
]
=
$request
->
media_id
;
}
if
(
isset
(
$request
->
start_time
)
&&
!
empty
(
$request
->
start_time
))
{
$start_time
=
new
UTCDateTime
(
strtotime
(
$request
->
start_time
)
*
1000
);
$match
[
'start_time'
]
=
[
'$gt'
=>
$start_time
];
}
if
(
isset
(
$request
->
end_time
)
&&
!
empty
(
$request
->
end_time
))
{
$end_time
=
new
UTCDateTime
(
strtotime
(
$request
->
end_time
)
*
1000
);;
$match
[
'end_time'
]
=
[
'$lt'
=>
$end_time
];
}
$media
=
MediaModel
::
where
(
$match
)
->
first
();
self
::
getScreeShotInfo
(
$media
[
"_id"
]);
}
catch
(
\Exception
$exception
)
{
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
return
$media
;
}
}
}
routes/api.php
View file @
ecb58233
...
@@ -53,5 +53,8 @@ Route::group(['namespace' => 'Api', 'prefix' => 'user','middleware' => ['api']],
...
@@ -53,5 +53,8 @@ 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
(
"screenShotCallback"
,
"MediaController@screenShotCallback"
);
#处理之前没有分辨率的旧数据
Route
::
post
(
"runScreenShot"
,
"MediaController@runScreenShot"
);
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment