update
This commit is contained in:
parent
f1d2b7f365
commit
d5b123de45
@ -26,6 +26,11 @@ class Settings(BaseSettings):
|
||||
ORDER_SUCCESS_TODAY_TEXT: str = "订单预计今晚前送达,请注意查收"
|
||||
ORDER_SUCCESS_TOMORROW_TEXT: str = "订单预计明晚前送达,请注意查收"
|
||||
|
||||
# 邀请新人赠送优惠券ID
|
||||
FIRST_ORDER_REFERRAL_COUPON_ID: int = 1
|
||||
FIRST_ORDER_REFERRAL_COUPON_COUNT: int = 1
|
||||
FIRST_ORDER_REFERRAL_COUPON_EXPIRE_DAYS: int = 7
|
||||
|
||||
# JWT 配置
|
||||
SECRET_KEY: str = "s10GmiRMmplfYWXYZLSsE3X36Ld4gVZxHgAcdqFGC20v3llv7UdOeWLBEEP3e40p"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES: Optional[int] = None # None 表示永不过期
|
||||
@ -65,6 +70,7 @@ class Settings(BaseSettings):
|
||||
{"coupon_id": 1, "count": 3, "expire_days": 15},
|
||||
]
|
||||
|
||||
# 小程序 & 微信支付配置
|
||||
WECHAT_APPID: str = "wx3cc5b7dcb28f2756"
|
||||
WECHAT_SECRET: str = "fdf03e0ff428097c2a264da50b7d804e"
|
||||
WECHAT_MCH_ID: str = "1705259837"
|
||||
@ -73,6 +79,15 @@ class Settings(BaseSettings):
|
||||
WECHAT_API_V3_KEY: str = "OAhAqXqebeT4ZC9VTYFkSWU0CENEahx5" # API v3密钥
|
||||
WECHAT_PLATFORM_CERT_PATH: str = "app/cert/platform_key.pem" # 平台证书路径
|
||||
|
||||
# 企业微信配置
|
||||
WECHAT_CORP_ID: str = "ww0e3897ec32009e20"
|
||||
WECHAT_CORP_SECRET: str = "FLghJS0t3LiE6M6z6fxL9QraIwGGTLuJg0vNrXgQ-zE"
|
||||
WECHAT_CORP_AGENT_ID: str = "1000002"
|
||||
WECHAT_CORP_TOKEN: str = "5zEDkbGNPbBoh"
|
||||
WECHAT_CORP_ENCODING_AES_KEY: str = "VTFtnosOeX7cdnRDBBCE0JTC5s7W7iFP8o86Oowo2w8"
|
||||
#WECHAT_CORP_AGENT_SECRET: str = "66666666666666666666666666666666"
|
||||
|
||||
# 公众号配置
|
||||
MP_APPID: str = "wxa9db2cc7868dfefd"
|
||||
MP_SECRET: str = "3eed9a717654d6460ba9afda3b0f6be2"
|
||||
MP_TOKEN: str = "yORAT7RL9I3sux7uc4PbMEEHT1xowc6H" # 用于验证服务器配置
|
||||
|
||||
47
app/core/coupon_manager.py
Normal file
47
app/core/coupon_manager.py
Normal file
@ -0,0 +1,47 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models.coupon import CouponDB,UserCouponDB
|
||||
from app.models.user import UserDB
|
||||
from datetime import datetime
|
||||
|
||||
class CouponManager:
|
||||
def __init__(self, db: Session):
|
||||
self.db = db
|
||||
|
||||
# 发放优惠券
|
||||
def add_coupon(
|
||||
self,
|
||||
user_id: int,
|
||||
coupon_id: int,
|
||||
count: int,
|
||||
expire_time: datetime
|
||||
):
|
||||
try:
|
||||
# 检查优惠券是否存在
|
||||
coupon = self.db.query(CouponDB).filter(CouponDB.id == coupon_id).first()
|
||||
if not coupon:
|
||||
raise ValueError("优惠券不存在")
|
||||
|
||||
# 检查用户是否存在
|
||||
user = self.db.query(UserDB).filter(UserDB.userid == user_id).first()
|
||||
if not user:
|
||||
raise ValueError("用户不存在")
|
||||
|
||||
for _ in range(count):
|
||||
# 发放优惠券
|
||||
user_coupon = UserCouponDB(
|
||||
user_id=user_id,
|
||||
coupon_id=coupon_id,
|
||||
coupon_name=coupon.name,
|
||||
coupon_amount=coupon.amount,
|
||||
coupon_type=coupon.coupon_type,
|
||||
expire_time=expire_time,
|
||||
)
|
||||
self.db.add(user_coupon)
|
||||
|
||||
self.db.commit()
|
||||
except Exception as e:
|
||||
self.db.rollback()
|
||||
raise e
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user