258 lines
9.5 KiB
PHP
258 lines
9.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Server\Admin;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Services\MediaLibraryService;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
|
||
|
|
class MediaLibraryController extends Controller
|
||
|
|
{
|
||
|
|
private $mediaLibraryService;
|
||
|
|
private $accountId;
|
||
|
|
private $groupName;
|
||
|
|
private $mediaType;
|
||
|
|
private $groupId;
|
||
|
|
private $page;
|
||
|
|
|
||
|
|
public function __construct(Request $request)
|
||
|
|
{
|
||
|
|
$this->mediaLibraryService = new MediaLibraryService();
|
||
|
|
$this->groupName = $request->input("group_name");
|
||
|
|
$this->groupId = $request->input("group_id");
|
||
|
|
$this->mediaType = $request->input("media_type");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function createGroup(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
if (!$this->groupName || !$this->mediaType || !$this->accountId) {
|
||
|
|
return $this->failure("参数不全");
|
||
|
|
}
|
||
|
|
$this->mediaLibraryService->createGroup($this->accountId, $this->groupName, $this->mediaType);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function renameGroup(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
if (!$this->groupName || !$this->mediaType || !$this->accountId) {
|
||
|
|
$this->failure("参数不全");
|
||
|
|
}
|
||
|
|
$this->mediaLibraryService->renameGroup($this->accountId, $this->groupName, $this->mediaType, $this->groupId);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function deleteGroup(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$this->mediaLibraryService->deleteGroup($this->accountId, $this->mediaType, $this->groupId);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function queryGroupList(Request $request)
|
||
|
|
{
|
||
|
|
$data = null;
|
||
|
|
try {
|
||
|
|
$keyword = $request->input('keyword');
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$data = $this->mediaLibraryService->queryGroupList($this->accountId, $this->mediaType, $this->groupId, $keyword);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功", $data);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function moveToGroup(Request $request)
|
||
|
|
{
|
||
|
|
$fileList = $request->input('file_list');
|
||
|
|
$old_group_id = (int)$request->input('old_group_id');
|
||
|
|
$new_group_id = (int)$request->input('new_group_id');
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
if (!$new_group_id || !$this->mediaType || !$this->accountId) {
|
||
|
|
return $this->failure("参数不全");
|
||
|
|
}
|
||
|
|
if ($fileList) {
|
||
|
|
$fileList = explode(",", $fileList);
|
||
|
|
//检查是不是数字
|
||
|
|
foreach ($fileList as $key => $val) {
|
||
|
|
$fileList[$key] = (int)$val;
|
||
|
|
if (!$fileList[$key]) {
|
||
|
|
unset($fileList[$key]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((!$old_group_id && !$fileList)) {
|
||
|
|
return $this->failure("旧分组ID或文件列表两个参数必须有其中一个");
|
||
|
|
}
|
||
|
|
$this->mediaLibraryService->moveToGroup($this->accountId, $this->mediaType, $old_group_id, $new_group_id, $fileList);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function queryFile(Request $request)
|
||
|
|
{
|
||
|
|
$start_time = $request->input("start_time");
|
||
|
|
$end_time = $request->input("end_time");
|
||
|
|
$keyword = $request->input("keyword");
|
||
|
|
$this->page = $request->input("page");
|
||
|
|
$order_by_created_time = $request->input("order_by_created_time");
|
||
|
|
$data = null;
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$data = $this->mediaLibraryService->queryFile($this->accountId, $this->mediaType, $this->groupId, $this->page, $start_time, $end_time, $keyword, $order_by_created_time);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
$this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功", $data);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function deleteFile(Request $request)
|
||
|
|
{
|
||
|
|
$file_list = $request->input("file_list");
|
||
|
|
if (!$file_list || !$this->groupId || !$this->mediaType) {
|
||
|
|
return $this->failure("参数不全");
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$fileList = explode(",", $file_list);
|
||
|
|
//检查是不是数字
|
||
|
|
foreach ($fileList as $key => $val) {
|
||
|
|
$fileList[$key] = (int)$val;
|
||
|
|
}
|
||
|
|
$this->mediaLibraryService->deleteFile($this->accountId, $this->mediaType, $fileList);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
return $this->success("操作成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
public function merchantGetVideoUrl(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$video_id = $request->input('aliyun_video_id');
|
||
|
|
$group_id = $request->input('group_id');
|
||
|
|
$media_name = $request->input('media_name');
|
||
|
|
if (!$video_id || !$group_id || !$media_name || !$this->accountId) {
|
||
|
|
return $this->failure('缺少参数');
|
||
|
|
}
|
||
|
|
$data = $this->mediaLibraryService->merchantGetVideoUrl($this->accountId, $video_id, $group_id, $media_name);
|
||
|
|
return $this->success("操作成功", $data);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
//$this->getError($e);
|
||
|
|
if ($e->getCode() == 403) {
|
||
|
|
return $this->jsonResponse(0, "视频审核中,请稍后重试");
|
||
|
|
} else {
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function saveMediaInfo(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$video_id = $request->input('aliyun_video_id');
|
||
|
|
$group_id = $request->input('group_id');
|
||
|
|
$media_name = $request->input('media_name');
|
||
|
|
$play_url = $request->input('play_url');
|
||
|
|
$media_type = $request->input('media_type'); //相信前端传的类型,没有做判断
|
||
|
|
if (!$group_id || !$media_name || !$this->accountId || !$play_url || !$media_type) {
|
||
|
|
return $this->failure('缺少参数');
|
||
|
|
}
|
||
|
|
if($media_type == 3){
|
||
|
|
if(!$video_id){
|
||
|
|
return $this->failure('媒体类型为视频时,video_id为必须参数');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$this->mediaLibraryService->saveMediaInfo($this->accountId, $video_id, $group_id, $media_name, $play_url, $media_type);
|
||
|
|
return $this->success("操作成功");
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function modifyMediaFileInfo(Request $request)
|
||
|
|
{
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$file_id = $request->input('file_id');
|
||
|
|
$media_name = $request->input('media_name');
|
||
|
|
try {
|
||
|
|
$this->mediaLibraryService->modifyMediaFileInfo($this->accountId, $file_id, $media_name);
|
||
|
|
return $this->success("操作成功");
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 移动到新分组
|
||
|
|
* @param Request $request
|
||
|
|
* @return \Illuminate\Http\JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function moveToNewGroup(Request $request)
|
||
|
|
{
|
||
|
|
$file_id = $request->input('file_id');
|
||
|
|
$group_name = $request->input('group_name');
|
||
|
|
$media_type = $request->input('media_type');
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
if (!$group_name || !$this->accountId || !$media_type || !$file_id) {
|
||
|
|
return $this->failure('缺少参数');
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
$this->mediaLibraryService->moveToNewGroup($this->accountId, $file_id, $group_name, $media_type);
|
||
|
|
return $this->success("操作成功");
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 添加到新分组
|
||
|
|
* @param Request $request
|
||
|
|
* @return \Illuminate\Http\JsonResponse|string
|
||
|
|
*/
|
||
|
|
public function addToNewGroup(Request $request)
|
||
|
|
{
|
||
|
|
$this->accountId = (int)$request->account_id;
|
||
|
|
$file_id = $request->input('file_id');
|
||
|
|
$group_name = $request->input('group_name');
|
||
|
|
$media_type = $request->input('media_type');
|
||
|
|
if (!$group_name || !$this->accountId || !$media_type || !$file_id) {
|
||
|
|
return $this->failure('缺少参数');
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
$this->mediaLibraryService->addToNewGroup($this->accountId, $file_id, $group_name, $media_type);
|
||
|
|
return $this->success("操作成功");
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
return $this->failure($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|