diff --git a/app/models/merchant.py b/app/models/merchant.py index 653df15..698e6ab 100644 --- a/app/models/merchant.py +++ b/app/models/merchant.py @@ -21,6 +21,7 @@ class MerchantDB(Base): id = Column(Integer, primary_key=True, autoincrement=True) user_id = Column(Integer, ForeignKey("users.userid"), nullable=False) # 归属用户 + community_id = Column(Integer, ForeignKey("communities.id"), nullable=False) # 所属小区 name = Column(String(100), nullable=False) business_hours = Column(String(100), nullable=False) # 营业时间,如 "09:00-22:00" address = Column(String(200), nullable=False) @@ -41,6 +42,7 @@ class MerchantDB(Base): class MerchantCreate(BaseModel): user_id: int + community_id: int # 所属小区ID name: str = Field(..., max_length=100) business_hours: str = Field(..., max_length=100) address: str = Field(..., max_length=200) @@ -55,6 +57,7 @@ class MerchantCreate(BaseModel): class MerchantApply(BaseModel): name: str = Field(..., max_length=100) + community_id: int = Field(..., ge=0) # 所属小区ID business_hours: str = Field(..., max_length=100) address: str = Field(..., max_length=200) longitude: float = Field(..., ge=-180, le=180, description="经度") @@ -70,6 +73,7 @@ class MerchantApply(BaseModel): class MerchantUpdate(BaseModel): user_id: Optional[int] = None + community_id: Optional[int] = None # 所属小区ID name: Optional[str] = Field(None, max_length=100) business_hours: Optional[str] = Field(None, max_length=100) address: Optional[str] = Field(None, max_length=200) @@ -85,6 +89,8 @@ class MerchantUpdate(BaseModel): class MerchantInfo(BaseModel): id: int user_id: int + community_id: int # 所属小区ID + community_name: Optional[str] = None # 用于关联查询显示小区名称 user_phone: Optional[str] = None user_nickname: Optional[str] = None online_pay_count: Optional[int] = 0 diff --git a/app/sql/v1.1.sql b/app/sql/v1.1.sql index f5b736e..e7c4eda 100644 --- a/app/sql/v1.1.sql +++ b/app/sql/v1.1.sql @@ -154,4 +154,9 @@ ALTER TABLE merchant_orders ADD COLUMN product_delivery_deadline_time DATETIME COMMENT '配送截止时间快照' AFTER product_delivery_date; ---====FINISH 3.23==== \ No newline at end of file +--====FINISH 3.23==== + +ALTER TABLE merchants +ADD COLUMN community_id INT COMMENT '所属小区' AFTER user_id, +ADD CONSTRAINT fk_merchant_community +FOREIGN KEY (community_id) REFERENCES communities(id) \ No newline at end of file diff --git a/jobs.sqlite b/jobs.sqlite index f30f845..808b71e 100644 Binary files a/jobs.sqlite and b/jobs.sqlite differ