You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Controllers\Manager;
use App\Models\Training;
class TrainingController extends CommonController
{
/**
* @OA\Get(
* path="/manager/get-videos",
* tags={"管理端视频展示"},
* summary="V2-获取视频列表",
* description="获取视频列表",
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="查询关键词"),
* @OA\Parameter(name="page", in="query", @OA\Schema(type="integer"), required=false, description="当前页码默认为1"),
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="integer"), required=false, description="每页数量默认为3"),
* @OA\Response(
* response="200",
* description="获取视频列表"
* )
* )
*/
public function index()
{
$data = (new Training());
if (request()->keyword) {
$keyword = request()->keyword;
$data = $data->where(function ($query) use ($keyword) {
$query
->where("title", "like", "%{$keyword}%")
->orWhereHas("type", function ($query) use ($keyword) {
$query->where("name", "like", "%{$keyword}%");
});
});
}
$page_size = request()->page_size ? (int)request()->page_size : 3;
//todo:配置视频开启用户
if (in_array($this->manager->username, ["liuyu","wujin","jiangwei"])) {
$data = $data->with(["type" => function ($query) {
$query->select("id", "name");
}])->select("id", "type_id", "title", "poster", "video", "published_at")->orderBy("published_at","desc")->paginate($page_size);
} else {
$data = $data->with(["type" => function ($query) {
$query->select("id", "name");
}])->select("id", "type_id", "title", "poster", "video as video_stopped", "published_at")->orderBy("published_at","desc")->paginate($page_size);
}
return response()->json($data->toArray());
}
/**
* @OA\Get(
* path="/manager/get-video/{id}",
* tags={"管理端视频展示"},
* summary="V2-获取单条视频数据",
* description="获取单条视频数据",
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="视频内容ID"),
* @OA\Response(
* response="200",
* description="获取单条视频数据"
* )
* )
*/
public function getVideo($id)
{
//todo:配置视频开启用户
if ($this->manager->username == "liuyu") {
$video = Training::with(["type" => function ($query) {
$query->select("id", "name");
}])->select("id", "type_id", "title", "poster", "video as video", "published_at")->find($id);
} else {
$video = Training::with(["type" => function ($query) {
$query->select("id", "name");
}])->select("id", "type_id", "title", "poster", "video as video_stopped", "published_at")->find($id);
}
return response()->json($video->toArray());
}
}