config.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """热线 / 二维码配置 CRUD"""
  2. from typing import Optional
  3. from sqlalchemy.orm import Session
  4. from app.models.business import HotlineConfig, QrcodeConfig
  5. def get_hotline(db: Session) -> Optional[HotlineConfig]:
  6. return (
  7. db.query(HotlineConfig)
  8. .filter(HotlineConfig.del_flag == "0")
  9. .order_by(HotlineConfig.create_time.asc())
  10. .first()
  11. )
  12. def get_qrcode(db: Session) -> Optional[QrcodeConfig]:
  13. return (
  14. db.query(QrcodeConfig)
  15. .filter(QrcodeConfig.del_flag == "0")
  16. .order_by(QrcodeConfig.create_time.asc())
  17. .first()
  18. )
  19. def update_hotline(
  20. db: Session,
  21. row: HotlineConfig,
  22. *,
  23. phone: Optional[str] = None,
  24. email: Optional[str] = None,
  25. address: Optional[str] = None,
  26. work_time: Optional[str] = None,
  27. update_by: Optional[str] = None,
  28. ) -> HotlineConfig:
  29. if phone is not None:
  30. row.phone = phone
  31. if email is not None:
  32. row.email = email
  33. if address is not None:
  34. row.address = address
  35. if work_time is not None:
  36. row.work_time = work_time
  37. if update_by:
  38. row.update_by = update_by
  39. db.commit()
  40. db.refresh(row)
  41. return row
  42. def update_qrcode(
  43. db: Session,
  44. row: QrcodeConfig,
  45. *,
  46. land_url: Optional[str] = None,
  47. title: Optional[str] = None,
  48. image_url: Optional[str] = None,
  49. update_by: Optional[str] = None,
  50. ) -> QrcodeConfig:
  51. if land_url is not None:
  52. row.land_url = land_url
  53. if title is not None:
  54. row.title = title
  55. if image_url is not None:
  56. row.image_url = image_url
  57. if update_by:
  58. row.update_by = update_by
  59. db.commit()
  60. db.refresh(row)
  61. return row