deep-risk/backend/app/models/order.py
2025-12-14 20:08:27 +08:00

99 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
电商订单模型
"""
from datetime import datetime
from typing import Optional, TYPE_CHECKING
from sqlalchemy import (
Column,
DateTime,
Integer,
String,
Float,
Boolean,
)
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import BaseModel
if TYPE_CHECKING:
from .streamer import StreamerInfo, McnAgency
class Order(BaseModel):
"""
电商订单数据表
"""
__tablename__ = "order"
order_id: Mapped[str] = mapped_column(
String(50), unique=True, nullable=False, comment="订单ID"
)
platform_order_no: Mapped[str] = mapped_column(
String(100), nullable=False, comment="平台订单号"
)
ecommerce_platform: Mapped[str] = mapped_column(
String(50),
nullable=False,
comment="电商平台taobao-淘宝tmall-天猫jd-京东douyin-抖音kuaishou-快手",
)
streamer_id: Mapped[str] = mapped_column(
String(50), nullable=False, comment="主播ID"
)
streamer_name: Mapped[str] = mapped_column(
String(100), nullable=False, comment="主播姓名"
)
product_id: Mapped[str] = mapped_column(
String(100), nullable=False, comment="商品ID"
)
product_name: Mapped[str] = mapped_column(
String(500), nullable=False, comment="商品名称"
)
quantity: Mapped[int] = mapped_column(
nullable=False, comment="购买数量"
)
original_price: Mapped[float] = mapped_column(
nullable=False, comment="原价"
)
sale_price: Mapped[float] = mapped_column(
nullable=False, comment="售价"
)
total_amount: Mapped[float] = mapped_column(
nullable=False, comment="总金额"
)
actual_payment: Mapped[float] = mapped_column(
nullable=False, comment="实付金额"
)
commission_ratio: Mapped[float] = mapped_column(
nullable=False, comment="佣金比例"
)
commission_amount: Mapped[float] = mapped_column(
nullable=False, comment="佣金金额"
)
streamer_commission: Mapped[float] = mapped_column(
nullable=False, comment="主播佣金"
)
buyer_id: Mapped[str] = mapped_column(
String(100), nullable=False, comment="买家ID"
)
order_time: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, comment="下单时间"
)
settlement_time: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True), nullable=True, comment="结算时间"
)
order_status: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="订单状态pending-待付款paid-已付款shipped-已发货completed-已完成cancelled-已取消",
)
is_commission_settled: Mapped[bool] = mapped_column(
default=False, comment="是否已结算佣金"
)
province: Mapped[Optional[str]] = mapped_column(
String(50), nullable=True, comment="省份"
)
city: Mapped[Optional[str]] = mapped_column(
String(50), nullable=True, comment="城市"
)