94b7c027be
savings/comparison/wallet(金币·现金流水)/report 写入显式 created_at=datetime.now(CN_TZ).replace(tzinfo=None),替代 SQLite 下返回 UTC 的 server_default=func.now()。后台统计 admin/ops 依赖 created_at 是 UTC,不动。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: xianze <ze@192.168.0.128> Reviewed-on: #25 Co-authored-by: zhangxianze <zhangxianze@wonderable.ai> Co-committed-by: zhangxianze <zhangxianze@wonderable.ai>
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""price_report 表读写。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.rewards import CN_TZ
|
|
from app.models.price_report import PriceReport
|
|
|
|
|
|
def create_report(
|
|
db: Session,
|
|
*,
|
|
user_id: int,
|
|
comparison_record_id: int | None,
|
|
store_name: str | None,
|
|
dish_summary: str | None,
|
|
original_platform_id: str | None,
|
|
original_platform_name: str | None,
|
|
original_price_cents: int | None,
|
|
reported_platform_id: str,
|
|
reported_platform_name: str,
|
|
reported_price_cents: int,
|
|
images: list[str],
|
|
) -> PriceReport:
|
|
rep = PriceReport(
|
|
user_id=user_id,
|
|
comparison_record_id=comparison_record_id,
|
|
store_name=store_name,
|
|
dish_summary=dish_summary,
|
|
original_platform_id=original_platform_id,
|
|
original_platform_name=original_platform_name,
|
|
original_price_cents=original_price_cents,
|
|
reported_platform_id=reported_platform_id,
|
|
reported_platform_name=reported_platform_name,
|
|
reported_price_cents=reported_price_cents,
|
|
images=images,
|
|
status="pending",
|
|
created_at=datetime.now(CN_TZ).replace(tzinfo=None), # 存北京 wall-clock(同 savings/comparison)
|
|
)
|
|
db.add(rep)
|
|
db.commit()
|
|
db.refresh(rep)
|
|
return rep
|
|
|
|
|
|
def list_reports(
|
|
db: Session, user_id: int, status: str | None = None
|
|
) -> list[PriceReport]:
|
|
"""该用户的上报记录,按时间倒序;status 非空时按状态筛选。"""
|
|
stmt = select(PriceReport).where(PriceReport.user_id == user_id)
|
|
if status:
|
|
stmt = stmt.where(PriceReport.status == status)
|
|
stmt = stmt.order_by(PriceReport.created_at.desc(), PriceReport.id.desc())
|
|
return list(db.execute(stmt).scalars().all())
|