|
|
@@ -589,7 +589,13 @@ class UserService:
|
|
|
logger.error(f"❌ 更新用户UI状态失败: user_id={user_id}, error={e}")
|
|
|
return None
|
|
|
|
|
|
- async def register_with_phone(self, phone: str, username: str = "", user_id: Optional[str] = None) -> Dict:
|
|
|
+ async def register_with_phone(
|
|
|
+ self,
|
|
|
+ phone: str,
|
|
|
+ username: str = "",
|
|
|
+ user_id: Optional[str] = None,
|
|
|
+ area_code: Optional[str] = None,
|
|
|
+ ) -> Dict:
|
|
|
"""
|
|
|
使用手机号注册
|
|
|
|
|
|
@@ -640,6 +646,8 @@ class UserService:
|
|
|
username = existing_user.username
|
|
|
|
|
|
existing_user.phone = phone
|
|
|
+ if area_code is not None:
|
|
|
+ existing_user.area_code = area_code
|
|
|
existing_user.username = username
|
|
|
existing_user.user_type = "registered"
|
|
|
existing_user.is_verified = True
|
|
|
@@ -668,6 +676,7 @@ class UserService:
|
|
|
user_id=new_user_id,
|
|
|
username=username,
|
|
|
phone=phone,
|
|
|
+ area_code=area_code,
|
|
|
user_type="registered",
|
|
|
is_verified=True,
|
|
|
registered_at=datetime.now(),
|
|
|
@@ -694,7 +703,7 @@ class UserService:
|
|
|
current_avatar_id=REGISTERED_AVATAR_ID
|
|
|
)
|
|
|
|
|
|
- logger.info(f"✅ 手机号注册成功: user_id={final_user_id}, phone={phone}")
|
|
|
+ logger.info(f"✅ 手机号注册成功: user_id={final_user_id}, area_code={area_code}, phone={phone}")
|
|
|
return user.to_dict()
|
|
|
except Exception as e:
|
|
|
logger.error(f"❌ 手机号注册失败: {e}")
|
|
|
@@ -969,7 +978,7 @@ class UserService:
|
|
|
logger.error(f"❌ QQ登录/注册失败: {e}")
|
|
|
raise
|
|
|
|
|
|
- async def login_with_phone(self, phone: str) -> Optional[Dict]:
|
|
|
+ async def login_with_phone(self, phone: str, area_code: Optional[str] = None) -> Optional[Dict]:
|
|
|
"""
|
|
|
使用手机号登录
|
|
|
|
|
|
@@ -982,12 +991,22 @@ class UserService:
|
|
|
try:
|
|
|
async with db_manager.get_session() as session:
|
|
|
result = await session.execute(
|
|
|
- select(User).where(User.phone == phone)
|
|
|
+ select(User).where(
|
|
|
+ User.phone == phone,
|
|
|
+ *( [User.area_code == area_code] if area_code else [] )
|
|
|
+ )
|
|
|
)
|
|
|
user = result.scalar_one_or_none()
|
|
|
+
|
|
|
+ # 兼容旧数据:未存区号时再用空区号回退查询
|
|
|
+ if not user and area_code:
|
|
|
+ fallback_result = await session.execute(
|
|
|
+ select(User).where(User.phone == phone, User.area_code.is_(None))
|
|
|
+ )
|
|
|
+ user = fallback_result.scalar_one_or_none()
|
|
|
|
|
|
if user:
|
|
|
- logger.info(f"✅ 手机号登录成功: user_id={user.user_id}, phone={phone}")
|
|
|
+ logger.info(f"✅ 手机号登录成功: user_id={user.user_id}, area_code={area_code}, phone={phone}")
|
|
|
return user.to_dict()
|
|
|
return None
|
|
|
except Exception as e:
|