summary($id); } /** @deprecated 用 ChannelService::summaries() */ public static function getByIds(array $ids) { return self::service()->summaries($ids); } /** v2 口径,v3 用 ChannelAbilityService::scopeListable() / abilities() */ public static function getCanReadByUser($userUuid = null) { // 获取 user 在某章节 所有有权限的 channel 列表 $channelId = []; // 我自己的 if ($userUuid) { $my = Channel::select('uid')->where('owner_uid', $userUuid)->get(); foreach ($my as $key => $value) { $channelId[$value->uid] = $value->uid; } // 获取共享channel $allSharedChannels = ShareApi::getResList($userUuid, 2); foreach ($allSharedChannels as $key => $value) { $channelId[$value['res_id']] = $value['res_id']; } } // 获取全网公开的channel $my = Channel::select('uid')->where('status', 30)->get(); foreach ($my as $key => $value) { $channelId[$value->uid] = $value->uid; } $output = []; foreach ($channelId as $key => $value) { $output[] = $key; } return $output; } /** v2 口径,v3 用 ChannelAbilityService::writableUids() */ public static function getCanEditByUser($userUuid = null) { // 获取 user 在某章节 所有有权限的 channel 列表 $channelId = []; // 我自己的 if ($userUuid) { $my = Channel::select('uid')->where('owner_uid', $userUuid)->get(); foreach ($my as $key => $value) { $channelId[$value->uid] = $value->uid; } // 获取共享channel $allSharedChannels = ShareApi::getResList($userUuid, 2); foreach ($allSharedChannels as $key => $value) { if ($value['power'] >= 20) { $channelId[$value['res_id']] = $value['res_id']; } } } $output = []; foreach ($channelId as $key => $value) { $output[] = $key; } return $output; } public static function userCanRead($userUid, $channelUid) { $channels = ChannelApi::getCanReadByUser($userUid); return in_array($channelUid, $channels); } /** v2 口径,v3 用 ChannelAbilityService::canWrite() */ public static function userCanEdit($userUid, $channelUid) { $channels = ChannelApi::getCanEditByUser($userUid); return in_array($channelUid, $channels); } public static function canManageByUser($channelId, $userUuid) { $isOwner = Channel::where('owner_uid', $userUuid) ->where('uid', $channelId)->exists(); return $isOwner; } /** @deprecated 用 ChannelService::systemUid() */ public static function getSysChannel($channel_name, $fallback = '') { return self::service()->systemUid((string) $channel_name, (string) $fallback); } /** @deprecated 用 ChannelService::byNameOrFail() */ public static function getChannelByName($name) { return self::service()->byNameOrFail((string) $name); } /** * 获取某个studio 的某个语言的自定义书的channel * 如果没有,建立 * * @deprecated 用 ChannelService::userBookUid() */ public static function userBookGetOrCreate($studioId, $lang, $status) { return self::service()->userBookUid((string) $studioId, (string) $lang, (int) $status); } private static function service(): ChannelService { return app(ChannelService::class); } }