value('dept_id'); return (int) ($deptId ?: 0); } protected static function normalizeMediaSource(string $mediaSource): string { return trim($mediaSource); } /** * @return array|null */ protected static function getVisibleCreatorIds(int $adminId, array $adminInfo): ?array { return DataScopeService::getVisibleAdminIds($adminId, $adminInfo); } protected static function canMutateRecord(int $adminId, array $adminInfo, int $creatorId): bool { if ((int) ($adminInfo['root'] ?? 0) === 1) { return true; } return $adminId > 0 && $adminId === $creatorId; } protected static function assertRecordVisible(int $adminId, array $adminInfo, int $creatorId): bool { $visibleIds = self::getVisibleCreatorIds($adminId, $adminInfo); if ($visibleIds === null) { return true; } return in_array($creatorId, $visibleIds, true); } protected static function isYejiDuplicate(int $creatorId, string $yejiDate, string $mediaSource, int $excludeId = 0): bool { $query = PersonalYeji::where('creator_id', $creatorId) ->where('yeji_date', $yejiDate) ->where('media_source', $mediaSource); if ($excludeId > 0) { $query->where('id', '<>', $excludeId); } return $query->count() > 0; } protected static function isCostDuplicate(int $creatorId, string $costDate, string $mediaSource, int $excludeId = 0): bool { $query = PersonalAccountCost::where('creator_id', $creatorId) ->where('cost_date', $costDate) ->where('media_source', $mediaSource); if ($excludeId > 0) { $query->where('id', '<>', $excludeId); } return $query->count() > 0; } }