payment_qr_service.py 932 B

1234567891011121314151617181920212223242526
  1. # app/services/payment_qr_service.py
  2. from sqlalchemy.orm import Session
  3. from app.core.biz_exception import NotFoundError, PermissionDeniedError, BizLogicError
  4. from app.models.payment_qr import VasPaymentQR
  5. from app.schemas.payment_qr import VasPaymentQrCreate
  6. class PaymentQrService:
  7. def create(db: Session, data: VasPaymentQrCreate):
  8. rec = VasPaymentQR(**data.dict())
  9. db.add(rec)
  10. db.commit()
  11. db.refresh(rec)
  12. return rec
  13. def get_by_id(db: Session, id: int):
  14. obj = db.query(VasPaymentQR).filter(id == id).first()
  15. if not obj:
  16. raise NotFoundError("QR not exist")
  17. return obj
  18. def get_by_devid(db: Session, devid: str):
  19. return db.query(VasPaymentQR).filter(VasPaymentQR.devid == devid).all()
  20. def get_by_provider(db: Session, provider: str):
  21. return db.query(VasPaymentQR).filter(VasPaymentQR.provider == provider).all()