49 line
2.2 KiB
Python
49 line
2.2 KiB
Python
from sqlalchemy import Column, Integer, String, Float, DateTime, Text, func
|
|
from database import Base
|
|
import hashlib
|
|
|
|
|
|
class User(Base):
|
|
"""用户表"""
|
|
__tablename__ = "user"
|
|
|
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
|
username = Column(String(50), unique=True, nullable=False, index=True, comment="用户名")
|
|
password_hash = Column(String(128), nullable=False, comment="密码哈希")
|
|
nickname = Column(String(50), nullable=True, comment="昵称")
|
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
|
|
|
def set_password(self, password):
|
|
self.password_hash = hashlib.sha256(password.encode()).hexdigest()
|
|
|
|
def check_password(self, password):
|
|
return self.password_hash == hashlib.sha256(password.encode()).hexdigest()
|
|
|
|
|
|
class Inventory(Base):
|
|
"""库存表"""
|
|
__tablename__ = "inventory"
|
|
|
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True, comment="序号")
|
|
cInvCode = Column(String(100), nullable=False, index=True, comment="产品编码")
|
|
supplier = Column(String(200), nullable=True, comment="供应商")
|
|
casing_label_remark = Column(Text, nullable=True, comment="现外壳&标签&备注")
|
|
batch = Column(String(100), nullable=True, comment="批次")
|
|
current_remaining = Column(Float, default=0, comment="当前时间剩余")
|
|
storage_location = Column(String(200), nullable=True, comment="存货地点")
|
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
|
|
|
|
|
class TransactionLog(Base):
|
|
"""出入库记录表"""
|
|
__tablename__ = "transaction_log"
|
|
|
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
|
inventory_id = Column(Integer, nullable=False, index=True, comment="库存ID")
|
|
cInvCode = Column(String(100), nullable=False, index=True, comment="产品编码")
|
|
type = Column(String(10), nullable=False, comment="类型: in/out")
|
|
quantity = Column(Float, nullable=False, comment="数量")
|
|
remark = Column(Text, nullable=True, comment="备注")
|
|
created_at = Column(DateTime, server_default=func.now(), comment="操作时间")
|