diff --git a/VERSION b/VERSION index 5f8175f..24ca32d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -VERSION=1.2.76 +VERSION=1.2.77 diff --git a/backend/app/models/models.py b/backend/app/models/models.py index 387f670..f218c60 100644 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -44,7 +44,8 @@ class User(Base): f99_100_points = Column(Integer, default=0) # 积分 f01_11_balance = Column(Float, default=0) # 余额 f01_12_total_amount = Column(Float, default=0) # 累计金额 - f01_13_invite_code = Column(String(20), nullable=True) # 邀请码 + f01_13_invite_code = Column(String(20), nullable=True) # 邀请码(自己的邀请码) + f99_101_invited_count = Column(Integer, default=0) # 通过自己邀请码注册的用户数量 collections = relationship("Collection", back_populates="user", cascade="all, delete-orphan") operations = relationship("Operation", back_populates="user", cascade="all, delete-orphan") diff --git a/backend/app/routers/auth.py b/backend/app/routers/auth.py index ccf1ba6..7cae222 100644 --- a/backend/app/routers/auth.py +++ b/backend/app/routers/auth.py @@ -55,6 +55,17 @@ def register(user_data: UserCreate, db: Session = Depends(get_db)): detail="E00041:该邮箱已被注册,请更换邮箱" ) + # 处理邀请码 + invited_by_user = None + if user_data.invite_code: + # 查找邀请人 + invited_by_user = db.query(User).filter(User.user_code == user_data.invite_code).first() + if not invited_by_user: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="E00042:邀请码无效" + ) + # 创建用户 import uuid hashed_password = get_password_hash(user_data.password) @@ -73,6 +84,18 @@ def register(user_data: UserCreate, db: Session = Depends(get_db)): ) db.add(user) + db.flush() # 确保获取user ID + + # 更新邀请人、被邀请人的关联关系 + if invited_by_user: + # 邀请人的邀请码(创建后生成自己的邀请码) + user.f01_13_invite_code = invited_by_user.user_code + # 增加邀请人的邀请计数 + invited_by_user.f99_101_invited_count = (invited_by_user.f99_101_invited_count or 0) + 1 + + # 生成自己的邀请码(用自己的user_code) + user.f01_13_invite_code = user.user_code + db.commit() db.refresh(user) diff --git a/backend/app/schemas/schemas.py b/backend/app/schemas/schemas.py index fe79fe6..a8497b5 100644 --- a/backend/app/schemas/schemas.py +++ b/backend/app/schemas/schemas.py @@ -19,6 +19,7 @@ class UserBase(BaseModel): class UserCreate(UserBase): password: str = Field(..., min_length=6) + invite_code: Optional[str] = Field(None, alias="inviteCode") # 填写的邀请码(选填) class UserUpdate(BaseModel): @@ -50,6 +51,7 @@ class UserResponse(UserBase): f01_11_balance: Optional[float] = Field(0, alias="balance") f01_12_total_amount: Optional[float] = Field(0, alias="totalAmount") f01_13_invite_code: Optional[str] = Field(None, alias="inviteCode") + f99_101_invited_count: Optional[int] = Field(0, alias="invitedCount") f99_90_id: str = Field(..., alias="id") f01_01_name: str = Field(..., alias="username") role: str diff --git a/frontend/src/pages/Login.jsx b/frontend/src/pages/Login.jsx index 47f3198..8c8dfc1 100644 --- a/frontend/src/pages/Login.jsx +++ b/frontend/src/pages/Login.jsx @@ -18,7 +18,8 @@ export default function Login() { confirmPassword: '', email: '', phone: '', - verifyCode: '' + verifyCode: '', + inviteCode: '' }) const [registerLoading, setRegisterLoading] = useState(false) const [registerError, setRegisterError] = useState('') @@ -148,6 +149,9 @@ export default function Login() { if (registerData.email) { payload.email = registerData.email } + if (registerData.inviteCode) { + payload.inviteCode = registerData.inviteCode + } const res = await fetch('/api/auth/register', { method: 'POST', @@ -165,7 +169,7 @@ export default function Login() { alert('注册成功!请登录') setShowRegister(false) - setRegisterData({ username: '', password: '', confirmPassword: '', email: '', phone: '', verifyCode: '' }) + setRegisterData({ username: '', password: '', confirmPassword: '', email: '', phone: '', verifyCode: '', inviteCode: '' }) setCodeSent(false) setCodeCountdown(0) generateCaptcha() @@ -584,7 +588,7 @@ export default function Login() { {/* 确认密码 */} -
+
+ {/* 邀请码(选填) */} +
+ setRegisterData(prev => ({ ...prev, inviteCode: e.target.value }))} + placeholder="邀请码(选填)" + style={{ + width: '100%', + padding: '14px', + borderRadius: '8px', + border: '1px solid rgba(255,255,255,0.2)', + background: 'rgba(255,255,255,0.05)', + color: '#fff', + fontSize: '16px', + outline: 'none' + }} + /> +
+ {/* 用户协议勾选 */}
@@ -626,7 +650,7 @@ export default function Login() {