Przeglądaj źródła

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 <cursoragent@cursor.com>
zlwu 1 miesiąc temu
rodzic
commit
7a4ecc34e0
1 zmienionych plików z 36 dodań i 1 usunięć
  1. 36 1
      backend/app/services/pl_vehicle_mine_vehicles.py

+ 36 - 1
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