| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273 |
- <?php
- namespace Modules\ManageApi\Controllers;
- use App\Constants\CommonConstant;
- use App\Jobs\Video\AgentUpdateChildUidsByAllParentUidsJob;
- use App\Models\Mysql\VideoCategoryModel;
- use App\Models\Mysql\VideoModel;
- use App\Repositories\AppRepository;
- use App\Repositories\Criterias\OrderLimitCriteria;
- use App\Repositories\Criterias\VideoCategoryPagesCriteria;
- use App\Repositories\Criterias\VideoPagesCriteria;
- use App\Repositories\Criterias\VideoTagPagesCriteria;
- use App\Repositories\VideoCategoryRepository;
- use App\Repositories\VideoRepository;
- use App\Repositories\VideoTagRepository;
- use Illuminate\Support\Facades\Validator;
- use Modules\ManageApi\Responses\CommonAllResponse;
- use Modules\ManageApi\Responses\CommonDetailResponse;
- use Modules\ManageApi\Responses\CommonPagesResponse;
- use Modules\ManageApi\Responses\CommonSuccessPkResponse;
- use Modules\ManageApi\Responses\CommonSuccessUidResponse;
- use Modules\ManageApi\Responses\VideoCategoryDetailResponse;
- use Modules\ManageApi\Responses\VideoCategoryPagesResponse;
- use Modules\ManageApi\Responses\VideoDetailResponse;
- use Modules\ManageApi\Responses\VideoPagesResponse;
- use Modules\ManageApi\Services\VideoTagService;
- class VideoController extends BaseController
- {
- /**
- * 视频列表
- * @return \Illuminate\Http\JsonResponse|VideoPagesResponse
- */
- public function lists()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoRepository $videoRepo
- */
- $videoRepo = app(VideoRepository::class);
- $inputData = $this->getJsonData();
- // 针对layui table自动分页请求参数,优先GET值.
- $queryPage = request()->has('page') ? request()->input('page', 1) : null;
- $queryPageSize = request()->has('page_size') ? request()->input('page_size', 10) : null;
- if (!is_null($queryPage)) {
- $inputData['page'] = $queryPage;
- }
- if (!is_null($queryPageSize)) {
- $inputData['page_size'] = $queryPageSize;
- }
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- 'video_uid' => 'nullable',
- 'type' => 'nullable|integer',
- 'category_uid' => 'nullable',
- 'tags' => 'nullable',
- 'status' => 'nullable|integer',
- 'title' => 'nullable',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 0);
- // 注意,单例分页一定要克隆一个(保证前面没用使用到paginate);
- $items = $videoRepo->pushCriteria(new VideoPagesCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new VideoPagesResponse($items);
- }
- /**
- * 视频详情
- * @return \Illuminate\Http\JsonResponse|VideoDetailResponse
- */
- public function detail()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoRepository $videoRepo
- */
- $videoRepo = app(VideoRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'video_uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $video = $videoRepo->findBy('video_uid', $inputData['video_uid']);
- return new VideoDetailResponse($video);
- }
- /**
- * 修改视频
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function modify()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoRepository $videoRepo
- */
- $videoRepo = app(VideoRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'video_uid' => 'required|string',
- 'type' => 'required|integer',
- 'category_uid' => 'required|string',
- 'title' => 'required|max:255',
- 'cover' => 'nullable',
- 'duration' => 'nullable',
- 'bitrate' => 'nullable',
- 'resolution' => 'nullable|max:16',
- 'tags' => 'nullable|max:700',
- 'screenshots' => 'nullable|array',
- 'status' => 'nullable|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $video = $videoRepo->findBy('video_uid', $inputData['video_uid']);
- if (empty($video)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldVideo = clone $video;
- if (isset($inputData['type'])) {
- $type = intval($inputData['type']);
- $video->type = $type;
- }
- if (isset($inputData['category_uid'])) {
- $categoryUid = trim($inputData['category_uid']);
- $video->category_uid = $categoryUid;
- }
- if (isset($inputData['title'])) {
- $title = trim($inputData['title']);
- $video->title = $title;
- }
- if (isset($inputData['cover'])) {
- $cover = trim($inputData['cover']);
- if (!empty($cover)) {
- if (!stripos($cover, '|')) {
- return json_fail('封面必须包含服务器组滚符号');
- }
- }
- $video->cover = $cover;
- }
- if (isset($inputData['duration'])) {
- $duration = intval($inputData['duration']);
- $video->duration = $duration;
- }
- if (isset($inputData['bitrate'])) {
- $bitrate = intval($inputData['bitrate']);
- $video->bitrate = $bitrate;
- }
- if (isset($inputData['resolution'])) {
- $resolution = strtolower(trim($inputData['resolution']));
- $video->resolution = $resolution;
- }
- if (isset($inputData['tags'])) {
- if (is_array($inputData['tags'])) {
- $strTags = implode(',', $inputData['tags']);
- } else {
- $strTags = (string)$inputData['tags'];
- }
- $video->tags = $strTags;
- }
- if (isset($inputData['screenshots'])) {
- if (is_array($inputData['screenshots'])) {
- $strScreenshots = implode(',', $inputData['screenshots']);
- } else {
- $strScreenshots = $inputData['screenshots'];
- }
- $video->screenshots = $strScreenshots;
- }
- if (isset($inputData['queue_status'])) {
- $queue_status = intval($inputData['queue_status']);
- $video->queue_status = $queue_status;
- }
- if (isset($inputData['status'])) {
- $status = intval($inputData['status']);
- $video->status = $status;
- }
- $result = $video->save();
- if (!$result) {
- return json_fail('编辑失败');
- } else {
- $logSubject = '编辑一个视频, 标题:' . $video->title;
- $logSvalue = $video->video_uid;
- $logDbData = [
- 'after_items' => [
- $video->toArray(),
- ],
- 'before_items' => [
- $oldVideo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($video->video_uid);
- }
- }
- /**
- * 删除视频
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function delete()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoRepository $videoRepo
- */
- $videoRepo = app(VideoRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'video_uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $video = $videoRepo->findBy('video_uid', $inputData['video_uid']);
- if (empty($video)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldVideo = clone $video;
- $result = $video->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个视频,标题:' . $oldVideo->title;
- $logSvalue = $oldVideo->video_uid;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldVideo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($inputData['video_uid']);
- }
- }
- /**
- * 批量删除视频
- */
- public function batchDelete()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoRepository $videoRepo
- */
- $inputData = $this->getJsonData();
- $rules = [
- 'video_uids' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- // 要删除的UID
- $videoUids = explode(',', $inputData['video_uids']);
- $videoRepo = app(VideoRepository::class);
- $videoModel = clone $videoRepo;
- // 查询有UID的数据
- $videoKeys = $videoRepo->findArray('video_uid', $videoUids);
- if (empty($videoKeys)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- // 批量删除
- $result = $videoModel->delectUids('video_uid', $videoUids);
- $videoKeysStr = implode(',', $videoKeys);
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '批量删除视频:' . $videoKeysStr;
- $logSvalue = $videoKeysStr;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $videoKeysStr,
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($inputData['video_uids']);
- }
- }
- /**
- * 批量操作视频.
- * @return \Illuminate\Http\JsonResponse|mixed
- */
- public function batch()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoRepository $videoRepo
- */
- $videoRepo = app(VideoRepository::class);
- $inputData = $this->getJsonData();
- $operateName = $inputData['operate_name'] ?? '';
- switch ($operateName) {
- case 'delete':
- $itemPks = $inputData['item_pks'] ?? [];
- if (!empty($itemPks)) {
- $model = new VideoModel();
- $resultItems = $model->whereIn('video_uid', $itemPks)->delete();
- if ($resultItems) {
- $strPks = implode(',', $itemPks);
- $logSubject = '批量删除多个视频';
- $logSvalue = $strPks;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- }
- }
- $data = [
- 'result' => 'success',
- 'pks' => $itemPks,
- ];
- return json_success($data);
- break;
- default:
- break;
- }
- return json_fail('未知操作');
- }
- /**
- * 视频分类分页
- * @return \Illuminate\Http\JsonResponse|VideoCategoryPagesResponse
- */
- public function categoryLists()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $inputData = $this->getJsonData();
- // 针对layui table自动分页请求参数,优先GET值.
- $queryPage = request()->has('page') ? request()->input('page', 1) : null;
- $queryPageSize = request()->has('page_size') ? request()->input('page_size', 10) : null;
- if (!is_null($queryPage)) {
- $inputData['page'] = $queryPage;
- }
- if (!is_null($queryPageSize)) {
- $inputData['page_size'] = $queryPageSize;
- }
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- 'category_uid' => 'nullable',
- 'name' => 'nullable',
- 'status' => 'nullable|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 0);
- // 注意,单例分页一定要克隆一个(保证前面没用使用到paginate);
- $items = $categoryRepo->pushCriteria(new VideoCategoryPagesCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new VideoCategoryPagesResponse($items);
- }
- /**
- * 分类详情
- * @return \Illuminate\Http\JsonResponse|VideoCategoryDetailResponse
- */
- public function categoryDetail()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'category_uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $category = $categoryRepo->findBy('category_uid', $inputData['category_uid']);
- return new VideoCategoryDetailResponse($category);
- }
- /**
- * 创建分类
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function categoryCreate()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'name' => 'required|max:60',
- 'parent_uid' => 'nullable',
- 'squad' => 'nullable|integer',
- 'status' => 'nullable|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- if (!empty($inputData['parent_uid'])) {
- $parentUid = trim($inputData['parent_uid']);
- } else {
- $parentUid = '';
- }
- if (!isset($inputData['squad'])) {
- $squad = 1000;
- } else {
- $squad = intval($inputData['squad']);
- }
- if (!empty($inputData['status'])) {
- $status = intval($inputData['status']);
- } else {
- $status = 1;
- }
- $setarr = [
- 'name' => trim($inputData['name']),
- 'parent_uid' => $parentUid,
- 'squad' => $squad,
- 'status' => $status,
- ];
- $result = $categoryRepo->create($setarr);
- if (!$result) {
- return json_fail('创建失败');
- } else {
- $logSubject = '添加一个视频分类, 名称:' . $result->name;
- $logSvalue = $result->category_uid;
- $logDbData = [
- 'after_items' => [
- $result->toArray(),
- ],
- 'before_items' => [
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($result->category_uid);
- }
- }
- /**
- * 修改分类
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function categoryModify()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'category_uid' => 'required|string',
- 'name' => 'required|max:60',
- 'parent_uid' => 'nullable',
- 'squad' => 'nullable|integer',
- 'status' => 'nullable|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $category = $categoryRepo->findBy('category_uid', $inputData['category_uid']);
- if (empty($category)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldCategory = clone $category;
- if (isset($inputData['name'])) {
- $name = trim($inputData['name']);
- $category->name = $name;
- }
- if (isset($inputData['parent_uid'])) {
- $parentUid = trim($inputData['parent_uid']);
- $category->parent_uid = $parentUid;
- }
- if (isset($inputData['squad'])) {
- $squad = intval($inputData['squad']);
- $category->squad = $squad;
- }
- if (isset($inputData['status'])) {
- $status = intval($inputData['status']);
- $category->status = $status;
- }
- $result = $category->save();
- if (!$result) {
- return json_fail('编辑失败');
- } else {
- $logSubject = '编辑一个视频分类, 名称:' . $category->name;
- $logSvalue = $category->category_uid;
- $logDbData = [
- 'after_items' => [
- $category->toArray(),
- ],
- 'before_items' => [
- $oldCategory->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($category->category_uid);
- }
- }
- /**
- * 修改视频分类状态
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function categoryEditStatus()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- $inputData = $this->getJsonData();
- $rules = [
- 'category_uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $category = $categoryRepo->findBy('category_uid', $inputData['category_uid']);
- if (empty($category)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldCategory = clone $category;
- $category->status = $category->status === 1 ? 2 : 1;
- if (!$category->save()) {
- return json_fail('删除失败');
- } else {
- $logSubject = '修改视屏分类状态:' . $category->name;
- $logSvalue = $category->category_uid;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldCategory->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($inputData['category_uid']);
- }
- }
- /**
- * 删除分类
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function categoryDelete()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'category_uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $category = $categoryRepo->findBy('category_uid', $inputData['category_uid']);
- if (empty($category)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldCategory = clone $category;
- $result = $category->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个视频分类,名称:' . $oldCategory->username;
- $logSvalue = $oldCategory->category_uid;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldCategory->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($inputData['category_uid']);
- }
- }
- /**
- * 批量删除视频分类
- */
- public function categoryBatchDelete()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- $inputData = $this->getJsonData();
- $rules = [
- 'category_uids' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $categoryUidArray = explode(',', $inputData['category_uids']);
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $categoryModel = clone $categoryRepo;
- // 查询有UID的数据
- $categoryKeys = $categoryRepo->findArray('category_uid', $categoryUidArray);
- if (empty($categoryKeys)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- // 批量删除
- $result = $categoryModel->delectUids('category_uid', $categoryKeys);
- $categoryStr = implode(',', $categoryUidArray);
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '批量删除视频分类:' . $categoryStr;
- $logSvalue = $categoryStr;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $categoryKeys,
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($inputData['category_uids']);
- }
- }
- /**
- * 批量操作分类
- * @return \Illuminate\Http\JsonResponse|mixed
- */
- public function categoryBatch()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $inputData = $this->getJsonData();
- $operateName = $inputData['operate_name'] ?? '';
- switch ($operateName) {
- case 'delete':
- $itemPks = $inputData['item_pks'] ?? [];
- if (!empty($itemPks)) {
- $model = new VideoCategoryModel();
- $resultItems = $model->whereIn('category_uid', $itemPks)->delete();
- if ($resultItems) {
- $strPks = implode(',', $itemPks);
- $logSubject = '批量删除多个视频分类';
- $logSvalue = $strPks;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- }
- }
- $data = [
- 'result' => 'success',
- 'pks' => $itemPks,
- ];
- return json_success($data);
- break;
- default:
- break;
- }
- return json_fail('未知操作');
- }
- /**
- * 所有视频分类
- * @return \Illuminate\Http\JsonResponse|VideoCategoryPagesResponse
- */
- public function categoryAll()
- {
- /**
- * @var VideoCategoryRepository $categoryRepo
- */
- $categoryRepo = app(VideoCategoryRepository::class);
- $orders = [
- ['created_at', 'DESC'],
- ];
- // 注意,单例分页一定要克隆一个(保证前面没用使用到paginate);
- $items = $categoryRepo->pushCriteria(new OrderLimitCriteria($orders))->all();
- return new CommonAllResponse($items);
- }
- /**
- * 推送APP
- * @return \Illuminate\Http\JsonResponse|CommonSuccessUidResponse
- */
- public function pushApp()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- $inputData = $this->getJsonData();
- $rules = [
- 'app_uid' => 'required|string',
- 'video_uids' => 'required|array',
- 'addon_params' => 'nullable|max:700',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- /**
- * @var $appRepo AppRepository
- */
- $appRepo = make(AppRepository::class);
- $item = $appRepo->findBy('app_uid', $inputData['app_uid']);
- if ($item->count() == 0) {
- return json_fail('无效应用');
- }
- $pushParams = [
- 'app_uid' => $inputData['app_uid'],
- 'video_uids' => $inputData['video_uids'],
- 'addon_params' => $inputData['addon_params'] ?? '',
- ];
- dispatch(new AgentUpdateChildUidsByAllParentUidsJob($pushParams));
- $strVideoUids = is_array($inputData['video_uids']) ? implode(',', $inputData['video_uids']) : $inputData['video_uids'];
- $logSubject = '推送一些视频至应用名称:' . $item->name;
- $logSvalue = $strVideoUids;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessUidResponse($item->app_uid);
- }
- public function tagLists()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- /**
- * @var VideoTagService $tagService
- */
- $tagService = app(VideoTagService::class);
- $inputData = $this->getJsonData();
- // 针对layui table自动分页请求参数,优先GET值.
- $queryPage = request()->has('page') ? request()->input('page', 1) : null;
- $queryPageSize = request()->has('page_size') ? request()->input('page_size', 10) : null;
- if (!is_null($queryPage)) {
- $inputData['page'] = $queryPage;
- }
- if (!is_null($queryPageSize)) {
- $inputData['page_size'] = $queryPageSize;
- }
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- 'name' => 'nullable',
- 'origin' => 'nullable',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 0);
- // 注意,单例分页一定要克隆一个(保证前面没用使用到paginate);
- $items = $tagRepo->pushCriteria(new VideoTagPagesCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new CommonPagesResponse($items);
- }
- public function tagCreate()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- /**
- * @var VideoTagService $tagService
- */
- $tagService = app(VideoTagService::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'tags' => 'required',
- 'origin' => 'nullable',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- if (!empty($inputData['origin'])) {
- $origin = trim($inputData['origin']);
- } else {
- $origin = '';
- }
- $result = $tagService->batchCreate($inputData['tags'], $origin);
- if (empty($result['names'])) {
- return json_fail('创建失败');
- } else {
- $strNames = implode(',', $result['names']);
- $strIds = implode(',', $result['ids']);
- $logSubject = '添加视频标签, 名称:' . mb_substr($strNames, 0, 255);
- $logSvalue = $strIds;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- $data = [
- 'result' => 'success',
- 'pks' => $result['ids'],
- ];
- return json_success($data);
- }
- }
- public function tagDetail()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'id' => 'required',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $tag = $tagRepo->findBy('id', $inputData['id']);
- return new CommonDetailResponse($tag);
- }
- public function tagModify()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- /**
- * @var VideoTagService $tagService
- */
- $tagService = app(VideoTagService::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'id' => 'required',
- 'name' => 'required',
- 'origin' => 'nullable',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $name = trim(urldecode($inputData['name']));
- $tag = $tagRepo->findBy('id', $inputData['id']);
- if (empty($tag)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldTag = clone $tag;
- if (isset($inputData['origin'])) {
- if (!empty($inputData['origin'])) {
- $origin = trim($inputData['origin']);
- } else {
- $origin = '';
- }
- $tag->origin = $origin;
- }
- if (!$tagService->isExists($name, $tag->id)) {
- $tag->name = $name;
- $result = $tag->save();
- } else {
- $result = false;
- }
- if (!$result) {
- return json_fail('创建失败');
- } else {
- $logSubject = '编辑视频标签, 名称:' . $name;
- $logSvalue = $inputData['id'];
- $logDbData = [
- 'after_items' => [
- $tag->toArray(),
- ],
- 'before_items' => [
- $oldTag->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessPkResponse($tag->id);
- }
- }
- public function tagDelete()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- /**
- * @var VideoTagService $tagService
- */
- $tagService = app(VideoTagService::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'id' => 'required',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $tag = $tagRepo->findBy('id', $inputData['id']);
- if (empty($tag)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $oldTag = clone $tag;
- $result = $tag->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个视频标签,名称:' . $oldTag->name;
- $logSvalue = $oldTag->id;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldTag->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessPkResponse($inputData['id']);
- }
- }
- /**
- * 批量删除标签
- * @return \Illuminate\Http\JsonResponse|CommonSuccessPkResponse
- */
- public function tagBatchDelete()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- /**
- * @var VideoTagService $tagService
- */
- $tagService = app(VideoTagService::class);
- $inputData = $this->getJsonData();
- $rules = [
- 'tagIds' => 'required',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $tagModel = clone $tagRepo;
- $tahIdsArray = explode(',', $inputData['tagIds']);
- $tagIds = $tagRepo->findArray('id', $tahIdsArray);
- if (empty($tagIds)) {
- return json_fail(trans('common.err_resource_not_found'));
- }
- $tagIdsStr = implode(',', $tagIds);
- if (!$tagModel->delectUids('id', $tagIds)) {
- return json_fail('删除失败');
- } else {
- $logSubject = '批量删除视频标签 id:' . $tagIdsStr;
- $logSvalue = $tagIdsStr;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $tagIds,
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new CommonSuccessPkResponse($inputData['tagIds']);
- }
- }
- public function tagBatch()
- {
- /**
- * @var Validator $validatorFactory
- */
- $validatorFactory = app('validator');
- /**
- * @var VideoTagRepository $tagRepo
- */
- $tagRepo = app(VideoTagRepository::class);
- /**
- * @var VideoTagService $tagService
- */
- $tagService = app(VideoTagService::class);
- $inputData = $this->getJsonData();
- $operateName = $inputData['operate_name'] ?? '';
- switch ($operateName) {
- case 'delete':
- $itemPks = $inputData['item_pks'] ?? [];
- if (!empty($itemPks)) {
- $model = new VideoModel();
- $resultItems = $model->whereIn('id', $itemPks)->delete();
- if ($resultItems) {
- $strPks = implode(',', $itemPks);
- $logSubject = '批量删除多个视频标签';
- $logSvalue = $strPks;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- }
- }
- $data = [
- 'result' => 'success',
- 'pks' => $itemPks,
- ];
- return json_success($data);
- break;
- default:
- break;
- }
- return json_fail('未知操作');
- }
- }
|