contract_repo.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from sqlalchemy.ext.asyncio import AsyncSession
  2. from alien_store.db.models.contract_store import ContractStore
  3. class ContractRepository:
  4. """合同数据访问层"""
  5. def __init__(self, db: AsyncSession):
  6. self.db = db
  7. async def get_by_id(self, store_id: int):
  8. """根据店铺id查询所有合同"""
  9. result = await self.db.execute(
  10. ContractStore.__table__.select().where(ContractStore.id == store_id)
  11. )
  12. return result.fetchall()
  13. async def create(self, user_data):
  14. """创建未签署合同模板"""
  15. db_templates = ContractStore(
  16. store_id=user_data.store_id,
  17. merchant_name=user_data.merchant_name,
  18. business_segment=user_data.business_segment,
  19. contact_phone=user_data.contact_phone,
  20. contract_url=user_data.contract_url,
  21. seal_url='0.0',
  22. )
  23. self.db.add(db_templates)
  24. await self.db.commit()
  25. await self.db.refresh(db_templates)
  26. return db_templates