feat: 开发采集、采集箱和商品编辑功能
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
"""模型统一导出(供 Alembic autogenerate 与业务代码 import)。"""
|
||||
from models.asset import ProductAsset
|
||||
from models.category import AttributeValue, CategoryAttribute, CategoryTree
|
||||
from models.product import Product
|
||||
from models.publish_task import PublishTask
|
||||
from models.shop import Shop
|
||||
from models.user import User
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
"Shop",
|
||||
"Product",
|
||||
"ProductAsset",
|
||||
"PublishTask",
|
||||
"CategoryTree",
|
||||
"CategoryAttribute",
|
||||
"AttributeValue",
|
||||
]
|
||||
@@ -0,0 +1,34 @@
|
||||
"""采集素材(图片/视频):分组、源站 URL、转存 URL、状态。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, String, Text, Uuid, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db import Base
|
||||
from models.enums import AssetStatus
|
||||
|
||||
|
||||
class ProductAsset(Base):
|
||||
__tablename__ = "product_assets"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
product_id: Mapped[uuid.UUID] = mapped_column(
|
||||
Uuid(as_uuid=True), ForeignKey("products.id", ondelete="CASCADE"), index=True
|
||||
)
|
||||
group_key: Mapped[str] = mapped_column(String(16), default="main") # main/sku/detail/video/param/generated
|
||||
variant_name: Mapped[str | None] = mapped_column(String(128), nullable=True) # SKU 规格名
|
||||
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
||||
type: Mapped[str] = mapped_column(String(8), default="img") # img / video
|
||||
source_url: Mapped[str] = mapped_column(Text, default="")
|
||||
stored_url: Mapped[str | None] = mapped_column(Text, nullable=True) # 本地路径或七牛公网 URL
|
||||
status: Mapped[AssetStatus] = mapped_column(
|
||||
Enum(AssetStatus, native_enum=False, length=16), default=AssetStatus.pending, index=True
|
||||
)
|
||||
dedupe_key: Mapped[str | None] = mapped_column(String(512), nullable=True, index=True)
|
||||
width: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
height: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
error: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
@@ -0,0 +1,60 @@
|
||||
"""Ozon 类目字典缓存(可重建,不作为业务真源)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, Boolean, DateTime, Integer, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db import Base
|
||||
|
||||
|
||||
class CategoryTree(Base):
|
||||
__tablename__ = "category_tree"
|
||||
|
||||
description_category_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
parent_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True)
|
||||
category_name: Mapped[str] = mapped_column(String(255), default="")
|
||||
type_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
type_name: Mapped[str] = mapped_column(String(255), default="")
|
||||
disabled: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
level: Mapped[int] = mapped_column(Integer, default=0)
|
||||
lang: Mapped[str] = mapped_column(String(8), default="DEFAULT")
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class CategoryAttribute(Base):
|
||||
__tablename__ = "category_attributes"
|
||||
|
||||
description_category_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
type_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
attribute_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(255), default="")
|
||||
description: Mapped[str] = mapped_column(Text, default="")
|
||||
type: Mapped[str] = mapped_column(String(32), default="")
|
||||
dictionary_id: Mapped[int] = mapped_column(BigInteger, default=0)
|
||||
group_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
group_name: Mapped[str] = mapped_column(String(255), default="")
|
||||
is_required: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
is_aspect: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
is_collection: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
max_value_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
attribute_complex_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
complex_is_collection: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
category_dependent: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
lang: Mapped[str] = mapped_column(String(8), default="DEFAULT")
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class AttributeValue(Base):
|
||||
__tablename__ = "attribute_values"
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
attribute_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
description_category_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
type_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
value: Mapped[str] = mapped_column(String(512), default="")
|
||||
picture: Mapped[str] = mapped_column(Text, default="")
|
||||
info: Mapped[str] = mapped_column(Text, default="")
|
||||
lang: Mapped[str] = mapped_column(String(8), default="DEFAULT")
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
@@ -0,0 +1,39 @@
|
||||
"""业务枚举。值写入数据库字符串列(native_enum=False,跨 SQLite/PG 一致)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
|
||||
|
||||
class Stage(str, enum.Enum):
|
||||
collected = "collected" # 插件刚上传,只有素材与原文
|
||||
editing = "editing" # 用户正在编辑
|
||||
ready = "ready" # 必填项齐全,可发布
|
||||
publishing = "publishing" # 已提交 ImportProductsV3,等待轮询
|
||||
published = "published" # 轮询 imported 成功
|
||||
failed = "failed" # 轮询返回 errors / 校验失败
|
||||
archived = "archived" # 手动归档(软删)
|
||||
|
||||
|
||||
class AssetStatus(str, enum.Enum):
|
||||
pending = "pending" # 已入库,等待下载
|
||||
downloading = "downloading" # 正在下载源图
|
||||
uploaded = "uploaded" # 已转存(本地/七牛)
|
||||
failed = "failed" # 下载或转存失败
|
||||
|
||||
|
||||
class PublishStatus(str, enum.Enum):
|
||||
pending = "pending"
|
||||
processing = "processing"
|
||||
moderation = "moderation"
|
||||
imported = "imported"
|
||||
failed = "failed"
|
||||
|
||||
|
||||
class ShopStatus(str, enum.Enum):
|
||||
active = "active"
|
||||
invalid = "invalid" # 连通性校验失败
|
||||
disabled = "disabled"
|
||||
|
||||
|
||||
# 图片分组(对齐契约 _images)
|
||||
IMAGE_GROUPS = ("main", "sku", "detail", "video", "param", "generated")
|
||||
@@ -0,0 +1,76 @@
|
||||
"""商品主表:对齐 Ozon ImportProductsV3 字段 + 本地扩展(raw/pricing/copy)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, Enum, Float, Integer, String, Text, Uuid, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db import Base
|
||||
from models.enums import Stage
|
||||
from models.types import JSONType
|
||||
|
||||
|
||||
class Product(Base):
|
||||
__tablename__ = "products"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id: Mapped[uuid.UUID | None] = mapped_column(Uuid(as_uuid=True), nullable=True)
|
||||
shop_id: Mapped[uuid.UUID | None] = mapped_column(Uuid(as_uuid=True), nullable=True) # 上架店铺
|
||||
stage: Mapped[Stage] = mapped_column(
|
||||
Enum(Stage, native_enum=False, length=16), default=Stage.collected, index=True
|
||||
)
|
||||
|
||||
# 采集溯源
|
||||
source_platform: Mapped[str | None] = mapped_column(String(16), nullable=True)
|
||||
source_item_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
source_url: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
# ── Ozon 字段(对齐 ImportProductsV3)──
|
||||
offer_id: Mapped[str] = mapped_column(String(255), default="", index=True)
|
||||
ozon_product_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True)
|
||||
ozon_sku: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
name: Mapped[str] = mapped_column(Text, default="")
|
||||
description: Mapped[str] = mapped_column(Text, default="")
|
||||
description_category_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
type_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
old_price: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
# 币种固定人民币(跨境卖家 CNY 计价);vat 恒为 0(简化税制,无 НДС),前端不再展示
|
||||
currency_code: Mapped[str] = mapped_column(String(3), default="CNY", server_default="CNY")
|
||||
vat: Mapped[str] = mapped_column(String(8), default="0", server_default="0")
|
||||
depth: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
width: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
height: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
dimension_unit: Mapped[str] = mapped_column(String(4), default="mm", server_default="mm")
|
||||
weight: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
weight_unit: Mapped[str] = mapped_column(String(4), default="g", server_default="g")
|
||||
barcode: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
|
||||
# 图片(有序公网 URL,≤15)
|
||||
images: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
primary_image: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
images360: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
color_image: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
pdf_list: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
promotions: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
|
||||
# 动态属性(工作台映射后填)
|
||||
attributes: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
complex_attributes: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
|
||||
# ── 本地扩展(提交 Ozon 前剥离)──
|
||||
raw: Mapped[dict | None] = mapped_column(JSONType, nullable=True) # 采集原文 + texts
|
||||
pricing: Mapped[dict | None] = mapped_column(JSONType, nullable=True) # 计价结果
|
||||
copy: Mapped[dict | None] = mapped_column(JSONType, nullable=True) # AI 文案结果
|
||||
fx_rate: Mapped[float | None] = mapped_column(Float, nullable=True)
|
||||
|
||||
published_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), index=True
|
||||
)
|
||||
|
||||
# 采集素材数量(冗余,供列表快速展示;由 service 维护)
|
||||
asset_counts: Mapped[dict | None] = mapped_column(JSONType, nullable=True)
|
||||
@@ -0,0 +1,33 @@
|
||||
"""发布任务:一次 ImportProductsV3 请求与轮询结果。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, Enum, ForeignKey, Uuid, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db import Base
|
||||
from models.enums import PublishStatus
|
||||
from models.types import JSONType
|
||||
|
||||
|
||||
class PublishTask(Base):
|
||||
__tablename__ = "publish_tasks"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
product_id: Mapped[uuid.UUID] = mapped_column(
|
||||
Uuid(as_uuid=True), ForeignKey("products.id", ondelete="CASCADE"), index=True
|
||||
)
|
||||
shop_id: Mapped[uuid.UUID] = mapped_column(
|
||||
Uuid(as_uuid=True), ForeignKey("shops.id", ondelete="CASCADE"), index=True
|
||||
)
|
||||
ozon_task_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True)
|
||||
status: Mapped[PublishStatus] = mapped_column(
|
||||
Enum(PublishStatus, native_enum=False, length=16), default=PublishStatus.pending, index=True
|
||||
)
|
||||
request_payload: Mapped[dict | None] = mapped_column(JSONType, nullable=True) # 脱敏后的 items[0]
|
||||
response: Mapped[dict | None] = mapped_column(JSONType, nullable=True) # import/info 原始结果
|
||||
errors: Mapped[list | None] = mapped_column(JSONType, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
@@ -0,0 +1,30 @@
|
||||
"""Ozon 店铺(Client-Id / Api-Key 加密落库)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Enum, String, Uuid, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db import Base
|
||||
from models.enums import ShopStatus
|
||||
|
||||
|
||||
class Shop(Base):
|
||||
__tablename__ = "shops"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id: Mapped[uuid.UUID | None] = mapped_column(Uuid(as_uuid=True), nullable=True) # 预留多用户
|
||||
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
client_id_enc: Mapped[str] = mapped_column(String(1024), nullable=False) # AES-GCM 密文
|
||||
api_key_enc: Mapped[str] = mapped_column(String(1024), nullable=False)
|
||||
currency_code: Mapped[str] = mapped_column(String(3), default="RUB", server_default="RUB")
|
||||
status: Mapped[ShopStatus] = mapped_column(
|
||||
Enum(ShopStatus, native_enum=False, length=16), default=ShopStatus.active
|
||||
)
|
||||
last_checked_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
"""共享列类型:JSON(SQLite 存 TEXT,PostgreSQL 存 JSON;跨库一致)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy import JSON
|
||||
|
||||
# 统一用 generic JSON:SQLite/PostgreSQL 均可,避免 autogenerate 对 JSONB 变体渲染异常。
|
||||
# 生产若需 JSONB 的索引能力,可再按需迁移,量级上差异可忽略。
|
||||
JSONType = JSON
|
||||
@@ -0,0 +1,19 @@
|
||||
"""用户表(预留多用户;MVP 用 APP_TOKEN 时为空)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, String, Uuid, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
username: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)
|
||||
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
Reference in New Issue
Block a user