This commit is contained in:
aaron 2025-03-30 16:52:57 +08:00
parent 9376f9a785
commit 0ed2b1d732
3 changed files with 15 additions and 16 deletions

View File

@ -1261,21 +1261,23 @@ async def deliveryman_complete_order(
db.commit()
# 如果当前订单是首单,如果有邀请人,给邀请人发放优惠券
if order.is_first_order and order_user.referral_code:
# 有邀请人,给邀请人积分奖励
if order_user.referral_code:
# 查询邀请人
invite_user = db.query(UserDB).filter(
UserDB.user_code == order_user.referral_code
).first()
if invite_user:
expire_time = datetime.now() + timedelta(days=settings.FIRST_ORDER_REFERRAL_COUPON_EXPIRE_DAYS)
manager = CouponManager(db)
manager.add_coupon(
points = settings.FIRST_ORDER_REFERRAL_POINT if order.is_first_order else settings.COMMON_ORDER_REFERRAL_POINT
desc = f"蜜友首单奖励" if order.is_first_order else f"蜜友下单奖励"
# 邀请人赠送积分
point_manager = PointManager(db)
point_manager.add_points(
user_id=invite_user.userid,
coupon_id=settings.FIRST_ORDER_REFERRAL_COUPON_ID,
expire_time=expire_time,
count=settings.FIRST_ORDER_REFERRAL_COUPON_COUNT
points=points,
description=desc,
order_id=order.orderid
)
# 发送企业微信消息

View File

@ -29,10 +29,11 @@ class Settings(BaseSettings):
ORDER_EXTRA_PACKAGE_PRICE: float = 0.5 # 额外包裹费用
ORDER_EXTRA_PACKAGE_THRESHOLD: int = 5 # 额外收费阈值
# 邀请新人赠送优惠券ID
FIRST_ORDER_REFERRAL_COUPON_ID: int = 1
FIRST_ORDER_REFERRAL_COUPON_COUNT: int = 1
FIRST_ORDER_REFERRAL_COUPON_EXPIRE_DAYS: int = 7
# 邀请新人赠送积分
FIRST_ORDER_REFERRAL_POINT: int = 5
COMMON_ORDER_REFERRAL_POINT: int = 1
# JWT 配置
SECRET_KEY: str = "s10GmiRMmplfYWXYZLSsE3X36Ld4gVZxHgAcdqFGC20v3llv7UdOeWLBEEP3e40p"
@ -193,10 +194,6 @@ class ProdSettings(Settings):
REDIS_PASSWORD: str = "redis_tjcZif"
VERIFICATION_CODE_EXPIRE_SECONDS: int = 300
FIRST_ORDER_REFERRAL_COUPON_ID: int = 2
FIRST_ORDER_REFERRAL_COUPON_COUNT: int = 1
FIRST_ORDER_REFERRAL_COUPON_EXPIRE_DAYS: int = 3
class Config:
env_file = ".env.prod"

Binary file not shown.