feat(attendant): 入驻免身份证材料、城市单选、材料后补与订单池同城过滤
入驻申请只收基本信息(身份证选填、材料全可空),服务城市改为单选白名单(北京/上海/天津/西安,默认北京);新增 POST /attendant-application/mine/materials 材料后补与 PATCH /employee/me/service-area 改城市接口;订单池按陪诊师服务城市过滤(本人已接/被共享不限城市),接单与详情二次校验;appId wxapp-escort-admin 更名为 wxapp_companion。
This commit is contained in:
@@ -151,6 +151,37 @@ class HandlerEscortRecord {
|
||||
return employee?.attendantInfo?.stage === "intern" ? "intern" : "certified";
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务城市匹配值
|
||||
*
|
||||
* 入驻/个人资料写入的是「北京市」这类带「市」的值,历史手工数据可能不带「市」,
|
||||
* 查询时同时兼容两种写法,避免存量档案匹配不到订单。
|
||||
*/
|
||||
static cityVariants(areas) {
|
||||
const set = new Set();
|
||||
for (const area of Array.isArray(areas) ? areas : []) {
|
||||
const text = String(area || "").trim();
|
||||
if (!text) continue;
|
||||
const stripped = text.replace(/市$/, "");
|
||||
set.add(text);
|
||||
set.add(stripped);
|
||||
if (stripped) set.add(`${stripped}市`);
|
||||
}
|
||||
return [...set];
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单是否属于陪诊师的服务城市
|
||||
* 未配置城市的存量档案、未填省份的历史订单都保持可见,避免存量数据突然消失
|
||||
*/
|
||||
static matchesServiceArea(record, employee) {
|
||||
const variants = HandlerEscortRecord.cityVariants(employee?.attendantInfo?.serviceAreas);
|
||||
if (!variants.length) return true;
|
||||
const province = String(record?.hospital?.province || "").trim();
|
||||
if (!province) return true;
|
||||
return variants.includes(province);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析用户下单时选择的陪诊师。
|
||||
*
|
||||
@@ -218,7 +249,10 @@ class HandlerEscortRecord {
|
||||
const employeeId = String(employee._id);
|
||||
const sharedWith = Array.isArray(record.attendant?.sharedWith) ? record.attendant.sharedWith : [];
|
||||
if (sharedWith.some((id) => String(id) === employeeId)) return true;
|
||||
if (!record.attendant?.id) return true;
|
||||
if (!record.attendant?.id) {
|
||||
// 未分配订单:只有本服务城市的陪诊师可查看
|
||||
return HandlerEscortRecord.matchesServiceArea(record, employee);
|
||||
}
|
||||
return String(record.attendant.id) === String(userId);
|
||||
}
|
||||
|
||||
@@ -491,13 +525,17 @@ class HandlerEscortRecord {
|
||||
userId: isIntern ? undefined : loginUserId,
|
||||
employeeId: attendantEmployee._id,
|
||||
};
|
||||
// 订单池只展示本服务城市的订单;本人已接/被共享的订单不受城市限制
|
||||
const poolCities = HandlerEscortRecord.cityVariants(
|
||||
attendantEmployee.attendantInfo?.serviceAreas
|
||||
);
|
||||
const scopeValue = String(scope || "");
|
||||
if (scopeValue === "pool") {
|
||||
attendantVisibility = { includeUnassigned: true };
|
||||
attendantVisibility = { includeUnassigned: true, poolCities };
|
||||
} else if (scopeValue === "mine") {
|
||||
attendantVisibility = mineVisibility;
|
||||
} else {
|
||||
attendantVisibility = { includeUnassigned: true, ...mineVisibility };
|
||||
attendantVisibility = { includeUnassigned: true, poolCities, ...mineVisibility };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,6 +681,10 @@ class HandlerEscortRecord {
|
||||
if (record.attendant?.id) {
|
||||
return ResponseUtil.error(ctx, "订单已被其他陪诊师接单", null, 409);
|
||||
}
|
||||
// 订单池只展示本城市订单;这里再挡一次,防止绕过列表直接调接口接单
|
||||
if (!HandlerEscortRecord.matchesServiceArea(record, employee)) {
|
||||
return ResponseUtil.forbidden(ctx, "该订单不在你的服务城市");
|
||||
}
|
||||
|
||||
const profile = employee.profile || {};
|
||||
const updated = await DBModel.EscortRecord.acceptRecord(id, {
|
||||
@@ -1194,7 +1236,7 @@ class HandlerEscortRecord {
|
||||
// 用户端与管理端共用本接口,按调用方 app 区分取消流程:
|
||||
// appId 只用于收紧权限——即使账号同时带管理员角色,从用户端小程序发起的取消
|
||||
// 也必须走取消申请,否则会在 C 端绕过「已确认订单需人工确认」直接退款。
|
||||
// 管理端固定带 appId=wxapp-escort-admin;未带 appId 的历史调用保持原角色判定。
|
||||
// 管理端固定带 appId=wxapp_companion;未带 appId 的历史调用保持原角色判定。
|
||||
const requestAppId = String(ctx.request.body?.appId || "");
|
||||
const isUserApp = requestAppId === "wxapp-escort";
|
||||
const role = isUserApp ? null : await resolveEscortAdminRole(user);
|
||||
|
||||
Reference in New Issue
Block a user