- 新增后台用车服务配置模块,支持维护服务简介、优势与使用流程 - 新增需求线索管理页面,支持筛选、查看与更新用车线索状态 - 新增小程序用车需求页面,优化登录路径与回跳逻辑 - 优化车型卡片跳转与用车需求提交功能 - 新增服务端API与数据处理逻辑,完善权限校验 - 更新全站配置与API文档,新增相关测试用例
38 lines
2.4 KiB
Python
38 lines
2.4 KiB
Python
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
from ..models import DemandFeatureCard, DemandForm, DemandHero, DestinationHero, HeroSlide, VehicleOption, VehicleServiceConfig
|
|
from ..serializers import model_dict
|
|
|
|
|
|
def site_config(db: Session, active_only: bool, include_public_extras: bool = True) -> dict:
|
|
hero_stmt = select(HeroSlide).order_by(HeroSlide.sortOrder.asc())
|
|
destination_hero_stmt = select(DestinationHero).order_by(DestinationHero.sortOrder.asc())
|
|
vehicle_stmt = select(VehicleOption).order_by(VehicleOption.sortOrder.asc())
|
|
demand_hero_stmt = select(DemandHero).order_by(DemandHero.sortOrder.asc())
|
|
demand_feature_card_stmt = select(DemandFeatureCard).order_by(DemandFeatureCard.sortOrder.asc())
|
|
demand_form_stmt = select(DemandForm).order_by(DemandForm.createdAt.asc())
|
|
vehicle_service_stmt = select(VehicleServiceConfig).order_by(VehicleServiceConfig.createdAt.asc())
|
|
if active_only:
|
|
hero_stmt = hero_stmt.where(HeroSlide.isActive.is_(True))
|
|
destination_hero_stmt = destination_hero_stmt.where(DestinationHero.isActive.is_(True))
|
|
vehicle_stmt = vehicle_stmt.where(VehicleOption.isActive.is_(True))
|
|
demand_hero_stmt = demand_hero_stmt.where(DemandHero.isActive.is_(True))
|
|
demand_feature_card_stmt = demand_feature_card_stmt.where(DemandFeatureCard.isActive.is_(True))
|
|
demand_form_stmt = demand_form_stmt.where(DemandForm.isActive.is_(True))
|
|
vehicle_service_stmt = vehicle_service_stmt.where(VehicleServiceConfig.isActive.is_(True))
|
|
|
|
hero_slides = db.scalars(hero_stmt).all()
|
|
destination_hero = db.scalars(destination_hero_stmt).all()
|
|
result = {
|
|
"heroSlides": [model_dict(item) for item in hero_slides],
|
|
"destinationHero": [model_dict(item) for item in destination_hero],
|
|
}
|
|
if include_public_extras:
|
|
result["vehicleOptions"] = [model_dict(item) for item in db.scalars(vehicle_stmt).all()]
|
|
vehicle_service = db.scalars(vehicle_service_stmt).first()
|
|
result["vehicleService"] = model_dict(vehicle_service) if vehicle_service else None
|
|
result["demandHero"] = [model_dict(item) for item in db.scalars(demand_hero_stmt).all()]
|
|
result["demandFeatureCards"] = [model_dict(item) for item in db.scalars(demand_feature_card_stmt).all()]
|
|
result["demandForm"] = [model_dict(item) for item in db.scalars(demand_form_stmt).all()]
|
|
return result
|