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

View File

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

Binary file not shown.