feat: 园区成员列表返回企业管理员信息
This commit is contained in:
@@ -632,6 +632,9 @@ async def admin_park_tenant_members(
|
||||
_role: dict = Depends(require_roles("operator")),
|
||||
_perm: dict = Depends(require_permission("menu:admin_user_mgmt")),
|
||||
):
|
||||
from ...infrastructure.models import ParkCompany, CompanyMember
|
||||
from sqlalchemy import select
|
||||
|
||||
members = await db.park_members.list_by_park(tid)
|
||||
items = []
|
||||
for m in members:
|
||||
@@ -643,6 +646,29 @@ async def admin_park_tenant_members(
|
||||
# 成员用户已删除(孤儿引用):显式标记
|
||||
d["user"] = {"id": m["user_id"], "username": "", "nickname": "", "phone": "",
|
||||
"role": "", "avatar": "", "certification_status": "", "deleted": True}
|
||||
|
||||
# 查询该用户在本园区下是否为企业管理员
|
||||
d["company_admin"] = None
|
||||
try:
|
||||
cm_rows = (await db.session.execute(
|
||||
select(CompanyMember, ParkCompany)
|
||||
.join(ParkCompany, CompanyMember.company_id == ParkCompany.id)
|
||||
.where(
|
||||
CompanyMember.user_id == m["user_id"],
|
||||
ParkCompany.tenant_id == tid,
|
||||
CompanyMember.status == "active",
|
||||
)
|
||||
)).all()
|
||||
for cm, pc in cm_rows:
|
||||
if cm.member_type == "admin" or cm.is_admin:
|
||||
d["company_admin"] = {
|
||||
"company_id": pc.id,
|
||||
"company_name": pc.name,
|
||||
}
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
items.append(d)
|
||||
return {"items": items}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user