where('talent_level', $talentLevel) ->where('status', UrsTransferFeeConfig::STATUS_ENABLED) ->first(); } /** * 获取所有启用的配置,按优先级排序 * * @return \Illuminate\Database\Eloquent\Collection */ public function getEnabledConfigs() { return UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_ENABLED) ->orderBy('priority', 'desc') ->orderBy('house_level') ->orderBy('talent_level') ->get(); } /** * 获取匹配指定条件的配置 * * @param int $houseLevel 房屋等级 * @param int $talentLevel 达人等级 * @return \Illuminate\Database\Eloquent\Collection */ public function getMatchingConfigs(int $houseLevel, int $talentLevel) { return UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_ENABLED) ->where(function ($query) use ($houseLevel) { $query->where('house_level', 0) ->orWhere('house_level', $houseLevel); }) ->where(function ($query) use ($talentLevel) { $query->where('talent_level', 0) ->orWhere('talent_level', $talentLevel); }) ->orderBy('priority', 'desc') ->get(); } /** * 检查是否存在重复的配置 * * @param int $houseLevel 房屋等级 * @param int $talentLevel 达人等级 * @param int|null $excludeId 排除的配置ID * @return bool */ public function hasDuplicateConfig(int $houseLevel, int $talentLevel, ?int $excludeId = null): bool { $query = UrsTransferFeeConfig::where('house_level', $houseLevel) ->where('talent_level', $talentLevel); if ($excludeId) { $query->where('id', '!=', $excludeId); } return $query->exists(); } /** * 获取最高优先级 * * @return int */ public function getMaxPriority(): int { return UrsTransferFeeConfig::max('priority') ?? 0; } /** * 批量更新状态 * * @param array $ids 配置ID数组 * @param int $status 状态值 * @return int 更新的记录数 */ public function batchUpdateStatus(array $ids, int $status): int { return UrsTransferFeeConfig::whereIn('id', $ids) ->update(['status' => $status]); } /** * 获取统计信息 * * @return array */ public function getStatistics(): array { $total = UrsTransferFeeConfig::count(); $enabled = UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_ENABLED)->count(); $disabled = UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_DISABLED)->count(); return [ 'total' => $total, 'enabled' => $enabled, 'disabled' => $disabled, 'enabled_percentage' => $total > 0 ? round(($enabled / $total) * 100, 2) : 0, ]; } }