| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace App\Module\Game\Services;
- use App\Module\Game\Enums\REWARD_SOURCE_TYPE;
- use App\Module\Game\Logics\UserLogLogic;
- use App\Module\Game\Models\UserLog;
- use Illuminate\Pagination\LengthAwarePaginator;
- /**
- * 用户日志服务类
- *
- * 提供用户日志相关的服务方法,用于外部调用
- */
- class UserLogService
- {
- /**
- * 记录用户日志
- *
- * @param int $userId 用户ID
- * @param string $message 日志消息
- * @param string|null $sourceType 来源类型
- * @param int|null $sourceId 来源记录ID
- * @param string|null $sourceTable 来源表名
- * @return UserLog|null
- */
- public static function log(
- int $userId,
- string $message,
- ?string $sourceType = null,
- ?int $sourceId = null,
- ?string $sourceTable = null
- ): ?UserLog {
- return UserLogLogic::log($userId, $message, $sourceType, $sourceId, $sourceTable);
- }
- /**
- * 使用枚举记录用户日志
- *
- * @param int $userId 用户ID
- * @param string $message 日志消息
- * @param REWARD_SOURCE_TYPE|null $sourceType 来源类型枚举
- * @param int|null $sourceId 来源记录ID
- * @param string|null $sourceTable 来源表名
- * @return UserLog|null
- */
- public static function logWithEnum(
- int $userId,
- string $message,
- ?REWARD_SOURCE_TYPE $sourceType = null,
- ?int $sourceId = null,
- ?string $sourceTable = null
- ): ?UserLog {
- $sourceTypeValue = $sourceType ? $sourceType->value : null;
- return UserLogLogic::log($userId, $message, $sourceTypeValue, $sourceId, $sourceTable);
- }
- /**
- * 批量记录用户日志
- *
- * @param array $logs 日志数据数组
- * @return bool
- */
- public static function batchLog(array $logs): bool
- {
- return UserLogLogic::batchLog($logs);
- }
- /**
- * 获取用户日志列表
- *
- * @param int $userId 用户ID
- * @param int $page 页码
- * @param int $pageSize 每页数量
- * @param array $filters 过滤条件
- * @return LengthAwarePaginator
- */
- public static function getUserLogs(
- int $userId,
- int $page = 1,
- int $pageSize = 20,
- array $filters = []
- ): LengthAwarePaginator {
- return UserLogLogic::getUserLogs($userId, $page, $pageSize, $filters);
- }
- /**
- * 清空用户日志
- *
- * @param int $userId 用户ID
- * @return bool
- */
- public static function clearUserLogs(int $userId): bool
- {
- return UserLogLogic::clearUserLogs($userId);
- }
- /**
- * 清理过期日志
- *
- * @param int $days 保留天数
- * @return int 删除的记录数
- */
- public static function cleanExpiredLogs(int $days = 30): int
- {
- return UserLogLogic::cleanExpiredLogs($days);
- }
- /**
- * 获取用户日志统计信息
- *
- * @param int $userId 用户ID
- * @return array
- */
- public static function getUserLogStats(int $userId): array
- {
- return UserLogLogic::getUserLogStats($userId);
- }
- }
|