优化接口以及后台页面样式
This commit is contained in:
@@ -31,18 +31,21 @@ 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 与 username 同值(H5 临时账号)
|
||||
$phone = $username;
|
||||
|
||||
if ($phone === null) {
|
||||
throw new \RuntimeException('Failed to allocate unique phone');
|
||||
$phoneExisting = self::where('phone', $phone)->find();
|
||||
if ($phoneExisting) {
|
||||
// 若历史数据存在“手机号=用户名”的行,直接复用;若不一致则拒绝创建,避免污染
|
||||
if (trim((string) ($phoneExisting->username ?? '')) === $username) {
|
||||
return $phoneExisting;
|
||||
}
|
||||
throw new \RuntimeException('Username is already used by another account');
|
||||
}
|
||||
|
||||
$pwd = hash_password(Random::build('alnum', 16));
|
||||
@@ -77,16 +80,6 @@ class MallUserAsset extends Model
|
||||
return $created;
|
||||
}
|
||||
|
||||
private static function allocateUniquePhone(): ?string
|
||||
{
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$candidate = '13' . sprintf('%09d', mt_rand(0, 999999999));
|
||||
if (!self::where('phone', $candidate)->find()) {
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
// allocateUniquePhone 已废弃:临时登录场景下 phone=用户名
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user