更新
This commit is contained in:
@@ -11,9 +11,22 @@ class QywxPromotionMemberRange
|
||||
* @param list<array<string,mixed>> $members
|
||||
* @return array{userids:list<string>,members:list<array<string,mixed>>,eligible_count:int}
|
||||
*/
|
||||
public static function evaluate(array $members, string $today, int $now): array
|
||||
public static function evaluate(array $members, string $today, int $now, array $config = []): array
|
||||
{
|
||||
$userIds = [];
|
||||
$backups = array_fill_keys((array) ($config['backup_userids'] ?? []), true);
|
||||
$backupIds = [];
|
||||
$scheduled = ($config['reception_mode'] ?? 'always') === 'scheduled';
|
||||
$scheduledUsers = [];
|
||||
if ($scheduled) {
|
||||
foreach ((array) ($config['reception_schedule'] ?? []) as $slot) {
|
||||
if (QywxPromotionConfig::matches($slot, $now)) {
|
||||
foreach ((array) ($slot['member_userids'] ?? []) as $userId) {
|
||||
$scheduledUsers[$userId] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($members as &$member) {
|
||||
if ((string) ($member['today_date'] ?? '') !== $today) {
|
||||
$member['today_date'] = $today;
|
||||
@@ -25,15 +38,24 @@ class QywxPromotionMemberRange
|
||||
}
|
||||
$userId = trim((string) ($member['userid'] ?? ''));
|
||||
if ($userId !== '') {
|
||||
$userIds[$userId] = true;
|
||||
if (isset($backups[$userId])) {
|
||||
$backupIds[$userId] = true;
|
||||
} elseif (!$scheduled || isset($scheduledUsers[$userId])) {
|
||||
$userIds[$userId] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($member);
|
||||
|
||||
$usingBackup = $userIds === [] && $backupIds !== [];
|
||||
if ($usingBackup) {
|
||||
$userIds = $backupIds;
|
||||
}
|
||||
return [
|
||||
'userids' => array_keys($userIds),
|
||||
'members' => array_values($members),
|
||||
'eligible_count' => count($userIds),
|
||||
'using_backup' => $usingBackup,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user