From 7a4ecc34e07470dac416faaff251c864cb2f8338 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Tue, 29 Sep 2026 12:15:57 +0800 Subject: [PATCH] fix(api): commit mineVehicles helper required by recharge withdraw withdraw commit imported should_restrict_mine_vehicles before the helper was on the branch. Co-authored-by: Cursor --- .../app/services/pl_vehicle_mine_vehicles.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/backend/app/services/pl_vehicle_mine_vehicles.py b/backend/app/services/pl_vehicle_mine_vehicles.py index c638e6408..d3756ba01 100644 --- a/backend/app/services/pl_vehicle_mine_vehicles.py +++ b/backend/app/services/pl_vehicle_mine_vehicles.py @@ -1,13 +1,48 @@ -"""当前用户关联驾押人员所挂靠车辆的车牌集合。""" +"""当前用户关联驾押人员所挂靠车辆的车牌集合;充值申请管理员放宽。""" from __future__ import annotations from typing import Optional, Set from sqlalchemy.orm import Session +from app.models.models import SysRole, SysUserRole from app.models.pl_models import PlVehicle, PlVehiclePersonnel from app.services.pl_driver_plan_service import resolve_personnel_for_user +# 小程序 mineVehicles 下可看/选本租户全部车牌的角色(精确匹配 role_name) +_PL_RECHARGE_ADMIN_ROLE_NAMES = frozenset({"管理员", "超级管理员"}) + + +def user_is_pl_recharge_admin(db: Session, tenant_no: str, user_id: str) -> bool: + uid = (user_id or "").strip() + tenant = (tenant_no or "").strip() + if not uid or not tenant: + return False + row = ( + db.query(SysRole.id) + .join(SysUserRole, SysUserRole.role_id == SysRole.id) + .filter( + SysUserRole.user_id == uid, + SysUserRole.tenant_no == tenant, + SysUserRole.del_flag == 0, + SysRole.tenant_no == tenant, + SysRole.del_flag == 0, + SysRole.status == "1", + SysRole.role_name.in_(_PL_RECHARGE_ADMIN_ROLE_NAMES), + ) + .first() + ) + return row is not None + + +def should_restrict_mine_vehicles( + db: Session, tenant_no: str, user_id: str, *, mine_vehicles: bool +) -> bool: + """mineVehicles 请求是否仍按挂靠车牌限制(管理员为 False)。""" + if not mine_vehicles: + return False + return not user_is_pl_recharge_admin(db, tenant_no, user_id) + def license_plates_for_user_personnel( db: Session, tenant_no: str, user_id: str