46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey
|
||
from sqlalchemy.sql import func
|
||
from pydantic import BaseModel, Field
|
||
from typing import Optional
|
||
from datetime import datetime
|
||
from .database import Base
|
||
from sqlalchemy.orm import relationship
|
||
|
||
class MerchantAuthDB(Base):
|
||
"""商家认证信息表"""
|
||
__tablename__ = "merchant_auths"
|
||
|
||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||
merchant_id = Column(Integer, ForeignKey("merchants.id"), nullable=False, unique=True) # 商家ID,一个商家只能有一条认证信息
|
||
license_image_url = Column(String(200), nullable=False) # 营业执照图片URL
|
||
id_front_url = Column(String(200), nullable=False) # 身份证正面图片URL
|
||
id_back_url = Column(String(200), nullable=False) # 身份证背面图片URL
|
||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
||
|
||
# 关联商家
|
||
merchant = relationship("MerchantDB", backref="auth_info")
|
||
|
||
# Pydantic 模型,用于API请求和响应
|
||
class MerchantAuthCreate(BaseModel):
|
||
merchant_id: int = Field(..., description="商家ID")
|
||
license_image_url: str = Field(..., description="营业执照图片URL")
|
||
id_front_url: str = Field(..., description="身份证正面图片URL")
|
||
id_back_url: str = Field(..., description="身份证背面图片URL")
|
||
|
||
class MerchantAuthUpdate(BaseModel):
|
||
license_image_url: Optional[str] = Field(None, description="营业执照图片URL")
|
||
id_front_url: Optional[str] = Field(None, description="身份证正面图片URL")
|
||
id_back_url: Optional[str] = Field(None, description="身份证背面图片URL")
|
||
|
||
class MerchantAuthInfo(BaseModel):
|
||
id: int
|
||
merchant_id: int
|
||
license_image_url: str
|
||
id_front_url: str
|
||
id_back_url: str
|
||
create_time: datetime
|
||
update_time: Optional[datetime] = None
|
||
|
||
class Config:
|
||
from_attributes = True |