修改积分数据类型为整数
This commit is contained in:
parent
38b88bfb19
commit
3e90da4910
@ -75,7 +75,7 @@ async def create_merchant_order(
|
||||
merchant_product_id=order.merchant_product_id,
|
||||
order_amount=pay_amount,
|
||||
pay_amount=pay_amount,
|
||||
gift_points=float(product.sale_price) * (float(product.gift_points_rate) / 100) * settings.POINT_RATIO,
|
||||
gift_points=int(float(product.sale_price) * (float(product.gift_points_rate) / 100) * settings.POINT_RATIO),
|
||||
status=MerchantOrderStatus.CREATED,
|
||||
order_verify_code=verify_code
|
||||
)
|
||||
@ -360,7 +360,7 @@ async def calculate_order_price(
|
||||
return error_response(code=404, message="商品不存在")
|
||||
|
||||
return success_response(data={
|
||||
"gift_points": float(product.sale_price) * (float(product.gift_points_rate) / 100) * settings.POINT_RATIO,
|
||||
"gift_points": int(float(product.sale_price) * (float(product.gift_points_rate) / 100) * settings.POINT_RATIO),
|
||||
"amount": product.sale_price
|
||||
})
|
||||
|
||||
|
||||
@ -37,10 +37,10 @@ async def calculate_gift_points(
|
||||
return error_response(code=404, message="商家不存在")
|
||||
|
||||
# 计算赠送积分
|
||||
gift_points = request.amount * (float(merchant.pay_gift_points_rate) / 100) * settings.POINT_RATIO
|
||||
gift_points = int(request.amount * (float(merchant.pay_gift_points_rate) / 100) * settings.POINT_RATIO)
|
||||
|
||||
return success_response(data={
|
||||
"gift_points": float(gift_points)
|
||||
"gift_points": gift_points
|
||||
})
|
||||
|
||||
@router.post("", response_model=ResponseModel)
|
||||
@ -66,7 +66,7 @@ async def create_pay_order(
|
||||
merchant_id=order.merchant_id,
|
||||
user_id=current_user.userid,
|
||||
amount=order.amount,
|
||||
gift_points=order.amount * (float(merchant.pay_gift_points_rate) / 100) * settings.POINT_RATIO
|
||||
gift_points=int(order.amount * (float(merchant.pay_gift_points_rate) / 100) * settings.POINT_RATIO)
|
||||
)
|
||||
|
||||
try:
|
||||
@ -93,7 +93,7 @@ async def create_pay_order(
|
||||
merchant_id=order.merchant_id,
|
||||
user_id=order.user_id,
|
||||
amount=float(order.amount),
|
||||
gift_points=float(order.gift_points),
|
||||
gift_points=order.gift_points,
|
||||
status=order.status,
|
||||
create_time=order.create_time,
|
||||
update_time=order.update_time,
|
||||
@ -144,7 +144,7 @@ async def list_pay_orders(
|
||||
merchant_id=order.MerchantPayOrderDB.merchant_id,
|
||||
user_id=order.MerchantPayOrderDB.user_id,
|
||||
amount=float(order.MerchantPayOrderDB.amount),
|
||||
gift_points=float(order.MerchantPayOrderDB.gift_points),
|
||||
gift_points=order.MerchantPayOrderDB.gift_points,
|
||||
status=order.MerchantPayOrderDB.status,
|
||||
create_time=order.MerchantPayOrderDB.create_time,
|
||||
update_time=order.MerchantPayOrderDB.update_time,
|
||||
@ -208,7 +208,7 @@ async def admin_list_pay_orders(
|
||||
merchant_id=order.merchant_id,
|
||||
user_id=order.user_id,
|
||||
amount=float(order.amount),
|
||||
gift_points=float(order.gift_points),
|
||||
gift_points=order.gift_points,
|
||||
status=order.status,
|
||||
create_time=order.create_time,
|
||||
update_time=order.update_time,
|
||||
|
||||
@ -90,13 +90,13 @@ def calculate_price(price_request: OrderPriceCalculateRequest,user: UserDB,db: S
|
||||
remaining_amount -= coupon_discount
|
||||
# 3. 如果没有优惠券,且用户有积分,则使用积分抵扣
|
||||
elif user.points > 0:
|
||||
# 计算最大可抵扣金额(1元=10积分)
|
||||
max_points_discount = float(user.points) / settings.POINT_RATIO
|
||||
# 计算最大可抵扣金额
|
||||
max_points_discount = user.points // settings.POINT_RATIO # 使用整除
|
||||
points_discount_amount = min(remaining_amount, max_points_discount)
|
||||
|
||||
if points_discount_amount > 0:
|
||||
result.price_info.points_discount_amount = points_discount_amount
|
||||
result.price_info.points_used = float(points_discount_amount * settings.POINT_RATIO)
|
||||
result.used_points = float(points_discount_amount * settings.POINT_RATIO) # 记录使用的积分数
|
||||
result.used_points = int(points_discount_amount * settings.POINT_RATIO)
|
||||
remaining_amount -= points_discount_amount
|
||||
|
||||
# 计算最终金额
|
||||
@ -467,7 +467,7 @@ async def cancel_order(
|
||||
# 如果使用了积分,返还积分
|
||||
if order.point_discount_amount > 0:
|
||||
# 返还积分
|
||||
return_points = float(order.point_discount_amount) * settings.POINT_RATIO
|
||||
return_points = int(order.point_discount_amount * settings.POINT_RATIO)
|
||||
current_user.points += return_points
|
||||
|
||||
# 记录积分变动
|
||||
@ -620,7 +620,7 @@ async def deliveryman_cancel_order(
|
||||
# 如果使用了积分,返还积分
|
||||
if order.point_discount_amount > 0:
|
||||
# 返还积分
|
||||
return_points = float(order.point_discount_amount) * settings.POINT_RATIO
|
||||
return_points = int(order.point_discount_amount * settings.POINT_RATIO)
|
||||
|
||||
order_user = db.query(UserDB).filter(
|
||||
UserDB.userid == order.userid
|
||||
|
||||
@ -68,6 +68,6 @@ async def get_point_records(
|
||||
|
||||
return success_response(data={
|
||||
"total": total, # 总记录数
|
||||
"total_points": float(total_points), # 当前总积分
|
||||
"total_points": total_points, # 当前总积分
|
||||
"items": [PointRecordInfo.model_validate(r) for r in records] # 积分记录列表
|
||||
})
|
||||
@ -26,7 +26,7 @@ class MerchantOrderDB(Base):
|
||||
merchant_product_id = Column(Integer, ForeignKey("merchant_products.id"), nullable=False)
|
||||
order_amount = Column(DECIMAL(10,2), nullable=False)
|
||||
pay_amount = Column(DECIMAL(10,2), nullable=False, default=0)
|
||||
gift_points = Column(DECIMAL(10,1), nullable=False, default=0) # 赠送的积分
|
||||
gift_points = Column(Integer, nullable=False, default=0) # 赠送的积分
|
||||
status = Column(Enum(MerchantOrderStatus), nullable=False, default=MerchantOrderStatus.CREATED)
|
||||
pay_status = Column(Boolean, nullable=False, default=False)
|
||||
order_verify_code = Column(String(21), unique=True, nullable=False)
|
||||
@ -47,7 +47,7 @@ class MerchantOrderInfo(BaseModel):
|
||||
merchant_product_id: int
|
||||
order_amount: float
|
||||
pay_amount: float
|
||||
gift_points: float
|
||||
gift_points: int
|
||||
status: MerchantOrderStatus
|
||||
order_verify_code: str
|
||||
verify_time: Optional[datetime]
|
||||
|
||||
@ -21,7 +21,7 @@ class MerchantPayOrderDB(Base):
|
||||
merchant_id = Column(Integer, ForeignKey("merchants.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.userid"), nullable=False)
|
||||
amount = Column(DECIMAL(10,2), nullable=False)
|
||||
gift_points = Column(DECIMAL(10,1), nullable=False, default=0)
|
||||
gift_points = Column(Integer, nullable=False, default=0)
|
||||
status = Column(Enum(MerchantPayOrderStatus), nullable=False, default=MerchantPayOrderStatus.UNPAID)
|
||||
pay_status = Column(Boolean, nullable=False, default=False)
|
||||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||||
@ -39,7 +39,7 @@ class MerchantPayOrderInfo(BaseModel):
|
||||
merchant_id: int
|
||||
user_id: int
|
||||
amount: float
|
||||
gift_points: float
|
||||
gift_points: int
|
||||
status: MerchantPayOrderStatus
|
||||
create_time: datetime
|
||||
update_time: Optional[datetime]
|
||||
|
||||
@ -124,7 +124,6 @@ class OrderPriceInfo(BaseModel):
|
||||
original_amount: float
|
||||
coupon_discount_amount: float = 0
|
||||
points_discount_amount: float = 0
|
||||
points_used: Optional[float] = None
|
||||
coupon_id: Optional[int] = None
|
||||
final_amount: float
|
||||
|
||||
@ -140,5 +139,5 @@ class OrderPriceResult(BaseModel):
|
||||
"""订单价格计算结果"""
|
||||
price_info: OrderPriceInfo
|
||||
used_coupon_id: Optional[int] = None # 使用的优惠券ID
|
||||
used_points: Optional[float] = None # 使用的积分数
|
||||
used_points: Optional[int] = None # 使用的积分数
|
||||
price_detail_text: Optional[str] = None # 价格详情文本
|
||||
@ -16,7 +16,7 @@ class PointRecordDB(Base):
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.userid"), nullable=False)
|
||||
points = Column(Integer, nullable=False) # 正数表示增加,负数表示减少
|
||||
points = Column(Integer, nullable=False) # 积分变动数量
|
||||
type = Column(Enum(PointRecordType), nullable=False)
|
||||
order_id = Column(String(32), nullable=True, index=True) # 添加索引但不设置外键
|
||||
description = Column(String(200), nullable=False)
|
||||
|
||||
@ -33,7 +33,7 @@ class UserDB(Base):
|
||||
password = Column(String(128), nullable=True) # 加密后的密码
|
||||
avatar = Column(String(200), nullable=True) # 头像URL地址
|
||||
gender = Column(Enum(Gender), nullable=False, default=Gender.UNKNOWN)
|
||||
points = Column(DECIMAL(10,1), nullable=False, default=0.0)
|
||||
points = Column(Integer, default=0) # 积分
|
||||
roles = Column(JSON, default=lambda: [UserRole.USER]) # 存储角色列表
|
||||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||||
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user