更新优惠券活动。
This commit is contained in:
parent
4f85408fd9
commit
62158fe4f0
@ -96,9 +96,19 @@ async def get_coupon_activities(
|
|||||||
.limit(limit)\
|
.limit(limit)\
|
||||||
.all()
|
.all()
|
||||||
|
|
||||||
|
# 查询每个活动被领取的次数
|
||||||
|
activities_data = []
|
||||||
|
for activity in activities:
|
||||||
|
receive_count = db.query(func.sum(CouponReceiveRecordDB.receive_count)).filter(
|
||||||
|
CouponReceiveRecordDB.activity_id == activity.id,
|
||||||
|
).scalar()
|
||||||
|
activity_data = CouponActivityInfo.model_validate(activity).model_dump()
|
||||||
|
activity_data.update({'receive_count': receive_count})
|
||||||
|
activities_data.append(activity_data)
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
"total": total,
|
"total": total,
|
||||||
"items": [CouponActivityInfo.model_validate(a) for a in activities]
|
"items": activities_data
|
||||||
})
|
})
|
||||||
|
|
||||||
@router.post("/{activity_id}/receive", response_model=ResponseModel)
|
@router.post("/{activity_id}/receive", response_model=ResponseModel)
|
||||||
|
|||||||
@ -44,12 +44,12 @@ class UserCouponDB(Base):
|
|||||||
# Pydantic 模型
|
# Pydantic 模型
|
||||||
class CouponCreate(BaseModel):
|
class CouponCreate(BaseModel):
|
||||||
name: str = Field(..., max_length=100)
|
name: str = Field(..., max_length=100)
|
||||||
amount: Optional[float] = Field(None, gt=0)
|
amount: Optional[float] = Field(None)
|
||||||
coupon_type: CouponType = Field(CouponType.CASH)
|
coupon_type: CouponType = Field(CouponType.CASH)
|
||||||
|
|
||||||
class CouponUpdate(BaseModel):
|
class CouponUpdate(BaseModel):
|
||||||
name: Optional[str] = Field(None, max_length=100)
|
name: Optional[str] = Field(None, max_length=100)
|
||||||
amount: Optional[float] = Field(None, gt=0)
|
amount: Optional[float] = Field(None)
|
||||||
coupon_type: CouponType = Field(CouponType.CASH)
|
coupon_type: CouponType = Field(CouponType.CASH)
|
||||||
|
|
||||||
class CouponInfo(BaseModel):
|
class CouponInfo(BaseModel):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user