chore: initialize tuhui repository
This commit is contained in:
1
backend/app/models/__init__.py
Normal file
1
backend/app/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""数据库模型"""
|
||||
BIN
backend/app/models/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/app/models/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
backend/app/models/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/download.cpython-310.pyc
Normal file
BIN
backend/app/models/__pycache__/download.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/download.cpython-311.pyc
Normal file
BIN
backend/app/models/__pycache__/download.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/download.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/download.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/order.cpython-310.pyc
Normal file
BIN
backend/app/models/__pycache__/order.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/order.cpython-311.pyc
Normal file
BIN
backend/app/models/__pycache__/order.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/order.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/order.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/user.cpython-310.pyc
Normal file
BIN
backend/app/models/__pycache__/user.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/user.cpython-311.pyc
Normal file
BIN
backend/app/models/__pycache__/user.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/user.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/user.cpython-312.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/work.cpython-310.pyc
Normal file
BIN
backend/app/models/__pycache__/work.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/work.cpython-311.pyc
Normal file
BIN
backend/app/models/__pycache__/work.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/models/__pycache__/work.cpython-312.pyc
Normal file
BIN
backend/app/models/__pycache__/work.cpython-312.pyc
Normal file
Binary file not shown.
13
backend/app/models/download.py
Normal file
13
backend/app/models/download.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from sqlalchemy import Column, Integer, DateTime, ForeignKey
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
class DownloadRecord(Base):
|
||||
__tablename__ = "download_records"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
work_id = Column(Integer, ForeignKey("works.id"), nullable=False, index=True)
|
||||
order_id = Column(Integer, ForeignKey("orders.id"), nullable=False, index=True)
|
||||
|
||||
downloaded_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
28
backend/app/models/order.py
Normal file
28
backend/app/models/order.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Enum
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
import enum
|
||||
|
||||
class OrderStatus(str, enum.Enum):
|
||||
PENDING = "pending" # 待支付
|
||||
PAID = "paid" # 已支付
|
||||
CANCELLED = "cancelled" # 已取消
|
||||
REFUNDED = "refunded" # 已退款
|
||||
|
||||
class Order(Base):
|
||||
__tablename__ = "orders"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
order_no = Column(String(100), unique=True, index=True, nullable=False) # 订单号
|
||||
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
work_id = Column(Integer, ForeignKey("works.id"), nullable=False, index=True)
|
||||
|
||||
amount = Column(Float, nullable=False) # 金额
|
||||
payment_method = Column(String(50)) # 支付方式:alipay, wechat, balance
|
||||
|
||||
status = Column(Enum(OrderStatus), default=OrderStatus.PENDING, index=True)
|
||||
|
||||
paid_at = Column(DateTime(timezone=True), nullable=True)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
15
backend/app/models/user.py
Normal file
15
backend/app/models/user.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Float
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
phone = Column(String(20), unique=True, index=True, nullable=False) # 手机号作为唯一标识
|
||||
password_hash = Column(String(255), nullable=False)
|
||||
nickname = Column(String(100), nullable=True)
|
||||
avatar = Column(String(500), nullable=True)
|
||||
balance = Column(Float, default=0.0) # 账户余额
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
33
backend/app/models/work.py
Normal file
33
backend/app/models/work.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime, Text
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
class Work(Base):
|
||||
__tablename__ = "works"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(255), nullable=False, index=True)
|
||||
category = Column(String(100), index=True)
|
||||
designer = Column(String(100))
|
||||
level = Column(Integer, default=1)
|
||||
level_text = Column(String(50))
|
||||
|
||||
# 文件路径
|
||||
original_image = Column(String(500)) # 原图(高清)
|
||||
watermarked_image = Column(String(500)) # 带水印图(详情页显示)
|
||||
thumbnail_image = Column(String(500)) # 缩略图(列表显示)
|
||||
|
||||
# 价格
|
||||
price = Column(Float, default=0.0) # 下载价格(元)
|
||||
|
||||
# 统计
|
||||
views = Column(Integer, default=0) # 浏览量
|
||||
downloads = Column(Integer, default=0) # 下载量
|
||||
collects = Column(Integer, default=0) # 收藏量
|
||||
|
||||
# 描述
|
||||
description = Column(Text, nullable=True)
|
||||
tags = Column(String(500), nullable=True) # JSON 格式存储标签
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
Reference in New Issue
Block a user