Compare commits

...
2 Commits
Author SHA1 Message Date
lik 814a58b306 feat(attendant): 公示接口返回陪诊师真实姓名
用户下单前需要按姓名指定陪诊师,公示列表不再脱敏;共享候选等内部接口的姓名口径保持不变。
2026-11-11 21:03:44 +08:00
lik cd3ff09a16 fix(escort): 管理员下单也按员工档案回填陪诊师快照
下单指定陪诊师时不再按 isAdmin 跳过解析,避免客户端原始 employeeId 落库、姓名电话为空,导致详情页误显示待分配;补充管理员下单的回归用例。
2026-11-11 21:03:41 +08:00
3 changed files with 37 additions and 21 deletions
+2 -9
View File
@@ -58,13 +58,6 @@ class HandlerEmployee {
return { stage, grade, star };
}
// 姓名脱敏:只留姓 + 「陪诊师」,不给全名,降低私下联系(跳单)的可能
static maskName(name) {
const trimmed = String(name || "").trim();
if (!trimmed) return "陪诊师";
return trimmed.slice(0, 1) + "陪诊师";
}
// 日期 → YYYY-MM-DD;无值或非法值返回空串,前端按空串隐藏该行
static formatDate(value) {
if (!value) return "";
@@ -107,7 +100,7 @@ class HandlerEmployee {
return {
id: employee._id,
name: HandlerEmployee.maskName(profile.name),
name: profile.name || "陪诊师",
avatar: profile.avatar || "",
sex: profile.sex || "",
// 年龄由前端换算,这里只下发原料。刻意走 formatDate 而不是原始 Date:
@@ -202,7 +195,7 @@ class HandlerEmployee {
}
// 共享候选名单:所有在职陪诊师(含实习),供接单陪诊师把订单共享出去。
// 与公示接口不同:这里不做姓名脱敏,也不排除实习,但必须本人是在职陪诊师。
// 不排除实习,但必须本人是在职陪诊师。
async getShareableAttendants(ctx) {
try {
const userId = ctx.state.user?._id;
+9 -8
View File
@@ -913,18 +913,19 @@ class HandlerEscortRecord {
const addressResult = HandlerEscortRecord.buildShippingAddress(body.shippingAddress, profile);
const payload = HandlerEscortRecord.pickFields(body);
// 用户可在下单时指定陪诊师:只认 employeeId,快照字段由服务端回填。
// 下单时指定陪诊师:只认 employeeId,快照字段由服务端回填。
// 管理员用用户端下单也要走这条解析:否则会把客户端原样的 { employeeId }
// 落库(name/mobile 走默认空串、id 缺失),详情页会误显示「待分配」。
// 未指定则清空,订单进入公共订单池等待抢单或管理端指派。
let selectedEmployee = null;
if (!isAdmin) {
if (body.attendant?.employeeId) {
const selected = await HandlerEscortRecord.resolveSelectedAttendant(body.attendant);
if (selected.error) return ResponseUtil.badRequest(ctx, selected.error);
if (selected.employee) {
selectedEmployee = selected.employee;
payload.attendant = { ...selected.snapshot, sharedWith: [] };
} else {
delete payload.attendant;
}
selectedEmployee = selected.employee;
payload.attendant = { ...selected.snapshot, sharedWith: [] };
} else if (!isAdmin) {
// 用户端不接受客户端自带的姓名 / 电话快照
delete payload.attendant;
}
// 归属以档案为准:管理员传入的 userId 一律忽略,无归属档案留空
payload.userId = orderUserId;
+26 -4
View File
@@ -49,11 +49,11 @@ function buildBody(attendant) {
};
}
function createCtx(body) {
function createCtx(body, user = { _id: USER_ID }) {
return {
request: { query: {}, body },
params: {},
state: { user: { _id: USER_ID } },
state: { user },
headers: {},
status: 200,
body: null,
@@ -83,7 +83,7 @@ function employeeFindOneStub(employee, overrides = {}) {
};
}
async function runCreate({ attendant, employee = buildEmployee() } = {}) {
async function runCreate({ attendant, employee = buildEmployee(), user } = {}) {
const calls = { payload: null, bumped: null };
const recordStub = {
findByIdempotencyKey: async () => null,
@@ -99,7 +99,7 @@ async function runCreate({ attendant, employee = buildEmployee() } = {}) {
},
});
const ctx = createCtx(buildBody(attendant));
const ctx = createCtx(buildBody(attendant), user);
await withModel("HealthProfile", { findProfileById: async () => buildProfile() }, () =>
withModel("EscortRecord", recordStub, () =>
withModel("Employee", employeeStub, () => new HandlerEscortRecord().createRecord(ctx))
@@ -125,6 +125,28 @@ test("用户下单指定陪诊师:服务端回填快照并累加接单数", as
assert.equal(calls.bumped, EMPLOYEE_ID);
});
test("管理员用用户端下单指定陪诊师:同样回填快照而不是落库 employeeId", async () => {
const admin = {
_id: USER_ID,
apps: [{ appId: "web-escort-admin", roles: ["admin"], status: "active" }],
};
const { ctx, calls } = await runCreate({
user: admin,
attendant: { employeeId: EMPLOYEE_ID },
});
assert.equal(ctx.body.code, 0);
assert.deepEqual(calls.payload.attendant, {
id: EMPLOYEE_USER_ID,
name: "李四",
sex: "female",
mobile: "13700137000",
sharedWith: [],
});
assert.equal(calls.payload.attendant.employeeId, undefined);
assert.equal(calls.bumped, EMPLOYEE_ID);
});
test("用户不指定陪诊师:订单进入公共池,不写陪诊师、不累加接单数", async () => {
const { ctx, calls } = await runCreate({ attendant: null });