| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- """热线 / 二维码配置 CRUD"""
- from typing import Optional
- from sqlalchemy.orm import Session
- from app.models.business import HotlineConfig, QrcodeConfig
- def get_hotline(db: Session) -> Optional[HotlineConfig]:
- return (
- db.query(HotlineConfig)
- .filter(HotlineConfig.del_flag == "0")
- .order_by(HotlineConfig.create_time.asc())
- .first()
- )
- def get_qrcode(db: Session) -> Optional[QrcodeConfig]:
- return (
- db.query(QrcodeConfig)
- .filter(QrcodeConfig.del_flag == "0")
- .order_by(QrcodeConfig.create_time.asc())
- .first()
- )
- def update_hotline(
- db: Session,
- row: HotlineConfig,
- *,
- phone: Optional[str] = None,
- email: Optional[str] = None,
- address: Optional[str] = None,
- work_time: Optional[str] = None,
- update_by: Optional[str] = None,
- ) -> HotlineConfig:
- if phone is not None:
- row.phone = phone
- if email is not None:
- row.email = email
- if address is not None:
- row.address = address
- if work_time is not None:
- row.work_time = work_time
- if update_by:
- row.update_by = update_by
- db.commit()
- db.refresh(row)
- return row
- def update_qrcode(
- db: Session,
- row: QrcodeConfig,
- *,
- land_url: Optional[str] = None,
- title: Optional[str] = None,
- image_url: Optional[str] = None,
- update_by: Optional[str] = None,
- ) -> QrcodeConfig:
- if land_url is not None:
- row.land_url = land_url
- if title is not None:
- row.title = title
- if image_url is not None:
- row.image_url = image_url
- if update_by:
- row.update_by = update_by
- db.commit()
- db.refresh(row)
- return row
|