优化接口/api/v1/temLogin报错

This commit is contained in:
2026-03-31 09:39:02 +08:00
parent 8305dbfcfd
commit 2868899253

View File

@@ -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;
}