feat: 订单获取链路收尾:管理端指派、接单开关与用户指定陪诊师

This commit is contained in:
lik
2026-11-10 15:13:48 +08:00
parent 78138a417b
commit b160102f12
8 changed files with 725 additions and 32 deletions
+62 -11
View File
@@ -1,5 +1,6 @@
import mongoose from "mongoose";
import { DBModel } from "../models/index.js";
import { MY_EMPLOYEE_SELECT } from "../models/schema/employee.js";
import ResponseUtil from "../utils/responseUtil.js";
/**
@@ -123,8 +124,8 @@ class HandlerEmployee {
specialties: info.specialties || [],
serviceAreas: info.serviceAreas || [],
languages: info.languages || [],
// 注:GB/T 4.2.1.5 要求公示的「累计服务次数」暂缺——orderCount 全项目无写入点(恒 0),
// 展示恒 0 反而误导,已从公示输出摘除;待 plan.md B8 补写入点后恢复
// 累计接单数由陪诊师接单 / 管理员指派成功时回写,可用于公示排序
orderCount: info.orderCount || 0,
introduction: employee.introduction || "",
};
}
@@ -140,9 +141,9 @@ class HandlerEmployee {
const pageSize = Math.min(Math.max(1, rawSize), HandlerEmployee.MAX_PAGE_SIZE);
// 只取在职且已转正的陪诊员,实习不对外公示。
// 排序不按 attendantInfo.rating / orderCount(均无可信来源),暂只按服务年限
// 排序:服务年限优先,累计接单数次之;rating 无写入点,不参与排序
const list = await DBModel.Employee.find(HandlerEmployee.publicAttendantFilter())
.sort({ "work.workYears": -1 })
.sort({ "work.workYears": -1, "attendantInfo.orderCount": -1 })
.skip((page - 1) * pageSize)
.limit(pageSize)
.exec();
@@ -247,6 +248,15 @@ class HandlerEmployee {
}
}
// 阶段/等级归一化后随档案返回,小程序据此展示身份文案与只读提示。
// canAcceptOrder 只由 stage 决定,等级不参与鉴权
static decorateMyEmployee(employee) {
const level = HandlerEmployee.normalizeAttendantLevel(employee.attendantInfo);
employee.attendantInfo = { ...(employee.attendantInfo || {}), ...level };
employee.canAcceptOrder = level.stage === "certified";
return employee;
}
// 当前登录账号的员工档案:登录即可访问,供管理端判定陪诊员身份。
// 只返回员工档案本身,不重复做管理员判定(管理员身份由管理端按登录响应的 apps 判定)
async getMyEmployee(ctx) {
@@ -257,7 +267,7 @@ class HandlerEmployee {
}
const employee = await DBModel.Employee.findOne({ userId })
.select("employeeNo role status profile.name profile.sex profile.phone profile.avatar attendantInfo")
.select(MY_EMPLOYEE_SELECT)
.lean()
.exec();
@@ -266,13 +276,54 @@ class HandlerEmployee {
return ResponseUtil.success(ctx, { employee: null }, "查询成功");
}
// 阶段/等级归一化后随档案返回,小程序据此展示身份文案与只读提示。
// canAcceptOrder 只由 stage 决定,等级不参与鉴权
const level = HandlerEmployee.normalizeAttendantLevel(employee.attendantInfo);
employee.attendantInfo = { ...(employee.attendantInfo || {}), ...level };
employee.canAcceptOrder = level.stage === "certified";
return ResponseUtil.success(
ctx,
{ employee: HandlerEmployee.decorateMyEmployee(employee) },
"查询成功"
);
} catch (err) {
return ResponseUtil.internalError(ctx, err);
}
}
return ResponseUtil.success(ctx, { employee }, "查询成功");
// 首页接单开关落库:只允许在职且已转正的陪诊师切换
async updateMyOnlineStatus(ctx) {
try {
const userId = ctx.state.user?._id;
if (!userId) {
return ResponseUtil.unauthorized(ctx, "登录已失效");
}
const isOnline = ctx.request.body?.isOnline;
if (typeof isOnline !== "boolean") {
return ResponseUtil.badRequest(ctx, "接单状态必须为布尔值");
}
const employee = await DBModel.Employee.findOne({
userId,
role: "attendant",
status: "active",
})
.select("attendantInfo.stage")
.lean()
.exec();
if (!employee) {
return ResponseUtil.forbidden(ctx, "仅在职陪诊师可切换接单状态");
}
if (HandlerEmployee.normalizeAttendantLevel(employee.attendantInfo).stage === "intern") {
return ResponseUtil.forbidden(ctx, "实习陪诊师暂不能接单");
}
const updated = await DBModel.Employee.setOnlineByUserId(userId, isOnline);
if (!updated) {
return ResponseUtil.forbidden(ctx, "仅在职陪诊师可切换接单状态");
}
return ResponseUtil.success(
ctx,
{ employee: HandlerEmployee.decorateMyEmployee(updated) },
isOnline ? "已开启接单" : "已暂停接单"
);
} catch (err) {
return ResponseUtil.internalError(ctx, err);
}