Browse Source

视频库基本管理

liuzejian 2 năm trước cách đây
mục cha
commit
e7f632da80

+ 1 - 1
modules/Channel/Http/Controllers/AdvertiserController.php

@@ -36,7 +36,7 @@ class AdvertiserController extends CatchController
             'miniProgramIds.*' => 'required|integer'
         ]);
         $this->user->emailUnique($request->input('email'));
-        $request['roles'] = [(DB::table('roles')->where('identify', 'Investmenter')->value('id') ?? 0)];
+        $request['roles'] = [(DB::table('roles')->where('identify', 'optimizer')->value('id') ?? 0)];
         $this->user->storeBy($request->all());
         $this->user->pid = $this->getLoginUserId();
         $this->user->save();

+ 2 - 0
modules/Common/Errors/Errors.php

@@ -6,4 +6,6 @@ class Errors
 {
     public const  EMAIL_EXISTS= [500001, '邮箱已经被使用'];
     public const  USER_NOT_FOUND= [500002, '用户不存在'];
+    public const  NO_OPERATE_PERMISSION= [500003, '用户无操作权限'];
+    public const  VIDEO_NOT_EXISTS= [500004, '视频不存在'];
 }

+ 17 - 0
modules/Common/Exceptions/CommonBusinessException.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Modules\Common\Exceptions;
+
+use Throwable;
+
+class CommonBusinessException extends \RuntimeException
+{
+    public function __construct($message = "", $code = 0, Throwable $previous = null)
+    {
+        parent::__construct($message, $code, $previous);
+    }
+
+    public static function throwError($error, Throwable $previous = null) {
+        throw (new static($error[1], $error[0], $previous));
+    }
+}

+ 17 - 0
modules/Video/Exceptions/ContentBusinessException.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Modules\ContentManage\Exceptions;
+
+use Throwable;
+
+class ContentBusinessException extends \RuntimeException
+{
+    public function __construct($message = "", $code = 0, Throwable $previous = null)
+    {
+        parent::__construct($message, $code, $previous);
+    }
+
+    public static function throwError($error, Throwable $previous = null) {
+        throw (new static($error[1], $error[0], $previous));
+    }
+}

+ 20 - 0
modules/Video/Exceptions/ContentManageForbidden.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Modules\ContentManage\Exceptions;
+
+use Catch\Enums\Code;
+use Catch\Exceptions\CatchException;
+use Symfony\Component\HttpFoundation\Response;
+
+class ContentManageForbidden extends CatchException
+{
+    protected $message = 'permission forbidden';
+
+    protected $code = Code::PERMISSION_FORBIDDEN;
+
+
+    public function statusCode(): int
+    {
+        return Response::HTTP_FORBIDDEN;
+    }
+}

+ 9 - 0
modules/Video/Exceptions/Errors.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Modules\ContentManage\Exceptions;
+
+class Errors
+{
+    public const REQUEST_HTTP_STATUS_ERROR = [500001, '请求上游接口返回http状态码有误'];
+    public const REQUEST_CODE_STATUS_ERROR = [500002, '请求上游接口返回code状态码有误'];
+}

+ 58 - 0
modules/Video/Http/Controllers/UserTrait.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace Modules\Video\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
+use Modules\User\Models\User;
+
+trait UserTrait
+{
+    // 当前登录用户
+    protected $currentUser;
+
+
+    /**
+     * 获取当前登录用户
+     * @return User
+     */
+    protected function getCurrentUser(): User {
+        if(!$this->currentUser) {
+            $this->currentUser = $this->getLoginUser();
+        }
+        return $this->currentUser;
+    }
+    /**
+     * 当前用户的所有的角色标识的结合
+     * @return Collection
+     */
+    protected function listUserRoles():Collection {
+        return $this->getCurrentUser()->roles->pluck('identify');
+    }
+
+    /**
+     * 当前用户是否是cp角色
+     * @return bool
+     */
+    public function userIsCp():bool {
+        return $this->listUserRoles()->contains('cp');
+    }
+
+    /**
+     * 如果当前用户是cp角色,返回cp_name,否则返回null
+     * @return string
+     */
+    public function getUserCpName():string|null {
+        if($this->userIsCp()) {
+            return DB::table('user_belong_to_cp')
+                ->where([
+                    'is_enabled' => 1,
+                    'user_id' => $this->getCurrentUser()->id,
+                ])->value('cp_name');
+        } else {
+            return null;
+        }
+    }
+
+}

+ 226 - 0
modules/Video/Http/Controllers/VideoController.php

@@ -0,0 +1,226 @@
+<?php
+
+namespace Modules\Video\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Modules\Common\Errors\Errors;
+use Modules\Common\Exceptions\CommonBusinessException;
+use Modules\User\Models\User;
+
+class VideoController extends CatchController
+{
+    use UserTrait;
+    use ValidatesRequests;
+
+    /**
+     * 短剧列表
+     * @param Request $request
+     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+     */
+    public function list(Request $request) {
+
+        $videoName = $request->input('videoName');
+        $updateType = $request->input('updateType');
+        $categoryId = $request->input('categoryId');
+
+        $videos = DB::table('videos')
+            ->when($videoName, function ($query, $videoName){
+               return $query->where('name', 'like', '%'. $videoName . '%');
+            })->when($updateType, function ($query, $updateType){
+                return $query->where('update_type', $updateType);
+            })->when($categoryId, function ($query, $categoryId){
+                return $query->where('category_id', $categoryId);
+            })->orderBy('id', 'desc')
+            ->paginate($request->integer('per_page', 15));
+        $userContext = $this->getUserContext($request);
+        $allVideoCategory =  DB::table('video_category')
+            ->get()->keyBy('id');
+        foreach ($videos as $video) {
+            $this->updateVideoInfo($video, $userContext);
+            $video->category_str = $this->getCategoryStr($allVideoCategory, $video->category_id);
+        }
+
+        return $videos;
+    }
+
+    /**
+     * 订阅设置
+     * @param Request $request
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function setChargeConfig(Request $request) {
+        $this->validate($request, [
+            'id' => 'required',
+            'chargeCoin' => 'required|integer|min:50|max:100',
+            'chargeType' => 'required|integer|in:1',
+            'chargeSequence' => 'required|integer|min:1|max:30'
+        ]);
+        $userContext = $this->getUserContext($request);
+        if($userContext['loginUserRoles']->diff(['administrator', 'optimizer'])->isEmpty()) {
+            CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
+        }
+        $now = date('Y-m-d H:i:s');
+        if($userContext['loginUserRoles']->contains('administrator')) {
+            DB::table('videos')
+                ->where('id', $request->input('id'))
+                ->update([
+                    'd_charge_type' => $request->input('chargeType'),
+                    'd_charge_sequence' => $request->input('chargeSequence'),
+                    'd_charge_coin' => $request->input('chargeCoin'),
+                    'updated_at' => $now
+                ]);
+        } else {
+            DB::table('video_user_config')
+                ->where([
+                    'video_id' => $request->input('id'),
+                    'uid' => $userContext['loginUser']->id
+                ])->update(['is_enabled' => 0, 'updated_at' => $now]);
+            DB::table('video_user_config')
+                ->insert([
+                    'uid' => $userContext['loginUser']->id,
+                    'video_id' => $request->input('id'),
+                    'charge_type' => $request->input('chargeType'),
+                    'charge_sequence' => $request->input('chargeSequence'),
+                    'charge_coin' => $request->input('chargeCoin'),
+                    'updated_at' => $now,
+                    'created_at' => $now
+                ]);
+        }
+
+    }
+
+    /**
+     * 添加短剧
+     * @param Request $request
+     * @return int
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function add(Request $request) {
+        $this->validate($request, [
+            'name' => 'required|string|max:128',
+            'total_episode_num' => 'required|integer',
+            'update_type' => 'required|integer|in:1,2',
+            'category_id' => 'required|integer',
+            'shelf_type' => 'required|integer|in:1,2',
+            'd_charge_sequence' => 'required|integer|min:1',
+            'd_charge_coin' => 'required|integer|min:1',
+            'cp_name' => 'required|string',
+            'cp_share_type' => 'required|integer|in:1,2,3',
+            'cover_image' => 'required|string'
+        ]);
+        $data = $request->all();
+        $now = date('Y-m-d H:i:s');
+        $data['created_at'] = $data['updated_at'] = $now;
+        if(2 == $request->integer('shelf_type')) {
+            $data['shelf_at'] = $now;
+        } else {
+            $data['shelf_at'] = null;
+        }
+        DB::table('videos')
+            ->insert($data);
+        return 1;
+    }
+
+    /**
+     * 更新短剧信息
+     * @param Request $request
+     * @return int
+     * @throws \Illuminate\Validation\ValidationException
+     */
+    public function update(Request $request) {
+        $this->validate($request, [
+            'id' => 'required',
+            'name' => 'required|string|max:128',
+            'total_episode_num' => 'required|integer',
+            'update_type' => 'required|integer|in:1,2',
+            'category_id' => 'required|integer',
+            'shelf_type' => 'required|integer|in:1,2',
+            'd_charge_sequence' => 'required|integer|min:1',
+            'd_charge_coin' => 'required|integer|min:1',
+            'cp_name' => 'required|string',
+            'cp_share_type' => 'required|integer|in:1,2,3',
+            'cover_image' => 'required|string'
+        ]);
+        $id = $request->input('id');
+        $data = $request->except('id', 'shelf_at');
+        $data['updated_at'] = date('Y-m-d H:i:s');
+        $video = DB::table('videos')->where('id', $id)->first();
+        if(!$video) {
+            CommonBusinessException::throwError(Errors::VIDEO_NOT_EXISTS);
+        }
+        if(2 == $request->integer('shelf_type') && 1 == $video->shelf_type) {
+            $data['shelf_at'] = $data['updated_at'];
+        }
+        DB::table('videos')
+            ->where('id', $id)
+            ->update($data);
+        return 1;
+    }
+
+
+    private function getUserContext(Request $request) {
+        $loginUser = $this->getLoginUser();
+        $loginUserRoles = $this->listUserRoles();
+        $operateUserId = $request->input('operateUserId');
+        if($operateUserId) {
+            $operateUser = User::find($operateUserId);
+            $operateUserRoles = $operateUser->roles->pluck('identify');
+            if($loginUser->id != $operateUser->pid) {
+                CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
+            }
+            if(!$operateUserRoles->contains('optimizer')) {
+                CommonBusinessException::throwError(Errors::NO_OPERATE_PERMISSION);
+            }
+        } else {
+            $operateUser = $loginUser;
+            $operateUserRoles = $loginUserRoles;
+        }
+
+        return compact('loginUser', 'loginUserRoles', 'operateUserRoles', 'operateUser');
+    }
+    private function updateVideoInfo($video, $userContext) {
+        if($userContext['loginUserRoles']->contains('administrator')) {
+            $video->charge_sequence = $video->d_charge_sequence;
+            $video->charge_coin = $video->d_charge_coin;
+            return;
+        }
+        if($userContext['loginUserRoles']->contains('company')) {
+            if($userContext['loginUser']->id == $userContext['operateUser']->id) {
+                $video->charge_sequence = $video->d_charge_sequence;
+                $video->charge_coin = $video->d_charge_coin;
+                return;
+            } else {
+                $videoUserConfig = $this->getVideoUserConfig($userContext['operateUser']->id, $video->id);
+                $video->charge_sequence = $videoUserConfig->charge_sequence ?? $video->d_charge_sequence;
+                $video->charge_coin = $videoUserConfig->charge_coin ?? $video->d_charge_coin;
+                return;
+            }
+        }
+        if($userContext['loginUserRoles']->contains('optimizer')) {
+            $videoUserConfig = $this->getVideoUserConfig($userContext['loginUser']->id, $video->id);
+            $video->charge_sequence = $videoUserConfig->charge_sequence ?? $video->d_charge_sequence;
+            $video->charge_coin = $videoUserConfig->charge_coin ?? $video->d_charge_coin;
+            return;
+        }
+    }
+
+    private function getVideoUserConfig($uid, $videoId) {
+         return DB::table('video_user_config')
+            ->where(['is_enabled' => 1, 'uid' => $uid, 'video_id' => $videoId])->first();
+
+    }
+
+    private function getCategoryStr($allCategory,$categoryId) {
+        $category = $allCategory->get($categoryId);
+        if(!$category) {
+            return '';
+        } else {
+            $firstLevelStr = $allCategory->get($category->pid)->category_name ?? '';
+            $secondLevelStr = $category->category_name;
+            return trim(join('/', compact('firstLevelStr','secondLevelStr')), '/');
+        }
+    }
+}

+ 32 - 0
modules/Video/Installer.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Modules\ContentManage;
+
+use Catch\Support\Module\Installer as ModuleInstaller;
+use Modules\ContentManage\Providers\ContentManageServiceProvider;
+
+class Installer extends ModuleInstaller
+{
+    protected function info(): array
+    {
+        // TODO: Implement info() method.
+        return [
+            'title' => '内容中台',
+            'name' => 'contentManage',
+            'path' => 'contentManage',
+            'keywords' => '内容中台',
+            'description' => '内容中台管理模块',
+            'provider' => ContentManageServiceProvider::class
+        ];
+    }
+
+    protected function requirePackages(): void
+    {
+        // TODO: Implement requirePackages() method.
+    }
+
+    protected function removePackages(): void
+    {
+        // TODO: Implement removePackages() method.
+    }
+}

+ 31 - 0
modules/Video/Providers/VideoServiceProvider.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Modules\Video\Providers;
+
+use Catch\CatchAdmin;
+use Catch\Providers\CatchModuleServiceProvider;
+use Modules\ContentManage\Middlewares\ContentManageGate;
+
+class VideoServiceProvider extends CatchModuleServiceProvider
+{
+    /**
+     * middlewares
+     *
+     * @return string[]
+     */
+    protected function middlewares(): array
+    {
+       return [];
+    }
+
+    /**
+     * route path
+     *
+     * @return string|array
+     */
+    public function moduleName(): string|array
+    {
+        // TODO: Implement path() method.
+        return 'video';
+    }
+}

+ 10 - 0
modules/Video/README.md

@@ -0,0 +1,10 @@
+#内容中台管理模块
+关于内容中台 相关的后台接口,对外api接口,都写在这里
+配置文件放在: config目录下,读取配置文件示例:config('contentManage.zhushuyunpublicapi.public_domain');
+config("模块名.配置文件名.配置项");
+
+数据库模型文件放在:Models 目录下面
+服务层文件放在:Services 目录下面
+控制器放在:modules/ContentManage/Http/Controllers 目录下面
+中间件放在:modules/ContentManage/Middlewares 目录下面
+路由只能现在 modules/ContentManage/rout/route.php 文件里

+ 88 - 0
modules/Video/Services/Notice/NoitceTypeService.php

@@ -0,0 +1,88 @@
+<?php
+/**
+ * ${CARET}
+ * @file:NoitceTypeService.php
+ * @Created by gnitif
+ * @Date: 2023/3/27
+ * @Time: 11:54
+ */
+
+
+namespace Modules\System\Services\Notice;
+
+use Illuminate\Support\Facades\DB;
+use Modules\ContentManage\Models\NoticeTypes;
+
+class NoitceTypeService
+{
+
+    /**
+     *  添加分类
+     * name: store
+     * @param array $param
+     * $param [
+     *      'name' => "平台通知"
+     * ];
+     * date 2023/03/27 18:14
+     */
+    public static function store(array $param)
+    {
+        return self::getModel()->storeBy($param);
+    }
+
+    protected static function getModel(){
+         return new NoticeTypes();
+    }
+
+    /**
+     *  获取通知分类列表分类
+     * name: list
+     * @param mixed $param
+     *  $param = [
+     *      'name' => '系统通知', // 分类名称模糊搜索
+     *      'page' => 1, //  页码
+     *      'limit' => 15, //  每页条数
+     * ]
+     * @param mixed $isAll // 是否获取所有数据 默认否
+     * date 2023/03/28 17:05
+     */
+    public static function list($param = [], $isAll = false)
+    {
+        $where = self::getCondition($param);
+        if ($isAll){
+            return   NoticeTypes::where($where)->select('id','name')->get();
+        }else {
+            $pageSize = $param['limit'] ?? 15;
+            return   NoticeTypes::where($where)->select('id', 'name', 'created_at')->paginate($pageSize);
+        }
+
+    }
+
+    /**
+     *  拼接查询条件
+     * name: getCondition
+     * @param mixed $param
+     * @return \string[][]
+     * date 2023/03/28 17:19
+     */
+    private static function getCondition(mixed $param)
+    {
+        $where = [['is_deleted', '=', '0']];
+        if (isset($param['name']) && !empty($param['name'])) {
+            $where[] = ['name', 'like', "%" . $param['name'] . "%"];
+        }
+        return $where;
+    }
+
+    /**
+     *  删除分类,软删除
+     * name: del
+     * @param $id
+     * @return mixed
+     * date 2023/03/29 11:05
+     */
+    public static function del($id)
+    {
+        return self::getModel()->updateBy($id,['is_deleted' => 1,'deleted_at' => date("Y-m-d H:i:s")]);
+    }
+}

+ 248 - 0
modules/Video/Services/Notice/NoticesService.php

@@ -0,0 +1,248 @@
+<?php
+/**
+ * ${CARET}
+ * @file:NoitceService.php
+ * @Created by gnitif
+ * @Date: 2023/3/27
+ * @Time: 11:54
+ */
+
+
+namespace Modules\System\Services\Notice;
+
+use Catch\Exceptions\FailedException;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\DB;
+use Modules\System\Models\Notices;
+use Modules\System\Models\UserNotice;
+use Modules\Permissions\Models\Roles;
+use Modules\User\Models\User;
+use PharIo\Manifest\Author;
+
+class NoticesService
+{
+
+    protected static function getModel()
+    {
+        return new Notices();
+    }
+
+    /**
+     *  添加通知
+     * name: addNotice
+     * @param array $param
+     *  $param = [
+     *      'title' => '测试', // 通知标题
+     *      'notice_type_id' =>  2, // 通知分类id
+     *      'type' => '2', // 通知人群 1全部 2,指定人,3指定角色
+     *      'notice_obj' => [['id' =>  1,'name' => "超管"]] , // 通知对象
+     *      'is_popup' => '1', // 是否是弹窗 1弹窗  0 普通
+     *       'content' => '312312', // 通知内容
+     * ];
+     *
+     * date 2023/03/29 14:25
+     */
+    public static function addNotice(array $param)
+    {
+
+        if ($param['type'] != 1 && (!isset($param['notice_obj']) || empty($param['notice_obj']))) {
+            throw new FailedException('通知对象不能为空!');
+        }
+
+        if ($param['type'] == 3) {
+            $roleIds = array_column($param['notice_obj'], 'id');
+            $userIds = DB::table('user_has_roles')->whereIn('role_id', $roleIds)->pluck('user_id')->toArray();
+        } else if ($param['type'] == 2) {
+            $userIds = array_column($param['notice_obj'], 'id');
+        } else {
+            $userIds = User::pluck('id')->toArray();
+            $param['notice_obj'] = [];
+        }
+        $param['user_ids'] = $userIds;
+        return self::getModel()->storeBy($param);
+    }
+
+    public static function delete($id)
+    {
+        return self::getModel()->updateBy($id, ['is_deleted' => 1, 'deleted_at' => get_date()]);
+    }
+
+    /**
+     *  获取通知详情
+     * name: getDetail
+     * @param $id
+     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|Notices[]
+     * date 2023/03/29 15:12
+     */
+    public static function getDetail($id)
+    {
+        $info = Notices::leftJoin('notice_types', 'notice_types.id', 'notices.notice_type_id')
+            ->select('notices.*', 'notice_types.name as notice_type_name')->where('notices.id', $id)->first();
+        return $info;
+    }
+
+    /**
+     *  更新
+     * name: update
+     * @param $id
+     * @param array $param
+     * date 2023/03/29 18:32
+     */
+    public static function update($id, array $param)
+    {
+       return  self::getModel()->updateBy($id, $param);
+    }
+
+    /**
+     *  管理员操作通知列表
+     * name: list
+     * @return mixed
+     * date 2023/03/29 22:49
+     */
+    public static function  list()
+    {
+        $list = self::getModel()->setBeforeGetList(function ($query) {
+            return $query->where('is_deleted', 0)->orderBy('created_at','desc');
+        })->getList();
+        if (!$list->isEmpty()) {
+            $cate = NoitceTypeService::list([], true);
+            if ($cate->isEmpty()) {
+                $cate = [];
+            } else {
+                $cate = array_column($cate->toArray(), null, 'id');
+            }
+
+            foreach ($list as $value) {
+                $value->notice_type_txt = $cate[$value->notice_type_id]['name'] ?? "";
+                $value->type_txt = $value->type == 1 ? "全部" : ($value->type == 2 ? "指定用户" : "指定角色");
+            }
+        }
+        return $list;
+    }
+
+    /**
+     * 我的通知
+     * name: myNoticesList
+     * date 2023/03/29 22:49
+     */
+    public static function myNoticesList($param = [])
+    {
+        $type = $param['type'] ?? "";
+        $noticeTypeId = $param['notice_type_id'] ?? 0;
+        $title = $param['title'] ?? "";
+        $pageSize = $param['limit'] ?? 0;
+        $pageSize = $pageSize < 1 ? 15 : $pageSize;
+        $userId = Auth::guard(getGuardName())->id();
+        $where = [
+            ['user_notice.is_deleted', '=', 0],
+            ['user_notice.user_id', '=', $userId],
+            ['notices.is_deleted', '=', 0],
+            ['user_notice.is_deleted', '=', 0],
+        ];
+        if ($type) {
+            $where[] = ['notices.type', '=', $type];
+        }
+        if ($noticeTypeId) {
+            $where[] = ['notices.notice_type_id', '=', $noticeTypeId];
+        }
+        if ($title) {
+            $where[] = ['notices.title', 'like', "%" . $title . "%"];
+        }
+
+        $list = UserNotice::leftJoin('notices', 'notices.id', "user_notice.notice_id")->where($where)->select('notices.id', 'notices.title', 'notices.is_popup', "user_notice.is_read", 'notices.created_at')
+            ->orderBy('notices.created_at', 'desc')->orderBy('sort', 'desc')->paginate($pageSize);
+        if (!$list->isEmpty()) {
+            foreach ($list as $val) {
+                $val->is_read_txt = $val->is_read == 1 ? "已读" : "未读";
+            }
+        }
+        return $list;
+    }
+
+    /**
+     *  设置已读
+     * name: setRead
+     * @param $id
+     * date 2023/03/29 23:51
+     */
+    public static function setRead($id)
+    {
+        $userId = Auth::guard(getGuardName())->id();
+        return UserNotice::where('user_id', $userId)->where('notice_id', $id)->update(['is_read' => 1, 'read_at' => get_date()]);
+    }
+
+    /**
+     *  用户删除
+     * name: userDel
+     * @param $id
+     * date 2023/03/29 23:55
+     */
+    public static function userDel($id)
+    {
+        $userId = Auth::guard(getGuardName())->id();
+        return UserNotice::where('user_id', $userId)->where('notice_id', $id)->update(['is_deleted' => 1, 'deleted_at' => get_date()]);
+    }
+
+    /**
+     *  阅读详情
+     * name: detail
+     * @param $id
+     * @return Notices
+     * date 2023/03/30 00:09
+     */
+    public static function detail($id)
+    {
+        return Notices::where('id', $id)->where('is_deleted', 0)->select('title', 'id', 'is_popup', 'content')->first();
+    }
+
+    /**
+     *  获取指定对象选择项
+     * name: objOption
+     * @param $type
+     * @param string $name
+     * @return array
+     * date 2023/03/30 10:23
+     */
+    public static function objOption($type, $name = ""): mixed
+    {
+        if ($type == 'user') {
+            if ($name) {
+                return  User::where("username", 'like', "%" . $name . "%")->without(['roles','jobs'])->select('id','username as name')->get();
+            }
+            return User::select('id','username as name')->without(['roles','jobs'])->get();
+        } else if ($type == "role") {
+            if ($name) {
+                return Roles::where("role_name", 'like', "%" . $name . "%")->select('id','role_name as name')->get();
+            }
+            return Roles::select('id','role_name as name')->get();
+        }
+        return [];
+    }
+
+    /**
+     *  一条获取弹窗信息
+     * name: getPopup
+     * @return Model|UserNotice|object|null
+     * date 2023/03/30 16:45
+     */
+    public static function getPopup()
+    {
+        $where = [
+            ['user_notice.is_deleted', '=', 0],
+            ['user_notice.user_id', '=',  Auth::guard(getGuardName())->id()],
+            ['notices.is_deleted', '=', 0],
+            ['notices.is_popup', '=', 1],
+            ['user_notice.is_read', '=', 0],
+        ];
+
+         $info =  UserNotice::leftJoin('notices', 'notices.id', "user_notice.notice_id")->where($where)->select('notices.id', 'notices.title', 'notices.content')
+             ->orderBy('notices.created_at', 'desc')->orderBy('sort', 'desc')->first();
+         if (empty($info)){
+             return  [];
+         }
+         return  $info;
+    }
+
+
+}

+ 14 - 0
modules/Video/routes/route.php

@@ -0,0 +1,14 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+use Modules\System\Http\Controllers\NoticesController;
+use Modules\System\Http\Controllers\NoticeTypesController;
+use Modules\Video\Http\Controllers\VideoController;
+
+Route::prefix('videoStock')->group(function () {
+    Route::get('video/list', [VideoController::class, 'list']);
+
+    Route::post('video/update', [VideoController::class, 'update']);
+    Route::post('video/add', [VideoController::class, 'add']);
+});
+

+ 3 - 1
tests/UsedTestCase.php

@@ -17,7 +17,9 @@ abstract class UsedTestCase extends BaseTestCase
 //            'password' => 'catchadmin',
             'remember' => false,
             'email' => 'xiaoli@qq.com',
-            'password' => 'Qaz123'
+            'password' => 'Qaz123',
+//        'email' => 'aa4@test.com',
+//            'password' => '123',
         ])->json();
         $this->token = $tokenInfo['data']['token'];
     }

+ 70 - 0
tests/Video/Http/Controllers/VideoControllerTest.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace Tests\Video\Http\Controllers;
+
+use Modules\Video\Http\Controllers\VideoController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class VideoControllerTest extends UsedTestCase
+{
+
+    public function testAdd()
+    {
+        $data = [
+            'name' => 'test1-112',
+            'total_episode_num' => 10,
+            'update_type' => 1,
+            'category_id' => 4,
+            'shelf_type' => 2,
+            'd_charge_sequence' => 3,
+            'd_charge_coin' => 10,
+            'cp_name' => 'kanshu1',
+            'cp_share_type' => 1,
+            'cover_image' => 'https://www.baidu.com'
+        ];
+
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/videoStock/video/add', $data);
+
+        $this->dumpJson($res);
+    }
+
+    public function testUpdate() {
+        $data = [
+            'name' => 'test1-114',
+            'total_episode_num' => 10,
+            'update_type' => 2,
+            'category_id' => 4,
+            'shelf_type' => 1,
+            'd_charge_sequence' => 3,
+            'd_charge_coin' => 10,
+            'cp_name' => 'kanshu1',
+            'cp_share_type' => 1,
+            'cover_image' => 'https://www.baidu.com',
+            'id' => 2,
+        ];
+
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/videoStock/video/update', $data);
+        $this->dumpJson($res);
+    }
+
+    public function testList() {
+        $query = [
+            'operateUserId' => null,
+        ];
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/videoStock/video/list', [
+//            'videoName' => '112',
+//        'updateType' => 2,
+//        'categoryId' => 4,
+            'operateUserId' =>10
+        ]);
+//        $this->dumpJson($res);
+        $res->dump();
+    }
+}