|
@@ -0,0 +1,1273 @@
|
|
|
|
|
+<?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('未知操作');
|
|
|
|
|
+ }
|
|
|
|
|
+}
|