feat(attendant): 入驻默认实习阶段并新增阶段等级调整接口
- employee.attendantInfo 增加 stage/grade/star,存量档案按正式青铜归一化 - 入驻审批仅在新建档案时写 intern,重新激活保留原阶段 - /employee/me 返回阶段等级与 canAcceptOrder - C 端公示列表与详情排除实习陪诊师 - 新增 PATCH /employee/:id/level:转正、调级、钻石设星
This commit is contained in:
+112
-12
@@ -30,6 +30,32 @@ const MIN_PUBLIC_REVIEW_COUNT = 5;
|
||||
class HandlerEmployee {
|
||||
// 公示列表单页上限:避免一次请求把整张表拖出来
|
||||
static MAX_PAGE_SIZE = 50;
|
||||
|
||||
// 陪诊师阶段与等级:等级只做展示/排序,权限只看 stage
|
||||
static STAGES = ["intern", "certified"];
|
||||
static GRADES = ["bronze", "silver", "gold", "diamond"];
|
||||
|
||||
// 公示口径:实习陪诊师不对外展示(不能被用户选择)。
|
||||
// stage 用 $ne 而非 $eq:存量档案没有该字段,一律视为正式
|
||||
static publicAttendantFilter() {
|
||||
return {
|
||||
role: "attendant",
|
||||
status: "active",
|
||||
"attendantInfo.stage": { $ne: "intern" },
|
||||
};
|
||||
}
|
||||
|
||||
// 阶段/等级归一化:存量档案缺字段时按 certified + bronze 处理
|
||||
static normalizeAttendantLevel(info = {}) {
|
||||
const stage = HandlerEmployee.STAGES.includes(info.stage) ? info.stage : "certified";
|
||||
const grade = HandlerEmployee.GRADES.includes(info.grade) ? info.grade : "bronze";
|
||||
const rawStar = Number(info.star);
|
||||
const star = grade === "diamond" && Number.isFinite(rawStar)
|
||||
? Math.min(Math.max(Math.trunc(rawStar), 0), 5)
|
||||
: 0;
|
||||
return { stage, grade, star };
|
||||
}
|
||||
|
||||
// 姓名脱敏:只留姓 + 「陪诊师」,不给全名,降低私下联系(跳单)的可能
|
||||
static maskName(name) {
|
||||
const trimmed = String(name || "").trim();
|
||||
@@ -97,7 +123,8 @@ class HandlerEmployee {
|
||||
specialties: info.specialties || [],
|
||||
serviceAreas: info.serviceAreas || [],
|
||||
languages: info.languages || [],
|
||||
orderCount: info.orderCount || 0,
|
||||
// 注:GB/T 4.2.1.5 要求公示的「累计服务次数」暂缺——orderCount 全项目无写入点(恒 0),
|
||||
// 展示恒 0 反而误导,已从公示输出摘除;待 plan.md B8 补写入点后恢复
|
||||
introduction: employee.introduction || "",
|
||||
};
|
||||
}
|
||||
@@ -112,13 +139,10 @@ class HandlerEmployee {
|
||||
const rawSize = parseInt(ctx.request.query.pageSize) || 50;
|
||||
const pageSize = Math.min(Math.max(1, rawSize), HandlerEmployee.MAX_PAGE_SIZE);
|
||||
|
||||
// 只取在职陪诊员。
|
||||
// 排序不按 attendantInfo.rating(无可信来源),改按服务年限 / 累计接单数
|
||||
const list = await DBModel.Employee.find({
|
||||
role: "attendant",
|
||||
status: "active",
|
||||
})
|
||||
.sort({ "work.workYears": -1, "attendantInfo.orderCount": -1 })
|
||||
// 只取在职且已转正的陪诊员,实习不对外公示。
|
||||
// 排序不按 attendantInfo.rating / orderCount(均无可信来源),暂只按服务年限
|
||||
const list = await DBModel.Employee.find(HandlerEmployee.publicAttendantFilter())
|
||||
.sort({ "work.workYears": -1 })
|
||||
.skip((page - 1) * pageSize)
|
||||
.limit(pageSize)
|
||||
.exec();
|
||||
@@ -148,8 +172,7 @@ class HandlerEmployee {
|
||||
|
||||
const employee = await DBModel.Employee.findOne({
|
||||
_id: id,
|
||||
role: "attendant",
|
||||
status: "active",
|
||||
...HandlerEmployee.publicAttendantFilter(),
|
||||
}).exec();
|
||||
|
||||
if (!employee) {
|
||||
@@ -186,12 +209,22 @@ class HandlerEmployee {
|
||||
}
|
||||
|
||||
const employee = await DBModel.Employee.findOne({ userId })
|
||||
.select("employeeNo role status profile.name profile.sex profile.phone profile.avatar")
|
||||
.select("employeeNo role status profile.name profile.sex profile.phone profile.avatar attendantInfo")
|
||||
.lean()
|
||||
.exec();
|
||||
|
||||
// 无员工档案不是错误:管理员账号通常没有 Employee 记录
|
||||
return ResponseUtil.success(ctx, { employee: employee || null }, "查询成功");
|
||||
if (!employee) {
|
||||
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 }, "查询成功");
|
||||
} catch (err) {
|
||||
return ResponseUtil.internalError(ctx, err);
|
||||
}
|
||||
@@ -413,6 +446,73 @@ class HandlerEmployee {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 陪诊师阶段/等级调整:实习转正、青铜~钻石调级、钻石设星
|
||||
*
|
||||
* 独立入口而不是并入通用 PUT:等级只做展示与排序、不参与鉴权,
|
||||
* 单独收口可避免误改档案其他字段
|
||||
*/
|
||||
async updateEmployeeLevel(ctx) {
|
||||
try {
|
||||
const { id } = ctx.params;
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
return ResponseUtil.badRequest(ctx, "员工ID不合法");
|
||||
}
|
||||
|
||||
const body = ctx.request.body || {};
|
||||
const flat = {};
|
||||
|
||||
if (body.stage !== undefined) {
|
||||
if (!HandlerEmployee.STAGES.includes(body.stage)) {
|
||||
return ResponseUtil.badRequest(ctx, "陪诊师阶段取值不正确");
|
||||
}
|
||||
flat["attendantInfo.stage"] = body.stage;
|
||||
}
|
||||
if (body.grade !== undefined) {
|
||||
if (!HandlerEmployee.GRADES.includes(body.grade)) {
|
||||
return ResponseUtil.badRequest(ctx, "陪诊师等级取值不正确");
|
||||
}
|
||||
flat["attendantInfo.grade"] = body.grade;
|
||||
}
|
||||
if (body.star !== undefined) {
|
||||
const star = Number(body.star);
|
||||
if (!Number.isInteger(star) || star < 0 || star > 5) {
|
||||
return ResponseUtil.badRequest(ctx, "星级必须是 0-5 的整数");
|
||||
}
|
||||
flat["attendantInfo.star"] = star;
|
||||
}
|
||||
if (!Object.keys(flat).length) {
|
||||
return ResponseUtil.badRequest(ctx, "没有可更新的字段");
|
||||
}
|
||||
|
||||
const employee = await DBModel.Employee.findById(id)
|
||||
.select("role attendantInfo")
|
||||
.lean()
|
||||
.exec();
|
||||
if (!employee) {
|
||||
return ResponseUtil.notFound(ctx, "员工不存在");
|
||||
}
|
||||
if (employee.role !== "attendant") {
|
||||
return ResponseUtil.badRequest(ctx, "只有陪诊师可设置阶段与等级");
|
||||
}
|
||||
|
||||
const current = HandlerEmployee.normalizeAttendantLevel(employee.attendantInfo);
|
||||
const nextGrade = flat["attendantInfo.grade"] || current.grade;
|
||||
if (flat["attendantInfo.star"] !== undefined && nextGrade !== "diamond") {
|
||||
return ResponseUtil.badRequest(ctx, "只有钻石等级可以设置星级");
|
||||
}
|
||||
// 离开钻石时星级归零,避免展示残留的星星
|
||||
if (flat["attendantInfo.grade"] && current.grade === "diamond" && nextGrade !== "diamond") {
|
||||
flat["attendantInfo.star"] = 0;
|
||||
}
|
||||
|
||||
const updated = await DBModel.Employee.updateEmployee(id, flat);
|
||||
return ResponseUtil.success(ctx, { employee: updated }, "等级已更新");
|
||||
} catch (err) {
|
||||
return ResponseUtil.internalError(ctx, err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入校验
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user