update
This commit is contained in:
parent
b4fda2abc1
commit
666896047e
@ -21,6 +21,8 @@ from app.models.point import PointRecordDB
|
|||||||
from app.core.account import AccountManager
|
from app.core.account import AccountManager
|
||||||
from app.core.wechat import WeChatClient
|
from app.core.wechat import WeChatClient
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("", response_model=ResponseModel)
|
@router.post("", response_model=ResponseModel)
|
||||||
@ -77,6 +79,7 @@ async def create_merchant_order(
|
|||||||
merchant_product_id=order.merchant_product_id,
|
merchant_product_id=order.merchant_product_id,
|
||||||
order_amount=original_amount,
|
order_amount=original_amount,
|
||||||
pay_amount=pay_amount,
|
pay_amount=pay_amount,
|
||||||
|
gift_points=float(product.sale_price) * settings.POINT_RATIO,
|
||||||
status=MerchantOrderStatus.CREATED,
|
status=MerchantOrderStatus.CREATED,
|
||||||
order_verify_code=verify_code
|
order_verify_code=verify_code
|
||||||
)
|
)
|
||||||
@ -361,10 +364,9 @@ async def calculate_order_price(
|
|||||||
if not product:
|
if not product:
|
||||||
return error_response(code=404, message="商品不存在")
|
return error_response(code=404, message="商品不存在")
|
||||||
|
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
"original_price": float(product.sale_price),
|
"gift_points": float(product.sale_price) * settings.POINT_RATIO,
|
||||||
"final_amount": product.sale_price
|
"amount": product.sale_price
|
||||||
})
|
})
|
||||||
|
|
||||||
class RefundRequest(BaseModel):
|
class RefundRequest(BaseModel):
|
||||||
|
|||||||
@ -14,6 +14,7 @@ from app.api.deps import get_current_user, get_admin_user
|
|||||||
from app.models.user import UserDB
|
from app.models.user import UserDB
|
||||||
from app.core.response import success_response, error_response, ResponseModel
|
from app.core.response import success_response, error_response, ResponseModel
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
from app.core.config import settings
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -39,7 +40,8 @@ async def create_pay_order(
|
|||||||
order_id=order_id,
|
order_id=order_id,
|
||||||
merchant_id=order.merchant_id,
|
merchant_id=order.merchant_id,
|
||||||
user_id=current_user.userid,
|
user_id=current_user.userid,
|
||||||
amount=order.amount
|
amount=order.amount,
|
||||||
|
gift_points=order.amount * settings.POINT_RATIO
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -164,7 +164,8 @@ async def create_payment(
|
|||||||
result = await wechat.create_jsapi_payment(
|
result = await wechat.create_jsapi_payment(
|
||||||
openid=current_user.openid,
|
openid=current_user.openid,
|
||||||
out_trade_no=request.order_id,
|
out_trade_no=request.order_id,
|
||||||
total_amount=int(float(amount) * 100), # 转换为分
|
# total_amount=int(float(amount) * 100), # 转换为分
|
||||||
|
total_amount=int(1), # 测试 1 分钱
|
||||||
description=description
|
description=description
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -232,16 +233,14 @@ async def payment_notify(
|
|||||||
|
|
||||||
if trade_state == "SUCCESS":
|
if trade_state == "SUCCESS":
|
||||||
# 添加积分
|
# 添加积分
|
||||||
points = order.pay_amount * 10
|
|
||||||
point_manager = PointManager(db)
|
point_manager = PointManager(db)
|
||||||
point_manager.add_points(order.user_id, points, f"订单完成,获得{settings.POINT_ALIAS} 奖励")
|
point_manager.add_points(order.user_id, order.gift_points, PointRecordType.CONSUME_RETURN, f"团购订单奖励", order.order_id)
|
||||||
|
|
||||||
# 更新订单状态
|
# 更新订单状态
|
||||||
order.pay_status = True
|
order.pay_status = True
|
||||||
order.status = MerchantOrderStatus.UNVERIFIED
|
order.status = MerchantOrderStatus.UNVERIFIED
|
||||||
order.transaction_id = transaction_id
|
order.transaction_id = transaction_id
|
||||||
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
||||||
order.gift_points = points
|
|
||||||
|
|
||||||
elif out_trade_no.startswith("P"): # 商家在线买单
|
elif out_trade_no.startswith("P"): # 商家在线买单
|
||||||
order = db.query(MerchantPayOrderDB).filter(
|
order = db.query(MerchantPayOrderDB).filter(
|
||||||
@ -253,16 +252,14 @@ async def payment_notify(
|
|||||||
|
|
||||||
if trade_state == "SUCCESS":
|
if trade_state == "SUCCESS":
|
||||||
# 添加积分
|
# 添加积分
|
||||||
points = order.amount * 10
|
|
||||||
point_manager = PointManager(db)
|
point_manager = PointManager(db)
|
||||||
point_manager.add_points(order.user_id, points, f"订单完成,获得{settings.POINT_ALIAS} 奖励")
|
point_manager.add_points(order.user_id, order.gift_points, PointRecordType.CONSUME_RETURN, f"买单订单奖励", order.order_id)
|
||||||
|
|
||||||
# 更新订单状态
|
# 更新订单状态
|
||||||
order.pay_status = True
|
order.pay_status = True
|
||||||
order.status = MerchantPayOrderStatus.PAID
|
order.status = MerchantPayOrderStatus.PAID
|
||||||
order.transaction_id = transaction_id
|
order.transaction_id = transaction_id
|
||||||
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
||||||
order.gift_points = points
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return error_response(code=400, message="未知的订单类型")
|
return error_response(code=400, message="未知的订单类型")
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
# 积分别名
|
# 积分别名
|
||||||
POINT_ALIAS: str = "蜂蜜"
|
POINT_ALIAS: str = "蜂蜜"
|
||||||
|
POINT_RATIO: float = 10.0 # 积分兑换比例
|
||||||
|
|
||||||
# 订单价格配置
|
# 订单价格配置
|
||||||
ORDER_BASE_PRICE: float = 3.0 # 基础费用
|
ORDER_BASE_PRICE: float = 3.0 # 基础费用
|
||||||
|
|||||||
@ -32,6 +32,7 @@ class MerchantDB(Base):
|
|||||||
longitude = Column(DECIMAL(9, 6), nullable=False) # 经度,精确到小数点后6位
|
longitude = Column(DECIMAL(9, 6), nullable=False) # 经度,精确到小数点后6位
|
||||||
latitude = Column(DECIMAL(9, 6), nullable=False) # 纬度,精确到小数点后6位
|
latitude = Column(DECIMAL(9, 6), nullable=False) # 纬度,精确到小数点后6位
|
||||||
phone = Column(String(20), nullable=False)
|
phone = Column(String(20), nullable=False)
|
||||||
|
brand_image_url = Column(String(200)) # 品牌图片地址
|
||||||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
category_id = Column(Integer, ForeignKey("merchant_categories.id"), nullable=True)
|
category_id = Column(Integer, ForeignKey("merchant_categories.id"), nullable=True)
|
||||||
@ -57,6 +58,7 @@ class MerchantCreate(BaseModel):
|
|||||||
longitude: float = Field(..., ge=-180, le=180, description="经度")
|
longitude: float = Field(..., ge=-180, le=180, description="经度")
|
||||||
latitude: float = Field(..., ge=-90, le=90, description="纬度")
|
latitude: float = Field(..., ge=-90, le=90, description="纬度")
|
||||||
phone: str = Field(..., max_length=20, pattern=r'^\d+$')
|
phone: str = Field(..., max_length=20, pattern=r'^\d+$')
|
||||||
|
brand_image_url: Optional[str] = Field(None, max_length=200)
|
||||||
images: List[MerchantImage] = []
|
images: List[MerchantImage] = []
|
||||||
category_id: Optional[int] = None
|
category_id: Optional[int] = None
|
||||||
|
|
||||||
@ -68,6 +70,7 @@ class MerchantUpdate(BaseModel):
|
|||||||
longitude: Optional[float] = Field(None, ge=-180, le=180, description="经度")
|
longitude: Optional[float] = Field(None, ge=-180, le=180, description="经度")
|
||||||
latitude: Optional[float] = Field(None, ge=-90, le=90, description="纬度")
|
latitude: Optional[float] = Field(None, ge=-90, le=90, description="纬度")
|
||||||
phone: Optional[str] = Field(None, max_length=20, pattern=r'^\d+$')
|
phone: Optional[str] = Field(None, max_length=20, pattern=r'^\d+$')
|
||||||
|
brand_image_url: Optional[str] = Field(None, max_length=200)
|
||||||
images: Optional[List[MerchantImage]] = None
|
images: Optional[List[MerchantImage]] = None
|
||||||
category_id: Optional[int] = None
|
category_id: Optional[int] = None
|
||||||
|
|
||||||
@ -83,6 +86,7 @@ class MerchantInfo(BaseModel):
|
|||||||
longitude: float
|
longitude: float
|
||||||
latitude: float
|
latitude: float
|
||||||
phone: str
|
phone: str
|
||||||
|
brand_image_url: Optional[str] = None
|
||||||
images: List[MerchantImage]
|
images: List[MerchantImage]
|
||||||
create_time: datetime
|
create_time: datetime
|
||||||
update_time: Optional[datetime]
|
update_time: Optional[datetime]
|
||||||
|
|||||||
@ -38,7 +38,6 @@ class MerchantOrderDB(Base):
|
|||||||
|
|
||||||
class MerchantOrderCreate(BaseModel):
|
class MerchantOrderCreate(BaseModel):
|
||||||
merchant_product_id: int
|
merchant_product_id: int
|
||||||
order_amount: float = Field(..., gt=0)
|
|
||||||
|
|
||||||
class MerchantOrderInfo(BaseModel):
|
class MerchantOrderInfo(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user