update
This commit is contained in:
parent
3dbd543357
commit
2ebac17cd2
@ -79,7 +79,7 @@ async def create_merchant_order(
|
||||
merchant_product_id=order.merchant_product_id,
|
||||
order_amount=original_amount,
|
||||
pay_amount=pay_amount,
|
||||
gift_points=float(product.sale_price) * settings.POINT_RATIO,
|
||||
gift_points=float(product.sale_price) * (float(product.gift_points_rate) / 100) * settings.POINT_RATIO,
|
||||
status=MerchantOrderStatus.CREATED,
|
||||
order_verify_code=verify_code
|
||||
)
|
||||
@ -365,7 +365,7 @@ async def calculate_order_price(
|
||||
return error_response(code=404, message="商品不存在")
|
||||
|
||||
return success_response(data={
|
||||
"gift_points": float(product.sale_price) * settings.POINT_RATIO,
|
||||
"gift_points": float(product.sale_price) * (float(product.gift_points_rate) / 100) * settings.POINT_RATIO,
|
||||
"amount": product.sale_price
|
||||
})
|
||||
|
||||
|
||||
@ -15,9 +15,35 @@ from app.models.user import UserDB
|
||||
from app.core.response import success_response, error_response, ResponseModel
|
||||
from datetime import datetime, timezone
|
||||
from app.core.config import settings
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class CalculatePointsRequest(BaseModel):
|
||||
"""计算积分请求"""
|
||||
merchant_id: int
|
||||
amount: float
|
||||
|
||||
@router.post("/calculate-points", response_model=ResponseModel)
|
||||
async def calculate_gift_points(
|
||||
request: CalculatePointsRequest,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""计算支付订单可获得的积分数量"""
|
||||
# 检查商家是否存在
|
||||
merchant = db.query(MerchantDB).filter(
|
||||
MerchantDB.id == request.merchant_id
|
||||
).first()
|
||||
if not merchant:
|
||||
return error_response(code=404, message="商家不存在")
|
||||
|
||||
# 计算赠送积分
|
||||
gift_points = request.amount * (float(merchant.pay_gift_points_rate) / 100) * settings.POINT_RATIO
|
||||
|
||||
return success_response(data={
|
||||
"gift_points": float(gift_points)
|
||||
})
|
||||
|
||||
@router.post("", response_model=ResponseModel)
|
||||
async def create_pay_order(
|
||||
order: MerchantPayOrderCreate,
|
||||
@ -41,7 +67,7 @@ async def create_pay_order(
|
||||
merchant_id=order.merchant_id,
|
||||
user_id=current_user.userid,
|
||||
amount=order.amount,
|
||||
gift_points=order.amount * settings.POINT_RATIO
|
||||
gift_points=order.amount * (merchant.pay_gift_points_rate / 100) * settings.POINT_RATIO
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@ -59,7 +59,8 @@ async def update_product(
|
||||
|
||||
update_data = product.model_dump(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(db_product, key, value)
|
||||
if value is not None:
|
||||
setattr(db_product, key, value)
|
||||
|
||||
try:
|
||||
db.commit()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user