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
7ad565b4
Commit
7ad565b4
authored
Apr 06, 2021
by
杨昕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
a4f9f03f
Pipeline
#14113
passed with stages
in 2 minutes 2 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
193 additions
and
19 deletions
+193
-19
MediasExport.php
app/Exports/MediasExport.php
+3
-1
MediaController.php
app/Http/Controllers/Web/MediaController.php
+51
-7
MediaRoute.php
app/Http/Routes/Web/MediaRoute.php
+2
-0
DownloadRecord.php
app/Model/DownloadRecord.php
+80
-0
MediaModel.php
app/Model/MediaModel.php
+11
-5
batch_media.blade.php
resources/views/admin/media/batch_media.blade.php
+46
-6
No files found.
app/Exports/MediasExport.php
View file @
7ad565b4
...
@@ -25,6 +25,7 @@ class MediasExport implements WithHeadings,FromArray,WithColumnWidths
...
@@ -25,6 +25,7 @@ class MediasExport implements WithHeadings,FromArray,WithColumnWidths
'B'
=>
55
,
'B'
=>
55
,
'C'
=>
45
,
'C'
=>
45
,
'D'
=>
45
,
'D'
=>
45
,
'E'
=>
55
];
];
}
}
...
@@ -37,8 +38,9 @@ class MediasExport implements WithHeadings,FromArray,WithColumnWidths
...
@@ -37,8 +38,9 @@ class MediasExport implements WithHeadings,FromArray,WithColumnWidths
return
[
return
[
'媒资编号'
,
'媒资编号'
,
'视频名称'
,
'视频名称'
,
"名称"
,
"永久播放地址"
,
"永久播放地址"
,
"全屏预览地址"
"全屏预览地址"
,
];
];
}
}
...
...
app/Http/Controllers/Web/MediaController.php
View file @
7ad565b4
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Web;
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Web;
use
App\Exports\MediasExport
;
use
App\Exports\MediasExport
;
use
App\Exports\MubanExport
;
use
App\Exports\MubanExport
;
use
App\Imports\MediasImport
;
use
App\Imports\MediasImport
;
use
App\Model\DownloadRecord
;
use
App\Model\MediaCategoryModel
;
use
App\Model\MediaCategoryModel
;
use
App\Model\MediaModel
;
use
App\Model\MediaModel
;
use
App\Tool\SrsHookValidate
;
use
App\Tool\SrsHookValidate
;
...
@@ -275,7 +276,7 @@ class MediaController extends Controller
...
@@ -275,7 +276,7 @@ class MediaController extends Controller
* @throws \App\Exceptions\ControllerException
* @throws \App\Exceptions\ControllerException
*/
*/
public
function
import_batch_media
(
Request
$request
){
public
function
import_batch_media
(
Request
$request
){
$type
=
$request
->
type
??
'media'
;
//
$type = $request->type??'media';
$data
=
handler_drive
(
function
()
use
(
$request
){
$data
=
handler_drive
(
function
()
use
(
$request
){
...
@@ -284,24 +285,67 @@ class MediaController extends Controller
...
@@ -284,24 +285,67 @@ class MediaController extends Controller
#将文件内容转化为数组
#将文件内容转化为数组
$sheet
=
(
new
MediasImport
())
->
toArray
(
$file
);
$sheet
=
(
new
MediasImport
())
->
toArray
(
$file
);
$temp
=
[];
foreach
(
$sheet
[
0
]
as
$key
=>
$item
){
if
(
!
isset
(
$item
[
"媒资编号"
])
||
!
isset
(
$item
[
"名称"
])){
throw
new
\Exception
(
"文件格式有误"
);
}
$media_ids
=
collect
(
$sheet
[
0
])
->
map
(
function
(
$item
,
$key
){
$temp
[
$item
[
'媒资编号'
]]
=
[
return
array_first
(
$item
);
'media_id'
=>
$item
[
"媒资编号"
],
})
->
toArray
();
'name'
=>
$item
[
'名称'
]
];
}
$data
=
[];
$data
=
[];
if
(
!
empty
(
$sheet
[
0
])){
if
(
!
empty
(
$sheet
[
0
])){
#批量获取永久播放链接地址
#批量获取永久播放链接地址
$mediaInfos
=
MediaModel
::
batchGetMediaForverM3u8
(
$request
,
$media_ids
);
$mediaInfos
=
MediaModel
::
batchGetMediaForverM3u8
(
$request
,
$temp
);
$data
=
new
MediasExport
(
array_values
(
$mediaInfos
));
$data
=
new
MediasExport
(
array_values
(
$mediaInfos
));
}
}
return
$data
;
$record
=
md5
(
json_encode
(
$data
));
DownloadRecord
::
addRecord
(
$record
,
$data
);
return
$record
;
});
});
return
Excel
::
download
(
$data
,
$type
.
'.xlsx'
);
return
success
(
$data
);
}
/**
* @param Request $request
* @param $keyId
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
* @throws \App\Exceptions\ControllerException
*/
public
function
download
(
Request
$request
,
$keyId
){
$data
=
handler_drive
(
function
()
use
(
$keyId
){
$record
=
DownloadRecord
::
getRecord
(
$keyId
);
if
(
empty
(
$record
)){
throw
new
\Exception
(
"数据不存在"
);
}
$content
=
json_decode
(
$record
[
'content'
],
true
);
DownloadRecord
::
delRecord
(
$keyId
);
return
new
MediasExport
(
$content
);
});
return
Excel
::
download
(
$data
,
'media.xlsx'
);
}
}
}
}
app/Http/Routes/Web/MediaRoute.php
View file @
7ad565b4
...
@@ -29,6 +29,8 @@ class MediaRoute extends AuthenRoute
...
@@ -29,6 +29,8 @@ class MediaRoute extends AuthenRoute
$router
->
get
(
'media_manager/export_batch_media'
,
'MediaController@export_batch_media'
);
$router
->
get
(
'media_manager/export_batch_media'
,
'MediaController@export_batch_media'
);
$router
->
get
(
"/media_manager/download/
{
keyId
}
"
,
'MediaController@download'
);
});
});
...
...
app/Model/DownloadRecord.php
0 → 100644
View file @
7ad565b4
<?php
namespace
App\Model
;
use
App\Exceptions\DatabaseException
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
MongoDB\BSON\UTCDateTime
;
class
DownloadRecord
extends
Eloquent
{
protected
$collection
=
"download_record"
;
protected
$connection
=
'mongodb'
;
//使用mongodb
protected
$primaryKey
=
'_id'
;
/**
* @param $keyId
* @param $data
* @return mixed
* @throws DatabaseException
*/
public
static
function
addRecord
(
$keyId
,
$data
){
try
{
$record
=
self
::
getRecord
(
$keyId
);
if
(
empty
(
$record
)){
$create_time
=
new
UTCDateTime
(
time
()
*
1000
);;
$data
=
[
'key_id'
=>
$keyId
,
'content'
=>
json_encode
(
$data
),
'create_time'
=>
$create_time
,
];
$id
=
DownloadRecord
::
insertGetId
(
$data
);
}
else
{
$id
=
$record
[
'id'
];
}
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
return
$id
;
}
/**
* @param $keyId
* @return mixed
* @throws DatabaseException
*/
public
static
function
getRecord
(
$keyId
){
try
{
$record
=
DownloadRecord
::
where
(
"key_id"
,
$keyId
)
->
first
();
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
return
$record
;
}
/**
* 删除记录
* @param $keyId
* @return mixed
* @throws DatabaseException
*/
public
static
function
delRecord
(
$keyId
){
try
{
$flag
=
DownloadRecord
::
where
(
"key_id"
,
$keyId
)
->
delete
();
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
return
$flag
;
}
}
app/Model/MediaModel.php
View file @
7ad565b4
...
@@ -1009,13 +1009,14 @@ class MediaModel extends Eloquent
...
@@ -1009,13 +1009,14 @@ class MediaModel extends Eloquent
* @return array
* @return array
* @throws DatabaseException
* @throws DatabaseException
*/
*/
public
static
function
batchGetMediaForverM3u8
(
$request
,
array
$
media_ids
){
public
static
function
batchGetMediaForverM3u8
(
$request
,
array
$
orginal_data
){
try
{
try
{
$ids
=
implode
(
','
,
$media_ids
);
$ids
=
implode
(
','
,
array_keys
(
$orginal_data
));
#生成批量处理地址
#生成批量处理地址
$url
=
getRbac
(
$request
,
'video/infos'
,
$ids
,
$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
));
...
@@ -1030,7 +1031,7 @@ class MediaModel extends Eloquent
...
@@ -1030,7 +1031,7 @@ class MediaModel extends Eloquent
throw
new
\Exception
(
"获取数据失败"
);
throw
new
\Exception
(
"获取数据失败"
);
}
}
return
self
::
mediaExportFormat
(
$result
[
'data'
],
$
media_ids
);
return
self
::
mediaExportFormat
(
$result
[
'data'
],
$
orginal_data
);
}
catch
(
\Exception
$exception
){
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
$exception
->
getMessage
());
throw
new
DatabaseException
(
$exception
->
getMessage
());
...
@@ -1043,7 +1044,8 @@ class MediaModel extends Eloquent
...
@@ -1043,7 +1044,8 @@ class MediaModel extends Eloquent
* @param $media_ids
* @param $media_ids
* @return mixed
* @return mixed
*/
*/
private
static
function
mediaExportFormat
(
array
$data
){
private
static
function
mediaExportFormat
(
array
$data
,
$orginal_data
){
foreach
(
$data
as
$key
=>
&
$item
){
foreach
(
$data
as
$key
=>
&
$item
){
...
@@ -1054,6 +1056,7 @@ class MediaModel extends Eloquent
...
@@ -1054,6 +1056,7 @@ class MediaModel extends Eloquent
$item
[
'media_name'
]
=
'未查到相关数据'
;
$item
[
'media_name'
]
=
'未查到相关数据'
;
$item
[
'forvery_url'
]
=
'未查到相关数据'
;
$item
[
'forvery_url'
]
=
'未查到相关数据'
;
$item
[
'is_full_url'
]
=
"未查到相关数据"
;
$item
[
'is_full_url'
]
=
"未查到相关数据"
;
$item
[
'name'
]
=
"未查到相关数据"
;
}
else
{
}
else
{
...
@@ -1064,6 +1067,8 @@ class MediaModel extends Eloquent
...
@@ -1064,6 +1067,8 @@ class MediaModel extends Eloquent
$item
[
'_id'
]
=
$item
[
'id'
];
$item
[
'_id'
]
=
$item
[
'id'
];
$item
[
'media_name'
]
=
$media
[
'media_name'
];
$item
[
'media_name'
]
=
$media
[
'media_name'
];
$item
[
'name'
]
=
$orginal_data
[
$item
[
'_id'
]][
'name'
];
$tmp
=
[
$tmp
=
[
'media_num'
=>
$media_num
,
'media_num'
=>
$media_num
,
...
@@ -1073,6 +1078,7 @@ class MediaModel extends Eloquent
...
@@ -1073,6 +1078,7 @@ class MediaModel extends Eloquent
$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'
]
=
$item
[
'url'
];
$item
[
'forvery_url'
]
=
$item
[
'url'
];
$item
[
'is_full_url'
]
=
$url
.
"player"
.
'/'
.
$media_num
;
$item
[
'is_full_url'
]
=
$url
.
"player"
.
'/'
.
$media_num
;
$item
[
'name'
]
=
$orginal_data
[
$media_id
][
'name'
];
unset
(
$item
[
'id'
]);
unset
(
$item
[
'id'
]);
unset
(
$item
[
'key'
]);
unset
(
$item
[
'key'
]);
unset
(
$item
[
'status'
]);
unset
(
$item
[
'status'
]);
...
...
resources/views/admin/media/batch_media.blade.php
View file @
7ad565b4
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
<!--***** CONTENT *****-->
<!--***** CONTENT *****-->
<div
class=
"row ml20 batch-list"
>
<div
class=
"row ml20 batch-list"
>
<form
action=
"{{ asset('/web/media_manager/import_batch_media') }}"
method=
"post"
enctype=
"multipart/form-data"
>
<form>
{{ method_field('POST')}}
{{ method_field('POST')}}
<input
type=
"hidden"
name=
"_token"
value=
"{{csrf_token()}}"
/>
<input
type=
"hidden"
name=
"_token"
value=
"{{csrf_token()}}"
/>
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<input
type=
"file"
class=
"btn btn-info"
id=
"uploadFile"
name=
"uploadFile"
accept=
".xls,.xlsx"
>
<input
type=
"file"
class=
"btn btn-info"
id=
"uploadFile"
name=
"uploadFile"
accept=
".xls,.xlsx"
>
</div>
</div>
<button
class=
"btn btn-info batch-media"
type=
"
submit
"
id=
"batch-media"
disabled
onclick=
"test()"
>
导出
</button>
<button
class=
"btn btn-info batch-media"
type=
"
button
"
id=
"batch-media"
disabled
onclick=
"test()"
>
导出
</button>
</form>
</form>
...
@@ -112,16 +112,56 @@
...
@@ -112,16 +112,56 @@
*/
*/
function
test
()
{
function
test
()
{
var
formData
=
new
FormData
();
formData
.
append
(
"uploadFile"
,
$
(
"#uploadFile"
)[
0
].
files
[
0
]);
$
.
ajax
({
url
:
'/web/media_manager/import_batch_media'
,
/*接口域名地址*/
type
:
'post'
,
data
:
formData
,
processData
:
false
,
contentType
:
false
,
success
:
function
(
res
){
if
(
res
.
code
===
200
){
$
(
'body'
).
toast
({
$
(
'body'
).
toast
({
position
:
'fixed'
,
position
:
'fixed'
,
content
:
'导入成功,数据处理中......'
,
content
:
'导入成功,数据处理中......'
,
duration
:
3000
,
duration
:
3000
,
top
:
'50%'
top
:
'50%'
});
});
setTimeout
(
function
()
{
$
(
"#batch-media"
).
attr
(
"disabled"
,
true
);
window
.
location
.
href
=
"/web/media_manager/download/"
+
res
.
data
$
(
"#uploadFile"
).
val
(
""
)
},
2000
)
}
else
{
$
(
'body'
).
toast
({
position
:
'fixed'
,
content
:
res
.
msg
,
duration
:
3000
,
top
:
'50%'
});
}
}
})
// $('body').toast({
// position: 'fixed',
// content: '导入成功,数据处理中......',
// duration: 3000,
// top: '50%'
// });
// setTimeout(function () {
// $("#batch-media").attr("disabled",true);
// $("#uploadFile").val("")
// }, 2000)
}
}
</script>
</script>
...
...
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