fix(attendant): 订单池审查问题修复
接单排除取消中/已取消订单;已取消订单禁止变动共享名单;取消共享补 404;实习脱敏补收货人姓名与诉求并禁用关键词侧信道。
This commit is contained in:
@@ -222,10 +222,13 @@ class HandlerEscortRecord {
|
||||
if (record.hospital.medicalRecordNo) record.hospital.medicalRecordNo = "接单后可见";
|
||||
}
|
||||
if (record.shippingAddress) {
|
||||
record.shippingAddress.recipientName = HandlerEscortRecord.maskName(record.shippingAddress.recipientName);
|
||||
record.shippingAddress.mobile = HandlerEscortRecord.maskMobile(record.shippingAddress.mobile);
|
||||
if (record.shippingAddress.address) record.shippingAddress.address = "接单后可见";
|
||||
}
|
||||
if (record.inquiry?.medicalHistory) record.inquiry.medicalHistory = "接单后可见";
|
||||
// 诉求是用户自由文本,可能夹带联系方式,一并脱敏
|
||||
if (record.inquiry?.demand) record.inquiry.demand = "接单后可见";
|
||||
}
|
||||
return record;
|
||||
}
|
||||
@@ -414,12 +417,14 @@ class HandlerEscortRecord {
|
||||
let attendantId;
|
||||
let attendantVisibility;
|
||||
let attendantEmployee = null;
|
||||
let isInternAttendant = false;
|
||||
if (mode === "attendant") {
|
||||
attendantEmployee = await HandlerEscortRecord.loadAttendant(loginUserId);
|
||||
if (!attendantEmployee) {
|
||||
return ResponseUtil.forbidden(ctx, "仅在职陪诊师可查看订单");
|
||||
}
|
||||
const isIntern = HandlerEscortRecord.attendantStage(attendantEmployee) === "intern";
|
||||
isInternAttendant = isIntern;
|
||||
// 可见范围由身份决定,前端传什么都会被忽略:
|
||||
// 实习 = 未分配 + 被共享;正式 = 未分配 + 本人已接 + 被共享
|
||||
attendantVisibility = {
|
||||
@@ -482,7 +487,9 @@ class HandlerEscortRecord {
|
||||
payChannel,
|
||||
startDate,
|
||||
endDate,
|
||||
keyword,
|
||||
// 实习看池订单只有脱敏展示,keyword 仍按原文匹配手机号/姓名会形成
|
||||
// 「确认某手机号存在订单」的侧信道,直接忽略其搜索词
|
||||
keyword: mode === "attendant" && isInternAttendant ? undefined : keyword,
|
||||
});
|
||||
|
||||
const records = result.records.map((record) => {
|
||||
@@ -548,6 +555,13 @@ class HandlerEscortRecord {
|
||||
|
||||
const record = await DBModel.EscortRecord.findById(id);
|
||||
if (!record || record.deletedAt) return ResponseUtil.notFound(ctx, "陪诊记录不存在");
|
||||
// 取消中/已取消的订单不进入接单:取消一旦被确认,刚接单的陪诊师会直接失去订单
|
||||
if (record.cancelStatus === "cancelled" || record.status === "cancelled") {
|
||||
return ResponseUtil.error(ctx, "订单已取消,无法接单", null, 409);
|
||||
}
|
||||
if (record.cancelStatus === "requested") {
|
||||
return ResponseUtil.error(ctx, "订单取消申请确认中,暂不能接单", null, 409);
|
||||
}
|
||||
if (record.attendant?.id) {
|
||||
return ResponseUtil.error(ctx, "订单已被其他陪诊师接单", null, 409);
|
||||
}
|
||||
@@ -586,6 +600,9 @@ class HandlerEscortRecord {
|
||||
|
||||
const record = await DBModel.EscortRecord.findById(id);
|
||||
if (!record) return ResponseUtil.notFound(ctx, "陪诊记录不存在");
|
||||
if (record.cancelStatus === "cancelled" || record.status === "cancelled") {
|
||||
return ResponseUtil.error(ctx, "订单已取消,无法共享", null, 409);
|
||||
}
|
||||
if (String(record.attendant?.id || "") !== String(userId)) {
|
||||
return ResponseUtil.forbidden(ctx, "只有接单陪诊师可以共享该订单");
|
||||
}
|
||||
@@ -629,6 +646,13 @@ class HandlerEscortRecord {
|
||||
const employee = await HandlerEscortRecord.loadAttendant(userId);
|
||||
if (!employee) return ResponseUtil.forbidden(ctx, "仅在职陪诊师可操作共享");
|
||||
|
||||
// 与 shareRecord 对齐:订单不存在按 404,已取消不允许再操作共享名单
|
||||
const record = await DBModel.EscortRecord.findById(id);
|
||||
if (!record) return ResponseUtil.notFound(ctx, "陪诊记录不存在");
|
||||
if (record.cancelStatus === "cancelled" || record.status === "cancelled") {
|
||||
return ResponseUtil.error(ctx, "订单已取消,无法操作共享", null, 409);
|
||||
}
|
||||
|
||||
const employeeIds = HandlerEscortRecord.parseShareEmployeeIds(ctx.request.body || {});
|
||||
if (employeeIds.length === 0) return ResponseUtil.badRequest(ctx, "请选择要取消共享的陪诊师");
|
||||
|
||||
|
||||
@@ -478,14 +478,14 @@ EscortRecordSchema.statics.findByIdempotencyKey = async function (userId, idempo
|
||||
};
|
||||
|
||||
// 接单:只有「未分配」的订单能被接走,条件更新保证并发下只有一个陪诊师成功。
|
||||
// 与支付状态无关:订单是否付款不影响接单。
|
||||
// 与支付状态无关:订单是否付款不影响接单;取消中(requested)与已取消订单不可接。
|
||||
EscortRecordSchema.statics.acceptRecord = async function (id, attendant) {
|
||||
return await this.findOneAndUpdate(
|
||||
{
|
||||
_id: id,
|
||||
deletedAt: null,
|
||||
"attendant.id": null,
|
||||
cancelStatus: { $ne: "cancelled" },
|
||||
cancelStatus: { $nin: ["cancelled", "requested"] },
|
||||
status: { $ne: "cancelled" },
|
||||
},
|
||||
{
|
||||
@@ -501,10 +501,10 @@ EscortRecordSchema.statics.acceptRecord = async function (id, attendant) {
|
||||
);
|
||||
};
|
||||
|
||||
// 共享 / 取消共享:只有当前接单陪诊师本人能操作
|
||||
// 共享 / 取消共享:只有当前接单陪诊师本人能操作,已取消订单不再变动共享名单
|
||||
EscortRecordSchema.statics.addSharedWith = async function (id, attendantId, employeeIds) {
|
||||
return await this.findOneAndUpdate(
|
||||
{ _id: id, deletedAt: null, "attendant.id": attendantId },
|
||||
{ _id: id, deletedAt: null, "attendant.id": attendantId, cancelStatus: { $ne: "cancelled" }, status: { $ne: "cancelled" } },
|
||||
{
|
||||
$addToSet: { "attendant.sharedWith": { $each: employeeIds } },
|
||||
$set: { "meta.updatetime": Date.now() },
|
||||
@@ -515,7 +515,7 @@ EscortRecordSchema.statics.addSharedWith = async function (id, attendantId, empl
|
||||
|
||||
EscortRecordSchema.statics.removeSharedWith = async function (id, attendantId, employeeIds) {
|
||||
return await this.findOneAndUpdate(
|
||||
{ _id: id, deletedAt: null, "attendant.id": attendantId },
|
||||
{ _id: id, deletedAt: null, "attendant.id": attendantId, cancelStatus: { $ne: "cancelled" }, status: { $ne: "cancelled" } },
|
||||
{
|
||||
$pull: { "attendant.sharedWith": { $in: employeeIds } },
|
||||
$set: { "meta.updatetime": Date.now() },
|
||||
|
||||
@@ -21,7 +21,7 @@ function buildRecord(overrides = {}) {
|
||||
patient: { name: "张三", mobile: "13800138000" },
|
||||
escort: { serviceId: 1, serviceName: "全天陪诊" },
|
||||
hospital: { name: "北京协和医院", address: "北京市东城区", medicalRecordNo: "MR0001" },
|
||||
shippingAddress: { mobile: "13900139000", address: "北京市西城区" },
|
||||
shippingAddress: { recipientName: "张三", mobile: "13900139000", address: "北京市西城区" },
|
||||
inquiry: { medicalHistory: "高血压", demand: "陪同检查" },
|
||||
schedule: {
|
||||
date: new Date("2026-12-01T00:00:00.000Z"),
|
||||
@@ -47,9 +47,9 @@ function buildEmployee(overrides = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function createCtx({ body = {}, user, params = { id: RECORD_ID } } = {}) {
|
||||
function createCtx({ body = {}, query = {}, user, params = { id: RECORD_ID } } = {}) {
|
||||
return {
|
||||
request: { query: {}, body },
|
||||
request: { query, body },
|
||||
params,
|
||||
state: { user: user ?? { _id: CERT_USER_ID } },
|
||||
headers: {},
|
||||
@@ -96,13 +96,18 @@ test("实习陪诊师看未分配订单:可见范围含未分配且按 employe
|
||||
|
||||
await withModel("Employee", employeeFindOneStub(intern), () =>
|
||||
withModel("EscortRecord", recordStub, async () => {
|
||||
const ctx = createCtx({ user: { _id: INTERN_USER_ID } });
|
||||
const ctx = createCtx({
|
||||
user: { _id: INTERN_USER_ID },
|
||||
// 实习传关键词想按手机号搜池订单:应被服务端忽略(防侧信道)
|
||||
query: { keyword: "13800138000" },
|
||||
});
|
||||
await new HandlerEscortRecord().getAttendantRecords(ctx);
|
||||
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assert.equal(captured.attendantVisibility.includeUnassigned, true);
|
||||
assert.equal(captured.attendantVisibility.userId, undefined);
|
||||
assert.equal(String(captured.attendantVisibility.employeeId), INTERN_EMPLOYEE_ID);
|
||||
assert.equal(captured.keyword, undefined);
|
||||
|
||||
const record = ctx.body.data.records[0];
|
||||
assert.equal(record.isPoolOrder, true);
|
||||
@@ -111,7 +116,9 @@ test("实习陪诊师看未分配订单:可见范围含未分配且按 employe
|
||||
assert.equal(record.patient.mobile, "138****8000");
|
||||
assert.equal(record.hospital.address, "接单后可见");
|
||||
assert.equal(record.hospital.medicalRecordNo, "接单后可见");
|
||||
assert.equal(record.shippingAddress.recipientName, "张**");
|
||||
assert.equal(record.inquiry.medicalHistory, "接单后可见");
|
||||
assert.equal(record.inquiry.demand, "接单后可见");
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -130,12 +137,17 @@ test("正式陪诊师可见本人已接与被共享订单,未分配同样在
|
||||
|
||||
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
|
||||
withModel("EscortRecord", recordStub, async () => {
|
||||
const ctx = createCtx({ user: { _id: CERT_USER_ID } });
|
||||
const ctx = createCtx({
|
||||
user: { _id: CERT_USER_ID },
|
||||
// 正式陪诊师可见完整信息,keyword 正常生效
|
||||
query: { keyword: "协和" },
|
||||
});
|
||||
await new HandlerEscortRecord().getAttendantRecords(ctx);
|
||||
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assert.equal(captured.attendantVisibility.includeUnassigned, true);
|
||||
assert.equal(String(captured.attendantVisibility.userId), CERT_USER_ID);
|
||||
assert.equal(captured.keyword, "协和");
|
||||
|
||||
const item = ctx.body.data.records[0];
|
||||
assert.equal(item.attendantSharedToMe, true);
|
||||
@@ -317,3 +329,72 @@ test("实习陪诊师可看未分配订单详情,但不能看他人已接且
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test("取消中/已取消订单不能接单", async () => {
|
||||
const cases = [
|
||||
{ cancelStatus: "requested", msg: "取消申请确认中" },
|
||||
{ cancelStatus: "cancelled", msg: "订单已取消" },
|
||||
{ status: "cancelled", msg: "订单已取消" },
|
||||
];
|
||||
for (const override of cases) {
|
||||
let accepted = 0;
|
||||
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
|
||||
withModel("EscortRecord", {
|
||||
findById: async () => buildRecord(override),
|
||||
acceptRecord: async () => {
|
||||
accepted += 1;
|
||||
return buildRecord();
|
||||
},
|
||||
}, async () => {
|
||||
const ctx = createCtx({ user: { _id: CERT_USER_ID } });
|
||||
await new HandlerEscortRecord().acceptRecord(ctx);
|
||||
|
||||
assert.equal(ctx.body.code, 409, `场景 ${JSON.stringify(override)} 应返回 409`);
|
||||
assert.equal(accepted, 0);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("已取消订单不能共享", async () => {
|
||||
let shared = 0;
|
||||
const recordStub = {
|
||||
findById: async () => buildRecord({
|
||||
cancelStatus: "cancelled",
|
||||
attendant: { id: CERT_USER_ID, name: "李四", sharedWith: [] },
|
||||
}),
|
||||
addSharedWith: async () => {
|
||||
shared += 1;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
|
||||
withModel("EscortRecord", recordStub, async () => {
|
||||
const ctx = createCtx({
|
||||
user: { _id: CERT_USER_ID },
|
||||
body: { employeeIds: [INTERN_EMPLOYEE_ID] },
|
||||
});
|
||||
await new HandlerEscortRecord().shareRecord(ctx);
|
||||
|
||||
assert.equal(ctx.body.code, 409);
|
||||
assert.equal(shared, 0);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test("取消共享时订单不存在返回 404", async () => {
|
||||
await withModel("Employee", employeeFindOneStub(buildEmployee()), () =>
|
||||
withModel("EscortRecord", {
|
||||
findById: async () => null,
|
||||
}, async () => {
|
||||
const ctx = createCtx({
|
||||
user: { _id: CERT_USER_ID },
|
||||
body: { employeeIds: [INTERN_EMPLOYEE_ID] },
|
||||
});
|
||||
await new HandlerEscortRecord().unshareRecord(ctx);
|
||||
|
||||
assert.equal(ctx.body.code, 404);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user