deliveryman-api/app/models/merchant_auth.py
2025-03-21 11:33:10 +08:00

46 lines
1.9 KiB
Python
Raw Permalink 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 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