contract_server.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from sqlalchemy.ext.asyncio import AsyncSession
  2. from alien_store.repositories.contract_repo import ContractRepository
  3. from alien_store.schemas.request.contract_store import TemplatesCreate
  4. class ContractServer:
  5. def __init__(self, db: AsyncSession):
  6. self.db = db
  7. self.esign_repo = ContractRepository(db)
  8. async def create_template(self, template_data: TemplatesCreate):
  9. await self.esign_repo.create(template_data)
  10. return {
  11. "message": "模板创建成功"
  12. }
  13. async def list_by_store(self, store_id: int):
  14. return await self.esign_repo.get_by_store_id(store_id)
  15. async def get_store_reason(self, store_id: int) -> str | None:
  16. return await self.esign_repo.check_store_status(store_id)
  17. async def get_contract_item_by_sign_flow_id(self, sign_flow_id: str):
  18. return await self.esign_repo.get_contract_item_by_sign_flow_id(sign_flow_id)
  19. async def update_contract_items(self, row_id: int, items: list) -> bool:
  20. return await self.esign_repo.update_contract_items(row_id, items)
  21. async def list_all_paged(
  22. self,
  23. page: int,
  24. page_size: int = 10,
  25. store_name: str | None = None,
  26. merchant_name: str | None = None,
  27. signing_status: str | None = None,
  28. business_segment: str | None = None,
  29. store_status: str | None = None,
  30. expiry_start=None,
  31. expiry_end=None,
  32. ):
  33. items, total = await self.esign_repo.get_all_paged(
  34. page,
  35. page_size,
  36. store_name=store_name,
  37. merchant_name=merchant_name,
  38. signing_status=signing_status,
  39. business_segment=business_segment,
  40. store_status=store_status,
  41. expiry_start=expiry_start,
  42. expiry_end=expiry_end,
  43. )
  44. return items, total
  45. async def mark_signed_by_phone(self, contact_phone: str, sign_flow_id: str, signing_time, contract_download_url):
  46. return await self.esign_repo.mark_signed_by_phone(contact_phone, sign_flow_id, signing_time, contract_download_url)
  47. async def update_sign_url(self, contact_phone: str, sign_flow_id: str, sign_url: str):
  48. return await self.esign_repo.update_sign_url(contact_phone, sign_flow_id, sign_url)
  49. async def append_contract_url(self, templates_data, contract_item: dict):
  50. return await self.esign_repo.append_contract_url(templates_data, contract_item)