0, 'count_up' => 0, // 上架作品数. 'count_down' => 0, // 下架作品数 'count_reject' => 0, // 拒绝作品数 'count_checking' => 0, // 审核中作品数 'total_creator' => 0, // 多少创作者 'tutorial' => [], 'course' => [], 'top_week' => [], // 收益月榜单 'top_all' => [], // 收益总计榜单 'upload_is_maintenance' => false, // 上传是否维护中 'upload_maintenance_desc' => '', // 上传维护描述信息 ]; $userCode = $this->getUserId(); $userRepo = make(UserRepository::class); $userInfo = $userRepo->getUserInfoFromCache($userCode); $creatorRepo = make(CreatorRepository::class); $configRepo = make(ConfigRepoistory::class); $detail = $creatorRepo->detail($userCode); $level = 0; if (!empty($detail)) { $level = intval($detail->level); } $countUp = $creatorRepo->countVideoByStatusType($userCode, 'up'); $countDown = $creatorRepo->countVideoByStatusType($userCode, 'down'); $countReject = $creatorRepo->countVideoByStatusType($userCode, 'reject'); $countChecking = $creatorRepo->countVideoByStatusType($userCode, 'checking'); $totalCreator = $creatorRepo->countCreator(); // 攻略 $tutorial = [ [ 'cover' => '', 'title' => '剪辑创作技巧', 'scheme' => 'url://', 'link' => 'http://h5.py163.xyz/'. env('STATIC_DIR_NAME') .'/creator/jiqiao.html', ], [ 'cover' => '', 'title' => '剪辑工具推荐', 'scheme' => 'url://', 'link' => 'http://h5.py163xyz/'. env('STATIC_DIR_NAME') .'/creator/gongju.html', ], ]; // 教程出品 $course = [ [ 'cover' => '', 'title' => '如何利用视频盈利', 'scheme' => 'url://', 'link' => 'http://h5.py163xyz/'. env('STATIC_DIR_NAME') .'/creator/zhuanqian.html', ], [ 'cover' => '', 'title' => '如何直走高质量视频', 'scheme' => 'url://', 'link' => 'http://h5.py163xyz/'. env('STATIC_DIR_NAME') .'/creator/tigao.html', ], ]; $result['level'] = $level; $result['count_up'] = $countUp; $result['count_down'] = $countDown; $result['count_reject'] = $countReject; $result['count_checking'] = $countChecking; $result['total_creator'] = $totalCreator; $result['tutorial'] = $tutorial; $result['course'] = $course; $topWeekItems = $creatorRepo->getTopIncome('week', 5, false); $topAllItems = $creatorRepo->getTopIncome('all', 5, false); // TODO 过段时间,换成上面真实的数据. // $topWeekItems = $creatorRepo->fakeTopIncome('week', true); // $topAllItems = $creatorRepo->fakeTopIncome('all', true); if (!empty($topWeekItems)) { foreach ($topWeekItems as &$v) { $v['avatar'] = M3u8CacheRepository::getImageUrl($v['avatar']); } } if (!empty($topAllItems)) { foreach ($topAllItems as &$v) { $v['avatar'] = M3u8CacheRepository::getImageUrl($v['avatar']); } } $result['top_week'] = !empty($topWeekItems) ? $topWeekItems : []; $result['top_all'] = !empty($topAllItems) ? $topAllItems : []; if (isset($userInfo['is_vip']) && $userInfo['is_vip'] != 'y') { $result['upload_is_maintenance'] = true; $result['upload_maintenance_desc'] = '会员VIP才可以上传视频赚钱哦!'; } $arrConfig = $configRepo->gets(['upload_maintenance_status', 'upload_maintenance_desc'], 'sys', []); if (isset($arrConfig['upload_maintenance_status']) && intval($arrConfig['upload_maintenance_status']) == 1) { $result['upload_is_maintenance'] = true; $result['upload_maintenance_desc'] = $arrConfig['upload_maintenance_desc'] ?? '上传维护中,请稍后恢复再试'; } return json_success($result); } //等级中心 public function levelCenter() { $validatorFactory = make(ValidatorFactoryInterface::class); $userCode = $this->getUserId(); $userRepo = make(UserRepository::class); $arrUserInfo = $userRepo->getUserInfoData($userCode); $ruleRepo = make(CreatorRuleRepository::class); $creatorRepo = make(CreatorRepository::class); $detail = $creatorRepo->detail($userCode); $income = 0; // 当前收入, 提现会从累计里扣除算出来的. $totalIncome = 0; // 累计收入 $level = 0; $dayAddonNum = 0; if (!empty($detail)) { $income = floatval($detail->income); $totalIncome = floatval($detail->total_income); $level = intval($detail->level); $dayAddonNum = intval($detail->day_addon_num); } $ruleTable = $ruleRepo->getRules(); $level0Rule = $ruleTable[0]; if (!empty($ruleTable)) { foreach ($ruleTable as &$v) { $v['day_addon_num'] = $dayAddonNum; unset($v['deduction_scale']); } } $ruleText = << $userCode, 'nick' => !empty($detail->user->nick) ? $detail->user->nick : '', 'total_income' => $totalIncome, 'level' => $level, 'published_video' => $creatorRepo->countPublishedVideo($userCode), 'require_video' => CreatorConstant::APPLY_REQUIRE_VIDEO, 'total_like' => $creatorRepo->sumLikedVideo($userCode), 'require_like' => CreatorConstant::APPLY_REQUIRE_LIKE, 'rule_text' => $ruleText, 'rule_table' => $ruleTable, ]; return json_success($result); } // 申请创作者 public function apply() { $userCode = $this->getUserId(); $userRepo = make(UserRepository::class); $arrUserInfo = $userRepo->getUserInfoData($userCode); $ruleRepo = make(CreatorRuleRepository::class); $creatorRepo = make(CreatorRepository::class); $detail = $creatorRepo->detail($userCode); $level = 0; if (!empty($detail)) { $level = intval($detail->level); } if ($level != 0) { return json_fail('您已经是创作者了,无需再申请'); } else { if (!empty($detail)) { if ($detail->status == 3) { return json_fail('请耐心等待,正在审核中,如需加急请联系客服'); } elseif ($detail->status == 2) { return json_fail('申请已被拒绝'); } } } $publishedVideo = $creatorRepo->countPublishedVideo($userCode); if ($publishedVideo < CreatorConstant::APPLY_REQUIRE_VIDEO) { return json_fail('作品数不足', 6001); } $creatorRepo->applyToUncheck($userCode); return json_success(['result' => 'success', 'msg' => '申请成功,等待审核']); } // 我的审核视频列表 public function videoPages() { $validatorFactory = make(ValidatorFactoryInterface::class); $userCode = $this->getUserId(); $userRepo = make(UserRepository::class); $inputData = $this->getJsonData(); $rules = [ 'status_type' => 'required|in:up,down,check', 'page' => 'nullable|int', 'page_size' => 'nullable|int', ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $statusType = data_get($inputData, 'status_type', ''); $page = format_page(data_get($inputData, 'page', 1)); $pageSize = intval(data_get($inputData, 'page_size', 10)); if ($pageSize > 20) { $pageSize = 20; } $creatorRepo = make(CreatorRepository::class); $lists = $creatorRepo->videoPages($userCode, $statusType, $page, $pageSize); $arrLists = $lists->toArray(); if (!empty($arrLists['data'])) { foreach ($arrLists['data'] as &$v) { $oldMu = $v['mu']; $v['mu'] = ''; $v['cover'] = M3u8CacheRepository::getImageUrl($v['cover']); $videoStatus = intval($v['status']); $videoCheck = intval($v['check']); $income = 0.00; $totalBuy = 0; $v['status_text'] = '未知状态'; if ($videoStatus == 1 && $videoCheck == 1) { $v['status_text'] = '上架'; $v['mu'] = M3u8CacheRepository::getVideoInnerUrl($oldMu, $userCode, $v['id'], 'video'); $incomeData = $creatorRepo->oneVideoIncome($userCode, $v['id']); $income = isset($incomeData['sum']) ? $incomeData['sum'] : 0; $totalBuy = $creatorRepo->countVideoBuyer($v['id']); } elseif ($videoStatus == 2 && $videoCheck == 1) { $v['status_text'] = '下架'; $incomeData = $creatorRepo->oneVideoIncome($userCode, $v['id']); $income = isset($incomeData['sum']) ? $incomeData['sum'] : 0; $totalBuy = $creatorRepo->countVideoBuyer($v['id']); } elseif ($videoCheck == 0) { $v['status_text'] = '审核中'; $v['cover'] = ''; if ($videoStatus == 3) { $v['status_text'] = '转码中'; } elseif ($videoStatus == 4) { $v['status_text'] = '转码失败'; } } elseif ($videoCheck == 2) { $v['status_text'] = '拒绝'; } else { $v['cover'] = ''; } $v['income'] = $income; // 收益. $v['total_buy'] = $totalBuy; // 购买人次 } } return json_success($arrLists); } public function todayVideo() { $userCode = $this->getUserId(); $userRepo = make(UserRepository::class); $arrUserInfo = $userRepo->getUserInfoData($userCode); $ruleRepo = make(CreatorRuleRepository::class); $creatorRepo = make(CreatorRepository::class); $detail = $creatorRepo->detail($userCode); $income = 0; $level = 0; $dayAddonNum = 0; $dayVideo = 0; if (!empty($detail)) { $income = floatval($detail->income); $level = intval($detail->level); $dayAddonNum = intval($detail->day_addon_num); $dayVideo = intval($detail->day_video); } $ruleLevel = $ruleRepo->getRuleByLevel($level); $dayMaxVideo = intval($ruleLevel->day_max_video) + $dayAddonNum; $todayVideo = $dayVideo; $isCanUpload = true; if ($todayVideo >= $dayMaxVideo) { $isCanUpload = false; } $isCanUploadCoin = isset($detail->coin_uper) ? boolval($detail->coin_uper) : false; // 是否能传收费视频 $needUploadFreeNum = 0; // 还需要上传免费视频个数. $countFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, true); // 统计免费视频个数 $countNotFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, false); //统计收费视频个数 if ($level <= 0) { if (CreatorConstant::LEVEL_0_FREE_VIDEO_NUM > 0) { // 金币视频 x 免费要求 = 最低历史上传免费个数 $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::LEVEL_0_FREE_VIDEO_NUM : CreatorConstant::LEVEL_0_FREE_VIDEO_NUM; if ($countFreeVideos >= $leastFreeNum) { $isCanUploadCoin = true; } else { $needUploadFreeNum = $leastFreeNum - $countFreeVideos; } } else { $isCanUploadCoin = true; } } else { if (CreatorConstant::FREE_VIDEO_NUM > 0) { // 金币视频 x 免费要求 = 最低限制上传免费个数 $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::FREE_VIDEO_NUM : CreatorConstant::FREE_VIDEO_NUM; if ($countFreeVideos >= $leastFreeNum) { $isCanUploadCoin = true; } else { $needUploadFreeNum = $leastFreeNum - $countFreeVideos; } } else { $isCanUploadCoin = true; } } // $todayideo = $creatorRepo->countTodayPublishedVideo($userCode); $result = [ 'level' => $level, 'day_max_video' => $dayMaxVideo, 'commission_ratio' => $ruleLevel->commission_ratio, 'today_video' => $todayVideo, // 计划任务每日凌晨3点清零一次. 'is_can_upload' => $isCanUpload, // 今天是否能上传. 'is_can_upload_coin' => $isCanUploadCoin, 'need_upload_free_num' => $needUploadFreeNum, 'count_free_videos' => $countFreeVideos, 'count_not_free_videos' => $countNotFreeVideos, ]; // TODO // $result['is_can_upload'] = false; // $result['is_can_upload_coin'] = false; return json_success($result); } public function createVideo() { // TODO // return json_fail('视频服务器正在扩容,预计2022-04-25日晚间恢复'); $validatorFactory = make(ValidatorFactoryInterface::class); $userCode = $this->getUserId(); $userRepo = make(UserRepository::class); $userInfo = $userRepo->getUserInfoFromCache($userCode); if (isset($userInfo['is_vip']) && $userInfo['is_vip'] != 'y') { return json_fail('会员VIP才可以上传视频赚钱哦!'); } $inputData = $this->getJsonData(); $rules = [ 'title' => 'required', 'cover' => 'nullable|max:700', 'coins' => 'required|int', 'tags' => 'required', // 这个是ID 'file_hash' => 'required' ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $videoRepo = make(VideoRepository::class); if ($videoRepo->checkExist($inputData['file_hash'])) { return json_fail('此视频已被其他人上传过,请重新更换'); } $mediaCenterRepo = make(MediaCenterRepository::class); $hashVideoInfo = $mediaCenterRepo->getHashInfo($inputData['file_hash']); if (!empty($hashVideoInfo)) { return json_fail('此视频有人上传过了,请重新更换'); } $ruleRepo = make(CreatorRuleRepository::class); $creatorRepo = make(CreatorRepository::class); $detail = $creatorRepo->detail($userCode); $level = 0; $dayAddonNum = 0; $dayVideo = 0; if (!empty($detail)) { $level = intval($detail->level); $dayAddonNum = intval($detail->day_addon_num); $dayVideo = intval($detail->day_video); } else { // 自动申请为原创者. $detail = $creatorRepo->applyToUncheck($userCode); $level = intval($detail->level); } $ruleLevel = $ruleRepo->getRuleByLevel($level); $dayMaxVideo = intval($ruleLevel->day_max_video) + $dayAddonNum; $todayVideo = !empty($detail) ? $dayVideo : 0; if ($todayVideo >= $dayMaxVideo) { return json_fail('今日已经超出上传数量限制'); } $cover = data_get($inputData, 'cover', ''); $coins = intval(data_get($inputData, 'coins', 0)); // 金币,单位数量个,10金币=1元人民币 $uploadingUrl = ''; // TODO,这里可以做一个固定视频,等待用户上传转码中. if ($coins < 0) { $coins = 0; } if ($coins > CreatorConstant::VIDEO_SELL_MAX_COIN) { return json_fail('售卖金币价格太大,可以提前联系客服'); } $arrTagIds = []; $tmpTagIds = data_get($inputData, 'tags', ''); if (is_string($tmpTagIds)) { $arrTagIds = explode(',', $tmpTagIds); } else { $arrTagIds = $tmpTagIds; } if (!empty($arrTagIds)) { $arrTagIds = array_filter($arrTagIds); $arrTagIds = array_unique($arrTagIds); } if (empty($arrTagIds)) { return json_fail('请选择至少1个口味'); } if (count($arrTagIds) > CreatorConstant::VIDEO_TAG_MAX_NUM) { return json_fail('最多选择'. strval(CreatorConstant::VIDEO_TAG_MAX_NUM) .'个口味'); } // 处理关联标签. $tagIdsRaltion = []; $tagNames = []; if (!empty($arrTagIds)) { foreach ($arrTagIds as $v) { $tagObj = TypeModel::query()->where('id', $v)->first(); if (!empty($tagObj->id)) { $tagIdsRaltion[] = $tagObj->id; $tagNames[] = $tagObj->title; } } } $isCanUploadCoin = isset($detail->coin_uper) ? boolval($detail->coin_uper) : false; // 是否能传收费视频 $needUploadFreeNum = 0; // 还需要上传免费视频个数. $countFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, true); // 统计免费视频个数 $countNotFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, false); //统计收费视频个数 if ($level <= 0) { if (CreatorConstant::LEVEL_0_FREE_VIDEO_NUM > 0) { // 金币视频 x 免费要求 = 最低历史上传免费个数 $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::LEVEL_0_FREE_VIDEO_NUM : CreatorConstant::LEVEL_0_FREE_VIDEO_NUM; if ($countFreeVideos >= $leastFreeNum) { $isCanUploadCoin = true; } else { $needUploadFreeNum = $leastFreeNum - $countFreeVideos; } } else { $isCanUploadCoin = true; } } else { if (CreatorConstant::FREE_VIDEO_NUM > 0) { // 金币视频 x 免费要求 = 最低限制上传免费个数 $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::FREE_VIDEO_NUM : CreatorConstant::FREE_VIDEO_NUM; if ($countFreeVideos >= $leastFreeNum) { $isCanUploadCoin = true; } else { $needUploadFreeNum = $leastFreeNum - $countFreeVideos; } } else { $isCanUploadCoin = true; } } if ($coins > 0 && !$isCanUploadCoin) { return json_fail('还不能上传收费视频,请先再传'. strval($needUploadFreeNum) . '个免费视频'); } $payType = 2; // 默认金币 if ($coins == 0) { $payType = 1; // vip } $newStrTagNames = !empty($tagNames) ? implode(',', $tagNames) : ''; $newStrTagIds = !empty($arrTagIds) ? implode(',', $arrTagIds) : ''; $setarr = [ 'uid' => $userCode, 'status' => 3, 'check' => 0, 'pay_type' => $payType, 'type' => 1, 'mu' => $uploadingUrl, 'title' => trim(data_get($inputData, 'title', '')), 'cover' => $cover, 'coins' => $coins, 'tags' => $newStrTagNames, 'file_hash' => data_get($inputData, 'file_hash', ''), 'custom_cover' => $cover, // 用户自定义封面. ]; $videoObj = VideoModel::query()->create($setarr); if ($videoObj) { $videoId = $videoObj->id; if (!empty($tagIdsRaltion)) { foreach ($tagIdsRaltion as $tagId) { $setarr2 = [ 'type_id' => $tagId, 'video_id' => $videoId, 'status' => 1, ]; TypeVideoModel::query()->create($setarr2); } } // 累加今日上传视频数量. $detail->day_video++; $detail->save(); } else { return json_fail('创建视频失败'); } $result = [ 'video' => [ 'id' => $videoObj->id, // 给前端的。前端拿到这个, 拼接 app应用全称(媒资库里定义的)| 模块名 | 视频ID ,doukui|video|video_id 'title' => $setarr['title'], 'coins' => $setarr['coins'], 'cover' => '', // 这里ppvod的是暴露的jpg路径,不能用,直接访问空字符串 'tag_names' => $newStrTagNames, 'tag_ids' => $newStrTagIds, ], ]; return json_success($result); } /** * 上传设置描述 * @return array */ public function uploadSetting() { $configRepo = make(ConfigRepoistory::class); $creatorRepo = make(CreatorRepository::class); $userCode = $this->getUserId(); $detail = $creatorRepo->detail($userCode); $level = 0; if (!empty($detail)) { $level = intval($detail->level); } $fileMaxSizeMb = CreatorConstant::VIDEO_MAX_SIZE_MB; // 文件最大多少MB $maxCoin = CreatorConstant::VIDEO_SELL_MAX_COIN; // 最多设置金币个数 $creatorMinVideoNum = CreatorConstant::FREE_VIDEO_NUM; // 创作者,level>0 $normalMinVideoNum = CreatorConstant::LEVEL_0_FREE_VIDEO_NUM; // 普通人, level=0 $maxTagNum = CreatorConstant::VIDEO_TAG_MAX_NUM; // 最多选择标签个数. $agreementLink = 'http://h5.py163xyz/'. env('STATIC_DIR_NAME') .'/creator/upload_agreement.html'; $tags = $creatorRepo->canUseTags(); $ppvodParams = $configRepo->gets(['ppvod_upload_category', 'ppvod_upload_tpl_id', 'ppvod_upload_tpl_name'], 'sys', []); $isCanUploadCoin = isset($detail->coin_uper) ? boolval($detail->coin_uper) : false; // 是否能传收费视频 $needUploadFreeNum = 0; // 还需要上传免费视频个数. $countFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, true); // 统计免费视频个数 $countNotFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, false); //统计收费视频个数 if ($level <= 0) { if (CreatorConstant::LEVEL_0_FREE_VIDEO_NUM > 0) { // 金币视频 x 免费要求 = 最低历史上传免费个数 $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::LEVEL_0_FREE_VIDEO_NUM : CreatorConstant::LEVEL_0_FREE_VIDEO_NUM; if ($countFreeVideos >= $leastFreeNum) { $isCanUploadCoin = true; } else { $needUploadFreeNum = $leastFreeNum - $countFreeVideos; } } else { $isCanUploadCoin = true; } } else { if (CreatorConstant::FREE_VIDEO_NUM > 0) { // 金币视频 x 免费要求 = 最低限制上传免费个数 $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::FREE_VIDEO_NUM : CreatorConstant::FREE_VIDEO_NUM; if ($countFreeVideos >= $leastFreeNum) { $isCanUploadCoin = true; } else { $needUploadFreeNum = $leastFreeNum - $countFreeVideos; } } else { $isCanUploadCoin = true; } } $coverDesc = << $coverDesc, 'price_desc' => $priceDesc, 'file_max_size_mb' => $fileMaxSizeMb, 'max_coin' => $maxCoin, 'creator_min_video_num' => $creatorMinVideoNum, 'normal_min_video_num' => $normalMinVideoNum, 'max_tag_num' => $maxTagNum, 'tags' => $tags, 'agreement_link' => $agreementLink, 'is_can_upload_coin' => $isCanUploadCoin, 'need_upload_free_num' => $needUploadFreeNum, 'count_free_videos' => $countFreeVideos, 'count_not_free_videos' => $countNotFreeVideos, 'ppvod_upload_category' => !empty($ppvodParams['ppvod_upload_category']) ? $ppvodParams['ppvod_upload_category'] : '用户上传', 'ppvod_upload_tpl_id' => !empty($ppvodParams['ppvod_upload_tpl_id']) ? $ppvodParams['ppvod_upload_tpl_id'] : '', 'ppvod_upload_tpl_name' => !empty($ppvodParams['ppvod_upload_tpl_name']) ? $ppvodParams['ppvod_upload_tpl_name'] : '默认', ]; // TODO // $result['file_max_size_mb'] = 1; return json_success($result); } /** * 删除视频. * @return mixed * @throws \Exception */ public function deleteVideo() { $creatorRepo = make(CreatorRepository::class); $validatorFactory = make(ValidatorFactoryInterface::class); $userCode = $this->getUserId(); $inputData = $this->getJsonData(); $rules = [ 'video_id' => 'required', 'force_state' => 'nullable|in:yes,no' ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $isForce = false; $videoId = data_get($inputData, 'video_id', ''); $forceState = data_get($inputData, 'force_state', 'no'); if ($forceState == 'yes') { $isForce = true; } $deleteStatus = $creatorRepo->deleteVideo($userCode, $videoId, $isForce); if (!$deleteStatus) { return json_fail('删除失败,请联系管理员'); } return json_success(['result' => 'success']); } }