from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, Enum from sqlalchemy.sql import func from pydantic import BaseModel, Field from typing import Optional from datetime import datetime from .database import Base import enum class FeedbackCommunityApplyDB(Base): """小区开通申请表""" __tablename__ = "feedback_community_apply" id = Column(Integer, primary_key=True, autoincrement=True) user_id = Column(Integer, ForeignKey("users.userid"), nullable=False) community_name = Column(String(100), nullable=False) # 小区名称 community_address = Column(String(200), nullable=False) # 小区地址 create_time = Column(DateTime(timezone=True), server_default=func.now()) update_time = Column(DateTime(timezone=True), onupdate=func.now()) class FeedbackPartnerApplyDB(Base): """合伙人申请表""" __tablename__ = "feedback_partner_apply" id = Column(Integer, primary_key=True, autoincrement=True) user_id = Column(Integer, ForeignKey("users.userid"), nullable=False) name = Column(String(50), nullable=False) # 姓名 phone = Column(String(20), nullable=False) # 联系电话 type = Column(String(50), nullable=False) # 合伙人类型 service_target = Column(String(200), nullable=False) # 服务对象/区域 create_time = Column(DateTime(timezone=True), server_default=func.now()) update_time = Column(DateTime(timezone=True), onupdate=func.now()) # Pydantic 模型 class CommunityApplyCreate(BaseModel): user_id: int = Field(..., description="用户ID") community_name: str = Field(..., max_length=100, description="小区名称") community_address: str = Field(..., max_length=200, description="小区地址") class CommunityApplyInfo(BaseModel): id: int user_id: int community_name: str community_address: str create_time: datetime update_time: Optional[datetime] = None class Config: from_attributes = True class PartnerApplyCreate(BaseModel): user_id: int = Field(..., description="用户ID") name: str = Field(..., max_length=50, description="姓名") phone: str = Field(..., max_length=20, description="联系电话") phone_code: str = Field(..., max_length=10, description="验证码") type: str = Field(..., max_length=50, description="合伙人类型") service_target: str = Field(..., max_length=200, description="服务对象/区域") @property def type_display(self): if self.type == "community": return "社区合伙人" elif self.type == "city": return "城市合伙人" else: return self.type class PartnerApplyInfo(BaseModel): id: int user_id: int name: str phone: str type: str service_target: str create_time: datetime update_time: Optional[datetime] = None class Config: from_attributes = True