v0.2.0 - 新增认购群管理员审批功能

- 创建认购群需管理员审批(pending状态)
- 新增管理员审批API:pending-approval、approve
- 普通用户创建群状态设为pending
- 管理员创建直接active
- 加入群时检查pending/rejected状态
- 模型新增approved_by、approved_at字段
This commit is contained in:
甲辰生产 2026-05-02 13:50:21 +08:00
parent bae5b6073a
commit 73075a1474
4 changed files with 125 additions and 8 deletions

View File

@ -1,5 +1,5 @@
# purchase - 认购群模型
# Version: 0.0.2 (2026-04-29)
# Version: 0.0.3 (2026-05-02)
# 认购群、成员、藏品管理
from sqlalchemy import Column, String, Text, Integer, DECIMAL, DateTime, ForeignKey, Boolean
@ -20,7 +20,9 @@ class PurchaseGroup(Base):
description = Column(Text, nullable=True) # 描述
creator_id = Column(String(36), nullable=False) # 创建者ID
creator_name = Column(String(50), nullable=True) # 创建者名字
status = Column(String(20), default="active") # active/closed
status = Column(String(20), default="pending") # pending/active/closed
approved_by = Column(String(36), nullable=True) # 审批管理员ID
approved_at = Column(DateTime(timezone=True), nullable=True) # 审批时间
total_members = Column(Integer, default=0) # 总参与人数
total_pending = Column(Integer, default=0) # 待审批人数
total_collections = Column(Integer, default=0) # 总藏品数

View File

@ -1,5 +1,6 @@
# purchase - 认购群API路由
# Version: 0.2.0 (2026-05-01)
# Version: 0.3.0 (2026-05-02)
# 新增:管理员审批功能
# 认购群、成员、藏品管理
from fastapi import APIRouter, Depends, HTTPException, Query
@ -238,13 +239,20 @@ def create_group(
except:
start_date = datetime.now()
# 管理员直接创建通过审批
if current_user.role in ["admin", "superadmin"]:
initial_status = "active"
else:
# 普通用户创建需要审批
initial_status = "pending"
group = PurchaseGroup(
group_code=group_code,
name=data.name,
description=data.description,
creator_id=current_user.f99_90_id,
creator_name=current_user.f01_01_name,
status="active",
status=initial_status,
total_members=data.total_members,
total_collections=data.total_collections,
cycle_months=data.cycle_months,
@ -253,6 +261,7 @@ def create_group(
db.add(group)
db.commit()
# 创建者直接成为成员
member = PurchaseMember(
group_id=group.id,
user_id=current_user.f99_90_id,
@ -290,6 +299,12 @@ def join_group(
if not group:
raise HTTPException(status_code=404, detail="认购群不存在")
if group.status == "pending":
raise HTTPException(status_code=400, detail="该认购群正在等待审批,请耐心等待")
if group.status == "rejected":
raise HTTPException(status_code=400, detail="该认购群申请已被拒绝")
if group.status != "active":
raise HTTPException(status_code=400, detail="该认购群已结束")
@ -658,3 +673,87 @@ def update_group(
db.refresh(group)
return group
# ============ 管理员审批API ============
class GroupApprovalResponse(BaseModel):
id: str
group_code: str
name: str
description: Optional[str]
creator_id: str
creator_name: Optional[str]
status: str
total_members: int
total_collections: int
created_at: Optional[datetime]
@router.get("/pending-approval", response_model=List[GroupApprovalResponse])
def get_pending_approval_groups(
current_user = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""获取待审批的认购群列表(仅管理员可见)"""
if not current_user:
raise HTTPException(status_code=401, detail="请先登录")
if current_user.role not in ["admin", "superadmin"]:
raise HTTPException(status_code=403, detail="只有管理员可以查看待审批列表")
groups = db.query(PurchaseGroup).filter(
PurchaseGroup.status == "pending"
).order_by(PurchaseGroup.created_at.asc()).all()
return groups
@router.post("/groups/{group_id}/approve")
def approve_group(
group_id: str,
action: str = Query(..., description="approve/reject"),
current_user = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""管理员审批或拒绝认购群"""
if not current_user:
raise HTTPException(status_code=401, detail="请先登录")
if current_user.role not in ["admin", "superadmin"]:
raise HTTPException(status_code=403, detail="只有管理员可以审批认购群")
group = db.query(PurchaseGroup).filter(PurchaseGroup.id == group_id).first()
if not group:
raise HTTPException(status_code=404, detail="认购群不存在")
if group.status != "pending":
raise HTTPException(status_code=400, detail="该认购群不在待审批状态")
if action == "approve":
group.status = "active"
group.approved_by = current_user.f99_90_id
group.approved_at = datetime.now()
db.commit()
return {"message": "已批准该认购群", "status": "active"}
elif action == "reject":
group.status = "rejected"
group.approved_by = current_user.f99_90_id
group.approved_at = datetime.now()
db.commit()
return {"message": "已拒绝该认购群", "status": "rejected"}
else:
raise HTTPException(status_code=400, detail="无效操作")
@router.get("/my-pending-groups", response_model=List[PurchaseGroupResponse])
def get_my_pending_groups(
current_user = Depends(get_current_user),
db: Session = Depends(get_db)
):
"""获取我创建的待审批认购群"""
if not current_user:
return []
groups = db.query(PurchaseGroup).filter(
PurchaseGroup.creator_id == current_user.f99_90_id,
PurchaseGroup.status == "pending"
).all()
return groups

View File

@ -1,5 +1,21 @@
# 版本更新记录
## v0.2.0 (2026-05-02)
### 后端更新
- **purchase.py**
- 新增:管理员审批功能 - 创建认购群需要管理员审批
- 新增pending-approval接口 - 获取待审批群列表(仅管理员可见)
- 新增approve接口 - 管理员审批/拒绝认购群
- 新增my-pending-groups接口 - 获取我创建的待审批群
- 修改普通用户创建群状态设为pending管理员创建直接active
- 修改加入群时检查pending/rejected状态
- **purchase模型**
- 新增approved_by字段 - 审批管理员ID
- 新增approved_at字段 - 审批时间
- 修改status字段扩展支持pending/active/closed/rejected状态
## v0.1.9 (2026-05-02)
### 后端更新

View File

@ -1,5 +1,5 @@
{
"version": "0.1.9",
"version": "0.2.0",
"updated": "2026-05-02",
"modules": {
"frontend": {
@ -12,12 +12,12 @@
}
},
"backend": {
"version": "0.1.9",
"version": "0.2.0",
"routers": {
"purchase": "0.2.0"
"purchase": "0.3.0"
},
"models": {
"purchase": "0.1.0"
"purchase": "0.0.3"
}
}
}