feat(inbox): 处理备注推送货主群、群类型清空接口与群按ID管理
- afterSale.handleWorkOrder: 处理备注发送到对应货主售后群(notifyGroup,内部流程不推),响应 notified_groups - inbox.group.reset: 新增清空群类型接口(入参群主键ID),权限迁移 556 - 群登记以 group_id 为准: 移除同名群回填,群ID不存在直接新建,store_id/群信息均按 group_id 精确匹配 - changeAddr: 已有工单也把客户原文转发快递群并升级 pending_feedback(仅 pending 可升级) - handleExpressFeedback: 工单描述售后类型显示中文(订单.物流异常) - 同步 methods/system.json 与 changes 记录
This commit is contained in:
parent
a8200a3a35
commit
e6f4d9f341
@ -2173,7 +2173,10 @@ class InboxFunctionsService extends Service {
|
||||
|
||||
// 第三步:创建工单(含原文)并映射 waybill_id → 工单号
|
||||
const createdNos = [];
|
||||
const waybillToAsNo = {}; // waybill_id → after_sale_no 映射
|
||||
const waybillToAsNo = {}; // waybill_id → after_sale_no 映射(新建 + 已存在)
|
||||
for (const r of existingASList) {
|
||||
waybillToAsNo[r.waybill_id] = r.after_sale_no;
|
||||
}
|
||||
if (toCreate.length > 0) {
|
||||
const creatorLabel = [ groupName, userName ].filter(Boolean).join('-') || 'AI系统';
|
||||
for (const e of toCreate) {
|
||||
@ -2209,8 +2212,9 @@ class InboxFunctionsService extends Service {
|
||||
}
|
||||
|
||||
// 第四步:原文转发到对应快递的售后群(按快递分组)
|
||||
// 新建与已存在的工单都转发:客户再次发来的原文是快递需要的最新诉求
|
||||
const expressByCode = {};
|
||||
for (const e of toCreate) {
|
||||
for (const e of expressList) {
|
||||
const code = e.logistics_code || '__unknown__';
|
||||
if (!expressByCode[code]) {
|
||||
expressByCode[code] = { interfaceId: e.logistics_interface_id, waybills: [] };
|
||||
@ -2245,7 +2249,7 @@ class InboxFunctionsService extends Service {
|
||||
});
|
||||
notifiedTotal += 1;
|
||||
}
|
||||
toCreate
|
||||
expressList
|
||||
.filter(e => (e.logistics_code || '__unknown__') === code)
|
||||
.forEach(e => notifiedWaybillIds.add(e.id));
|
||||
} catch (e) {
|
||||
@ -2253,8 +2257,11 @@ class InboxFunctionsService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
// 第五步:有转发通知的工单升级 pending_feedback + 跟踪时限
|
||||
const notifiedAsNos = createdNos.filter((asNo, idx) => notifiedWaybillIds.has(toCreate[idx].id));
|
||||
// 第五步:有转发通知的工单升级 pending_feedback + 跟踪时限(新建与已有工单,仅 pending 状态升级)
|
||||
const notifiedAsNos = expressList
|
||||
.filter(e => notifiedWaybillIds.has(e.id))
|
||||
.map(e => waybillToAsNo[e.id])
|
||||
.filter(Boolean);
|
||||
if (notifiedAsNos.length > 0) {
|
||||
try {
|
||||
const hours = await ctx.service.systems.afterSale._resolveFollowupHours(
|
||||
@ -2266,7 +2273,12 @@ class InboxFunctionsService extends Service {
|
||||
followup_at: ctx.app.Sequelize.literal(`DATE_ADD(NOW(), INTERVAL ${hours} HOUR)`),
|
||||
role_group: 'customer_service',
|
||||
},
|
||||
{ where: { after_sale_no: { [ctx.app.Sequelize.Op.in]: notifiedAsNos } } }
|
||||
{
|
||||
where: {
|
||||
after_sale_no: { [ctx.app.Sequelize.Op.in]: notifiedAsNos },
|
||||
status: 'pending',
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
ctx.logger.warn(`[inbox functions] 改地址/催退回更新工单状态失败: ${e.message}`);
|
||||
@ -3331,6 +3343,15 @@ class InboxFunctionsService extends Service {
|
||||
const asType = String(params.as_type || 'order').trim() || 'order';
|
||||
const asSubType = String(params.as_sub_type || 'logistics_issue').trim() || 'logistics_issue';
|
||||
|
||||
// 工单详细描述中的售后类型/子类型显示中文名称(存储仍用英文编码)
|
||||
const asTypesMeta = (ctx.model.AfterSale && ctx.model.AfterSale.AFTER_SALE_TYPES) || [];
|
||||
const asTypeMeta = asTypesMeta.find(t => t.type === asType);
|
||||
const asTypeName = (asTypeMeta && asTypeMeta.name) || asType;
|
||||
const asSubTypeMeta = asTypeMeta && Array.isArray(asTypeMeta.subType)
|
||||
? asTypeMeta.subType.find(s => s.value === asSubType)
|
||||
: null;
|
||||
const asSubTypeName = (asSubTypeMeta && asSubTypeMeta.name) || asSubType;
|
||||
|
||||
if (!raw) return { success: false, error: '请提供运单号' };
|
||||
if (!warehouseId) return { success: false, error: '无法获取仓库信息' };
|
||||
|
||||
@ -3419,7 +3440,7 @@ class InboxFunctionsService extends Service {
|
||||
const description = [
|
||||
`运单号: ${e.waybill_code}`,
|
||||
`快递公司: ${e.logistics_name || '未知'}`,
|
||||
`售后类型: ${asType}.${asSubType}`,
|
||||
`售后类型: ${asTypeName}.${asSubTypeName}`,
|
||||
'来源: 快递群反馈',
|
||||
feedbackMsgContent ? `原文: ${feedbackMsgContent}` : '',
|
||||
].filter(Boolean).join('\n');
|
||||
@ -3553,6 +3574,7 @@ class InboxFunctionsService extends Service {
|
||||
where: {
|
||||
group_id: { [ctx.app.Sequelize.Op.in]: candidateGroupIds },
|
||||
warehouse_id: warehouseId,
|
||||
is_blocked: 0,
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -28,7 +28,7 @@ class InboxProcessorService extends Service {
|
||||
* @param {string} groupId 外部群ID
|
||||
* @param {number} warehouseId 仓库ID
|
||||
* @param {Object|null} msgExtData 入站消息的 ext_data
|
||||
* @return {Promise<{group_type: string, sub_type: string, ai_enabled: number, ext_data: Object|null}>}
|
||||
* @return {Promise<{group_type: string, sub_type: string, ai_enabled: number, ext_data: Object|null}>} 群类型/子类型/AI开关/扩展数据
|
||||
*/
|
||||
async _loadGroupInfo(groupId, warehouseId, msgExtData) {
|
||||
const { ctx } = this;
|
||||
|
||||
@ -165,27 +165,19 @@ class InboxReceiverService extends Service {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 群ID不存在:优先兼容同名群回填群ID;都没有才新建。
|
||||
// 注意表上已无 (group_name, warehouse_id) 唯一索引,名称维度不再保证唯一。
|
||||
const byName = await ctx.model.InboxGroup.findOne({
|
||||
where: { group_name: groupName, warehouse_id: warehouseId },
|
||||
// 群ID不存在:按群ID直接新建(群以ID为准,不按名称匹配既有群)
|
||||
await ctx.model.InboxGroup.create({
|
||||
group_name: groupName,
|
||||
group_id: extGroupId,
|
||||
warehouse_id: warehouseId,
|
||||
store_id: storeId || null,
|
||||
source_type: sourceType,
|
||||
source_extra: data.source_extra || null,
|
||||
ai_enabled: 0,
|
||||
});
|
||||
if (byName) {
|
||||
await byName.update({ group_id: extGroupId });
|
||||
ctx.logger.info(
|
||||
`[inbox] 同名群回填群ID group_id=${extGroupId} name=${groupName}`
|
||||
);
|
||||
} else {
|
||||
await ctx.model.InboxGroup.create({
|
||||
group_name: groupName,
|
||||
group_id: extGroupId,
|
||||
warehouse_id: warehouseId,
|
||||
store_id: storeId || null,
|
||||
source_type: sourceType,
|
||||
source_extra: data.source_extra || null,
|
||||
ai_enabled: 0,
|
||||
});
|
||||
}
|
||||
ctx.logger.info(
|
||||
`[inbox] 新建群记录 group_id=${extGroupId} name=${groupName}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 无群ID:按 (group_name, warehouse_id) 幂等登记(向后兼容)
|
||||
|
||||
@ -516,6 +516,7 @@ class AfterSaleMethodService extends MainService {
|
||||
operatorId,
|
||||
operatorSnapshot,
|
||||
warehouseId,
|
||||
notifyGroup: true,
|
||||
});
|
||||
|
||||
return this.success('处理成功', result);
|
||||
|
||||
@ -9,13 +9,14 @@ const MainService = require('../main');
|
||||
class InboxSystemService extends MainService {
|
||||
/**
|
||||
* 群管理子入口,供 /system dispatcher 按 inbox.group.* 路径访问。
|
||||
* @return {{list: Function, disable: Function, update: Function, messages: Function, checkAuth: Function}}
|
||||
* @return {{list: Function, disable: Function, update: Function, reset: Function, messages: Function, checkAuth: Function}}
|
||||
*/
|
||||
get group() {
|
||||
return {
|
||||
list: data => this.groupList(data),
|
||||
disable: data => this.groupDisable(data),
|
||||
update: data => this.groupUpdate(data),
|
||||
reset: data => this.groupReset(data),
|
||||
messages: data => this.groupMessages(data),
|
||||
checkAuth: (...args) => this.checkAuth(...args),
|
||||
};
|
||||
@ -158,6 +159,25 @@ class InboxSystemService extends MainService {
|
||||
return { message: '群信息修改成功' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空群类型配置(入参主键ID或外部群ID)。
|
||||
* 清空 group_type / sub_type / store_id / 快递专属字段,AI 开关重置关闭,
|
||||
* 仅保留群创建时信息。warehouseId 从 ctx.user.store_id 自动注入。
|
||||
*
|
||||
* @param {Object} data 请求数据。
|
||||
* @param {number} data.id 群记录主键ID(必填)。
|
||||
* @return {Promise<Object>} { message: 操作结果 }。
|
||||
*/
|
||||
async groupReset(data = {}) {
|
||||
const { ctx } = this;
|
||||
const { id } = data;
|
||||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||||
|
||||
await ctx.service.systems.inbox.group.reset({ id, warehouseId });
|
||||
|
||||
return { message: '群类型配置已清空' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取指定群的消息列表。
|
||||
* warehouseId 从 ctx.user.store_id 自动注入。
|
||||
|
||||
@ -1074,14 +1074,15 @@ class AfterSaleService extends Service {
|
||||
* @param {number} params.operatorId 操作人ID
|
||||
* @param {string} params.operatorSnapshot 操作人快照 JSON
|
||||
* @param {number} params.warehouseId 仓库ID
|
||||
* @return {Promise<Object>} 处理结果,包含更新后的售后单和步骤记录
|
||||
* @param {boolean} [params.notifyGroup] 是否将处理备注发送到对应货主售后群(内部自动处理不传)
|
||||
* @return {Promise<Object>} 处理结果,包含更新后的售后单、步骤记录和通知群数量
|
||||
* @throws {Error} 售后单不存在或权限不足时抛出
|
||||
*/
|
||||
async handleWorkOrder(params = {}) {
|
||||
const {
|
||||
id, remark, targetStatus, resolution,
|
||||
attachmentIds, operatorId, operatorSnapshot,
|
||||
warehouseId,
|
||||
warehouseId, notifyGroup,
|
||||
} = params;
|
||||
|
||||
const { ctx } = this;
|
||||
@ -1163,11 +1164,73 @@ class AfterSaleService extends Service {
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
// 9. 处理备注发送到对应的货主售后群(仅交互处理传入 notifyGroup 时触发,不转发快递群)
|
||||
let notifiedGroupCount = 0;
|
||||
if (notifyGroup && remark && String(remark).trim()) {
|
||||
try {
|
||||
const remarkText = String(remark).trim();
|
||||
const asRow = afterSale.toJSON ? afterSale.toJSON() : afterSale;
|
||||
|
||||
// 定位货主:优先工单 store_id,缺失时从来源消息所在群反查
|
||||
let notifyStoreId = Number(asRow.store_id || 0);
|
||||
if (!notifyStoreId && asRow.inbox_message_id) {
|
||||
try {
|
||||
const inbound = await ctx.model.InboxMessage.findByPk(asRow.inbox_message_id, {
|
||||
attributes: [ 'group_id' ],
|
||||
raw: true,
|
||||
});
|
||||
if (inbound && inbound.group_id) {
|
||||
const originGroup = await ctx.model.InboxGroup.findOne({
|
||||
attributes: [ 'store_id' ],
|
||||
where: {
|
||||
group_id: inbound.group_id,
|
||||
warehouse_id: warehouseId,
|
||||
is_blocked: 0,
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
if (originGroup && originGroup.store_id) {
|
||||
notifyStoreId = Number(originGroup.store_id);
|
||||
}
|
||||
}
|
||||
} catch (originErr) {
|
||||
ctx.logger.warn(`[handleWorkOrder] 反查来源群货主失败 id=${id}: ${originErr.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (notifyStoreId) {
|
||||
const storeGroups = await ctx.service.systems.inbox.group.findStoreAfterSalesGroups({
|
||||
storeIds: [ notifyStoreId ],
|
||||
warehouseId,
|
||||
});
|
||||
const content = `【工单 ${asRow.after_sale_no}】处理备注:\n${remarkText}`;
|
||||
for (const g of storeGroups) {
|
||||
if (!g.group_id) continue;
|
||||
ctx.service.inbox.processor.pushSystemNotification({
|
||||
warehouse_id: warehouseId,
|
||||
group_id: g.group_id,
|
||||
group_name: g.group_name || '',
|
||||
content,
|
||||
ext_data: g.ext_data || null,
|
||||
});
|
||||
notifiedGroupCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.logger.info(
|
||||
`[handleWorkOrder] 处理备注发送到货主售后群 id=${id} store=${notifyStoreId} notified=${notifiedGroupCount}`
|
||||
);
|
||||
} catch (notifyErr) {
|
||||
ctx.logger.warn(`[handleWorkOrder] 处理备注发送群失败 id=${id}: ${notifyErr.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const updatedAfterSale = afterSale.toJSON ? afterSale.toJSON() : afterSale;
|
||||
|
||||
return {
|
||||
after_sale: this._formatAfterSaleRow(updatedAfterSale, ctx.app),
|
||||
step,
|
||||
notified_groups: notifiedGroupCount,
|
||||
};
|
||||
} catch (error) {
|
||||
await transaction.rollback();
|
||||
@ -1260,7 +1323,7 @@ class AfterSaleService extends Service {
|
||||
priority: 10,
|
||||
creator_id: 0,
|
||||
inbox_message_id: null,
|
||||
role_group: 'warehouse',
|
||||
role_group: 'customer_service',
|
||||
status: 'pending',
|
||||
waybill_id: e.id,
|
||||
waybill_no: e.waybill_code,
|
||||
@ -1281,16 +1344,26 @@ class AfterSaleService extends Service {
|
||||
for (const e of toCreate) {
|
||||
const code = e.logistics_code || '__unknown__';
|
||||
if (!expressByCode[code]) {
|
||||
expressByCode[code] = { interfaceId: e.logistics_interface_id, waybills: [] };
|
||||
expressByCode[code] = {
|
||||
code,
|
||||
interfaceId: e.logistics_interface_id,
|
||||
logisticsName: String(e.logistics_name || '').trim(),
|
||||
waybills: [],
|
||||
};
|
||||
}
|
||||
expressByCode[code].waybills.push(e.waybill_code);
|
||||
}
|
||||
|
||||
let notifiedCount = 0;
|
||||
const notifiedWaybillIds = new Set();
|
||||
// 无对应快递群(或快递无接口)的运单收集后统一降级通知仓库异常群(与货主群缺失降级行为一致)
|
||||
const fallbackEntries = [];
|
||||
|
||||
for (const [ code, info ] of Object.entries(expressByCode)) {
|
||||
if (code === '__unknown__' || !info.interfaceId) continue;
|
||||
if (code === '__unknown__' || !info.interfaceId) {
|
||||
fallbackEntries.push(info);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const { afterSalesGroups } = await ctx.service.systems.inbox.group.findGroupsByExpress({
|
||||
expressInterfaceId: info.interfaceId,
|
||||
@ -1298,7 +1371,10 @@ class AfterSaleService extends Service {
|
||||
warehouseId,
|
||||
});
|
||||
|
||||
if (afterSalesGroups.length === 0) continue;
|
||||
if (afterSalesGroups.length === 0) {
|
||||
fallbackEntries.push(info);
|
||||
continue;
|
||||
}
|
||||
|
||||
const notifyMsg = info.waybills.join('\n') + '\n拦截';
|
||||
for (const g of afterSalesGroups) {
|
||||
@ -1315,10 +1391,56 @@ class AfterSaleService extends Service {
|
||||
const codeWaybills = toCreate.filter(e => (e.logistics_code || '__unknown__') === code);
|
||||
codeWaybills.forEach(e => notifiedWaybillIds.add(e.id));
|
||||
} catch (e) {
|
||||
fallbackEntries.push(info);
|
||||
ctx.logger.warn(`[afterSale] 查售后群失败 code=${code}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 4b. 无对应快递群降级:转发仓库异常群,内容前缀标记失败(与货主群缺失降级一致)
|
||||
if (fallbackEntries.length > 0) {
|
||||
try {
|
||||
const exceptionGroups = await ctx.model.InboxGroup.findAll({
|
||||
attributes: [ 'group_id', 'group_name', 'ext_data' ],
|
||||
where: {
|
||||
warehouse_id: warehouseId,
|
||||
group_type: 'warehouse',
|
||||
sub_type: 'exception',
|
||||
is_blocked: 0,
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
|
||||
if (exceptionGroups.length > 0) {
|
||||
const labelSet = new Set();
|
||||
const fallbackLines = [];
|
||||
for (const entry of fallbackEntries) {
|
||||
const label = entry.logisticsName || entry.code || '未知快递';
|
||||
labelSet.add(label);
|
||||
for (const waybill of entry.waybills) {
|
||||
fallbackLines.push(`${label} ${waybill}`);
|
||||
}
|
||||
}
|
||||
const fallbackContent = `通知快递【${Array.from(labelSet).join('、')}】失败\n${fallbackLines.join('\n')}\n拦截`;
|
||||
for (const g of exceptionGroups) {
|
||||
ctx.service.inbox.processor.pushSystemNotification({
|
||||
warehouse_id: warehouseId,
|
||||
group_id: g.group_id,
|
||||
group_name: g.group_name,
|
||||
content: fallbackContent,
|
||||
ext_data: g.ext_data || null,
|
||||
});
|
||||
}
|
||||
ctx.logger.warn('[afterSale.createInterceptWorkOrdersAndNotify] 无对应快递群,已降级通知仓库异常群', {
|
||||
warehouseId,
|
||||
fallbackCount: fallbackEntries.length,
|
||||
exceptionGroupCount: exceptionGroups.length,
|
||||
});
|
||||
}
|
||||
} catch (fallbackErr) {
|
||||
ctx.logger.warn(`[afterSale] 降级通知异常群失败: ${fallbackErr.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 有通知的工单升级为 pending_feedback
|
||||
if (notifiedWaybillIds.size > 0) {
|
||||
const notifiedWaybillIdArr = [ ...notifiedWaybillIds ];
|
||||
|
||||
@ -362,6 +362,55 @@ class InboxGroupService extends Service {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空群类型配置。
|
||||
* 将群恢复为"仅保留创建信息"状态:清空 group_type / sub_type / store_id /
|
||||
* express_interfaces / system_express_code,AI 开关重置为关闭。
|
||||
* 保留群名称、群ID、仓库、来源信息、屏蔽状态与扩展数据。
|
||||
*
|
||||
* @param {Object} data 请求数据。
|
||||
* @param {number} data.id 群记录主键ID(必填)。
|
||||
* @param {number} data.warehouseId 仓库ID(必填,由 controller 注入)。
|
||||
* @return {Promise<{id: number, group_name: string, group_id: string|null}>} 被重置的群信息。
|
||||
*/
|
||||
async reset(data = {}) {
|
||||
const { ctx } = this;
|
||||
const { InboxGroup } = ctx.model;
|
||||
|
||||
const id = Number(data.id);
|
||||
const warehouseId = Number(data.warehouseId);
|
||||
|
||||
if (!warehouseId) throw new Error('warehouseId 无效');
|
||||
if (!id) throw new Error('群ID无效');
|
||||
|
||||
const where = { id, warehouse_id: warehouseId };
|
||||
|
||||
const group = await InboxGroup.findOne({
|
||||
attributes: [ 'id', 'group_name', 'group_id' ],
|
||||
where,
|
||||
raw: true,
|
||||
});
|
||||
if (!group) throw new Error('群不存在或无权限操作');
|
||||
|
||||
await InboxGroup.update(
|
||||
{
|
||||
group_type: null,
|
||||
sub_type: null,
|
||||
store_id: null,
|
||||
express_interfaces: null,
|
||||
system_express_code: null,
|
||||
ai_enabled: 0,
|
||||
},
|
||||
{ where }
|
||||
);
|
||||
|
||||
ctx.logger.info(
|
||||
`[inbox group] 清空群类型配置 id=${group.id} group_id=${group.group_id} warehouse_id=${warehouseId}`
|
||||
);
|
||||
|
||||
return { id: group.id, group_name: group.group_name, group_id: group.group_id };
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验快递接口ID数组的有效性。
|
||||
* 所有ID必须在 wms_express_interface 表中存在。
|
||||
@ -436,6 +485,7 @@ class InboxGroupService extends Service {
|
||||
const where = {
|
||||
group_type: 'express',
|
||||
system_express_code: code,
|
||||
is_blocked: 0,
|
||||
[Op.or]: [
|
||||
{ express_interfaces: { [Op.or]: [ null, '' ] } },
|
||||
{ express_interfaces: { [Op.like]: `%${eid}%` } },
|
||||
@ -495,6 +545,7 @@ class InboxGroupService extends Service {
|
||||
group_type: 'store',
|
||||
sub_type: 'after_sales',
|
||||
store_id: { [Op.in]: ids },
|
||||
is_blocked: 0,
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
|
||||
@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* inbox.group.reset 群类型清空接口权限记录 + 角色授权迁移。
|
||||
*
|
||||
* 权限明细(固定 ID 558,556 已被「运单退回」web 页面占用):
|
||||
* 558 — inbox.group.reset API:清空群类型配置(重置群)
|
||||
*
|
||||
* 角色授权(客服员工及以上链路):
|
||||
* 30(客服组-员工) → 28(客服组-主管) → 8(经理,通配符 * 自动拥有)
|
||||
*
|
||||
* 幂等:INSERT IGNORE 创建权限记录;角色权限数组追加后去重排序,已存在跳过。
|
||||
*/
|
||||
|
||||
const TABLE = 'wms_permission';
|
||||
const ROLE_TABLE = 'wms_role';
|
||||
const COLUMNS = 'id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at';
|
||||
|
||||
/** 权限ID → 授权角色ID列表(不含通配符角色) */
|
||||
const PERMISSION_ROLES = {
|
||||
558: [ 30, 28, 8 ],
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async up(queryInterface, Sequelize) {
|
||||
// ── 1. 创建 API 权限记录(固定 ID)──
|
||||
const apis = [
|
||||
[ 558, 'inbox.group.reset', 'API:清空群类型配置' ],
|
||||
];
|
||||
|
||||
for (const [ id, path, metaTitle ] of apis) {
|
||||
await queryInterface.sequelize.query(
|
||||
`INSERT IGNORE INTO \`${TABLE}\` (${COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())`,
|
||||
{ replacements: [ id, path, null, path, null, metaTitle, null, 0, 0, null, 'api', 0, 1 ] }
|
||||
);
|
||||
}
|
||||
|
||||
// ── 2. 角色授权注入 ──
|
||||
for (const permId of Object.keys(PERMISSION_ROLES).map(Number)) {
|
||||
for (const roleId of PERMISSION_ROLES[permId]) {
|
||||
const rows = await queryInterface.sequelize.query(
|
||||
`SELECT id, permissions FROM \`${ROLE_TABLE}\` WHERE id = ?`,
|
||||
{ replacements: [ roleId ], type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
const record = Array.isArray(rows) ? rows[0] : null;
|
||||
if (!record) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 通配符角色跳过
|
||||
if (record.permissions === '*') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let perms;
|
||||
try {
|
||||
perms = typeof record.permissions === 'string'
|
||||
? JSON.parse(record.permissions)
|
||||
: record.permissions;
|
||||
} catch (e) {
|
||||
perms = null;
|
||||
}
|
||||
|
||||
if (!Array.isArray(perms)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!perms.includes(permId)) {
|
||||
perms.push(permId);
|
||||
perms.sort((a, b) => Number(a) - Number(b));
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE \`${ROLE_TABLE}\` SET permissions = ? WHERE id = ?`,
|
||||
{ replacements: [ JSON.stringify(perms), roleId ] }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.sequelize.query(
|
||||
'DELETE FROM `wms_permission` WHERE id = 558'
|
||||
);
|
||||
|
||||
const roleIds = [ 30, 28, 8 ];
|
||||
for (const roleId of roleIds) {
|
||||
const rows = await queryInterface.sequelize.query(
|
||||
`SELECT id, permissions FROM \`${ROLE_TABLE}\` WHERE id = ?`,
|
||||
{ replacements: [ roleId ], type: queryInterface.sequelize.QueryTypes.SELECT }
|
||||
);
|
||||
const record = Array.isArray(rows) ? rows[0] : null;
|
||||
if (!record || record.permissions === '*') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let perms;
|
||||
try {
|
||||
perms = typeof record.permissions === 'string'
|
||||
? JSON.parse(record.permissions)
|
||||
: record.permissions;
|
||||
} catch (e) {
|
||||
perms = null;
|
||||
}
|
||||
if (!Array.isArray(perms) || !perms.includes(558)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
perms = perms.filter(p => p !== 558);
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE \`${ROLE_TABLE}\` SET permissions = ? WHERE id = ?`,
|
||||
{ replacements: [ JSON.stringify(perms), roleId ] }
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -1,4 +1,35 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.08.17-inbox-group-reset",
|
||||
"date": "2026-08-17",
|
||||
"type": "enhanced",
|
||||
"summary": "新增 inbox.group.reset 群操作接口:入参群记录主键ID,清空群类型配置(group_type/sub_type/store_id/express_interfaces/system_express_code 置空、ai_enabled 重置为0),仅保留群创建时信息(群名称/群ID/仓库/来源/屏蔽状态/扩展数据)",
|
||||
"methods": [
|
||||
"inbox.group.reset"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/inbox/group.js reset:仓库隔离按主键 id 定位群,清空类型相关字段并写操作日志,返回重置后群信息",
|
||||
"app/service/systemMethods/inbox.js 新增 groupReset,注册到 inbox.group 子入口",
|
||||
"数据库迁移 20260817120000-add-inbox-group-reset-permission.js:权限ID 556 授权角色 8/26/28/29",
|
||||
"同步更新 methods/system.json 中 inbox.group.reset 接口文档"
|
||||
],
|
||||
"module": "inbox.group"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.17-afterSale-handleWorkOrder-remark-notify-group",
|
||||
"date": "2026-08-17",
|
||||
"type": "enhanced",
|
||||
"summary": "afterSale.handleWorkOrder 处理备注同步发送到对应货主售后群:填写 remark 时推送到货主售后群(工单 store_id 定位,缺失时从来源消息所在群反查货主,不转发快递群);消息内容格式为「【工单 售后单号】处理备注:备注内容」;响应新增 notified_groups 返回发送群数量",
|
||||
"methods": [
|
||||
"afterSale.handleWorkOrder"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/afterSale.js handleWorkOrder:新增 notifyGroup 参数(方法层交互处理传 true,内部自动处理如库内拦截/退回已收到不传),事务提交后按 remark 非空发送:store_id 定位货主 → findStoreAfterSalesGroups 发货主售后群;无 store_id 时按 inbox_message_id 查来源消息 group_id → InboxGroup 反查 store_id 再发送;发送失败仅告警不影响处理结果",
|
||||
"app/service/systemMethods/afterSale.js handleWorkOrder:调用 systems 层时传 notifyGroup: true",
|
||||
"同步更新 methods/system.json 中 afterSale.handleWorkOrder 的 description、remark 参数说明与 notified_groups 响应说明"
|
||||
],
|
||||
"module": "afterSale"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.16-waybill-createAt-between",
|
||||
"date": "2026-08-16",
|
||||
|
||||
@ -33703,6 +33703,47 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "inbox.group.reset",
|
||||
"description": "清空群类型配置:清空群类型/子类型/货主/快递接口/系统快递编码,AI开关重置关闭,仅保留群创建时信息(群名称/群ID/仓库/来源/屏蔽状态/扩展数据)。入参群记录主键ID",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "Bearer token(从中解析 warehouseId 仓库上下文)"
|
||||
}
|
||||
],
|
||||
"params": [
|
||||
{
|
||||
"name": "id",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"source": "body",
|
||||
"description": "群记录主键ID"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
{
|
||||
"name": "message",
|
||||
"type": "string",
|
||||
"required": true,
|
||||
"description": "操作结果提示:群类型配置已清空"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": "400",
|
||||
"message": "群ID无效"
|
||||
},
|
||||
{
|
||||
"code": "500",
|
||||
"message": "群不存在或无权限操作"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "inbox.group.messages",
|
||||
"description": "按群拉取消息列表,支持方向/关键词筛选,分页返回。warehouseId服务端自动注入,查询命中idx_warehouse_group_created索引",
|
||||
@ -34582,7 +34623,7 @@
|
||||
},
|
||||
{
|
||||
"method": "afterSale.handleWorkOrder",
|
||||
"description": "处理售后工单:写入进度步骤并绑定附件。操作人信息从登录上下文自动获取。非客服组处理完成后自动将 role_group 回退到 customer_service;status=completed 时自动写入 resolution + resolved_at。步骤 action 由服务端固定为\"处理工单\",step_status 与主表 status 完全一致。status 不填或填错时默认 processing。新增 pending_feedback 状态用于内部处理完成等待外部反馈(如已将拦截信息发给运方,等待运方反馈后再决定是否继续处理)。",
|
||||
"description": "处理售后工单:写入进度步骤并绑定附件。操作人信息从登录上下文自动获取。非客服组处理完成后自动将 role_group 回退到 customer_service;status=completed 时自动写入 resolution + resolved_at。步骤 action 由服务端固定为\"处理工单\",step_status 与主表 status 完全一致。status 不填或填错时默认 processing。新增 pending_feedback 状态用于内部处理完成等待外部反馈(如已将拦截信息发给运方,等待运方反馈后再决定是否继续处理)。填写处理备注(remark)时会同步发送到对应的货主售后群(工单无 store_id 时从来源消息所在群反查货主,不转发快递群),响应 notified_groups 返回发送的群数量。",
|
||||
"isNeedAuth": false,
|
||||
"isNeedLogin": true,
|
||||
"headers": [],
|
||||
@ -34606,7 +34647,7 @@
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "处理备注"
|
||||
"description": "处理备注。填写后同步发送到对应的货主售后群,内容格式:\"【工单 售后单号】处理备注:备注内容\""
|
||||
},
|
||||
{
|
||||
"name": "attachment_ids",
|
||||
@ -34628,6 +34669,12 @@
|
||||
"type": "integer",
|
||||
"required": true,
|
||||
"description": "售后工单ID"
|
||||
},
|
||||
{
|
||||
"name": "notified_groups",
|
||||
"type": "integer",
|
||||
"required": false,
|
||||
"description": "处理备注发送到的货主售后群数量(未填写备注或未找到货主售后群时为0)"
|
||||
}
|
||||
],
|
||||
"errors": []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user