diff --git a/app/common/model/MallUserAsset.php b/app/common/model/MallUserAsset.php index d1f5b7b..dd90c6a 100644 --- a/app/common/model/MallUserAsset.php +++ b/app/common/model/MallUserAsset.php @@ -31,13 +31,16 @@ class MallUserAsset extends Model */ public static function ensureForUsername(string $username): self { - $username = trim($username); +// $username = trim($username); $existing = self::where('username', $username)->find(); if ($existing) { return $existing; } - $phone = self::allocateUniquePhone(); + //手机号直接=用户名,暂时不做验证 +// $phone = self::allocateUniquePhone(); + $phone = $username; + if ($phone === null) { throw new \RuntimeException('Failed to allocate unique phone'); } @@ -77,7 +80,7 @@ class MallUserAsset extends Model private static function allocateUniquePhone(): ?string { for ($i = 0; $i < 8; $i++) { - $candidate = '13' . str_pad(mt_rand(0, 999999999), 9, '0', STR_PAD_LEFT); + $candidate = '13' . sprintf('%09d', mt_rand(0, 999999999)); if (!self::where('phone', $candidate)->find()) { return $candidate; }