You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
769 B
31 lines
769 B
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\Activity;
|
|
use App\Models\Venue;
|
|
|
|
/** 活动 + 场馆核销共用 6 位数字,全库唯一(含软删活动占用) */
|
|
final class PortalSixDigitPin
|
|
{
|
|
public static function isTaken(string $pin): bool
|
|
{
|
|
$pin = trim($pin);
|
|
|
|
return Activity::withTrashed()->where('verify_portal_pin', $pin)->exists()
|
|
|| Venue::query()->where('verify_portal_pin', $pin)->exists();
|
|
}
|
|
|
|
public static function generateUnique(): string
|
|
{
|
|
for ($n = 0; $n < 500; $n++) {
|
|
$pin = sprintf('%06d', random_int(0, 999_999));
|
|
if (! self::isTaken($pin)) {
|
|
return $pin;
|
|
}
|
|
}
|
|
|
|
return sprintf('%06d', random_int(0, 999_999));
|
|
}
|
|
}
|