> $members * @return array{userids:list,members:list>,eligible_count:int} */ public static function evaluate(array $members, string $today, int $now): array { $userIds = []; foreach ($members as &$member) { if ((string) ($member['today_date'] ?? '') !== $today) { $member['today_date'] = $today; $member['today_count'] = 0; } $member['current_weight'] = 0; if (!self::eligible($member, $now)) { continue; } $userId = trim((string) ($member['userid'] ?? '')); if ($userId !== '') { $userIds[$userId] = true; } } unset($member); return [ 'userids' => array_keys($userIds), 'members' => array_values($members), 'eligible_count' => count($userIds), ]; } /** @param array $member */ public static function eligible(array $member, int $now): bool { if ((int) ($member['enabled'] ?? 0) !== 1) { return false; } $start = max(0, (int) ($member['active_start'] ?? 0)); $end = max(0, (int) ($member['active_end'] ?? 0)); if (($start > 0 && $start > $now) || ($end > 0 && $end < $now)) { return false; } $limit = max(0, (int) ($member['daily_limit'] ?? 0)); return $limit === 0 || (int) ($member['today_count'] ?? 0) < $limit; } /** @param list $left @param list $right */ public static function same(array $left, array $right): bool { $normalise = static function (array $values): array { $result = []; foreach ($values as $value) { $userId = trim((string) $value); if ($userId !== '') { $result[$userId] = true; } } $result = array_keys($result); sort($result, SORT_STRING); return $result; }; return $normalise($left) === $normalise($right); } }