更新活动
This commit is contained in:
parent
a2ab1c6720
commit
f4fb6929ba
@ -48,7 +48,8 @@ async def create_coupon_activity(
|
||||
@router.get("/{activity_id}", response_model=ResponseModel)
|
||||
async def get_coupon_activity(
|
||||
activity_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserDB = Depends(get_current_user)
|
||||
):
|
||||
"""获取优惠券活动详情"""
|
||||
activity = db.query(CouponActivityDB).filter(
|
||||
@ -57,7 +58,7 @@ async def get_coupon_activity(
|
||||
|
||||
if not activity:
|
||||
return error_response(code=404, message="活动不存在")
|
||||
|
||||
|
||||
# 获取活动对应的优惠券
|
||||
coupons = db.query(CouponDB).filter(
|
||||
CouponDB.id.in_(activity.coupon_config.keys())
|
||||
@ -66,12 +67,27 @@ async def get_coupon_activity(
|
||||
activity_data = CouponActivityInfo.model_validate(activity).model_dump()
|
||||
activity_data.update({'coupons': [CouponInfo.model_validate(coupon) for coupon in coupons]})
|
||||
|
||||
# 当前是否可以领取
|
||||
# 检查总领取次数是否超过限制
|
||||
can_receive = True
|
||||
|
||||
if activity.total_limit > 0:
|
||||
user_receive_count = db.query(func.count(CouponReceiveRecordDB.id)).filter(
|
||||
CouponReceiveRecordDB.activity_id == activity_id,
|
||||
CouponReceiveRecordDB.user_id == current_user.userid
|
||||
).scalar()
|
||||
if user_receive_count >= activity.total_limit:
|
||||
can_receive = False
|
||||
|
||||
# 检查当前是否可以领取
|
||||
current_time = datetime.now().time()
|
||||
if current_time < activity.daily_start_time or current_time > activity.daily_end_time:
|
||||
can_receive = False
|
||||
activity_data.update({'can_receive': can_receive})
|
||||
|
||||
# 检查活动是否结束
|
||||
if activity.end_time < datetime.now():
|
||||
activity_data.update({'can_receive': False})
|
||||
else:
|
||||
activity_data.update({'can_receive': True})
|
||||
activity_data.update({'is_end': True})
|
||||
|
||||
return success_response(data=activity_data)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user