WMS_MAIN/database/migrations/20260817120000-add-inbox-group-reset-permission.js
liufumingren e6f4d9f341 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 记录
2026-08-17 22:01:18 +08:00

118 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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 ] }
);
}
},
};