WMS_MAIN/database/migrations/20260809140100-grant-after-sale-workorder-pages.js
liufumingren b436b6dd9e feat: 拦截链路全流程完善 — 新增interceptScan + 运单表同步 + 工单通知
新增:
- order.recheckOrder.interceptScan: 拦截扫描接口,入参运单号,查express标记退回,处理工单,更新订单拦截状态
- afterSale.createInterceptWorkOrdersAndNotify: 共享方法,幂等创建工单+通知快递群

修复:
- confirmIntercept: 补运单is_back同步(仅限is_intercept=Y),补工单创建+通知
- batchIntercept: 补运单is_intercept同步,补工单创建+通知
- batchUnintercept: 补运单is_intercept/is_back清除
- Qimen/OpenAPI cancel: 补运单is_intercept同步,补工单创建+通知
- interceptScan: 删除死查询,加空指针兜底

文档:
- methods/system.json: interceptScan + confirmIntercept 完整API文档
- methods/changes/system.json: 变更记录
2026-08-12 20:47:19 +08:00

104 lines
4.2 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';
/**
* 为售后模块新增页面权限授权,并创建财务组角色。
*
* 操作:
* 1. 新建财务组角色(role_code='finance')
* 2. 为以下角色追加页面权限 524 (afterSale.workOrder)、525 (afterSale.workOrder.list):
* - 经理 (role_code=2)
* - 客服组-主管 (role_code=05)
* - 客服组-员工 (role_code=04)
* - 仓库组-主管 (role_code=warehouse)
* - 仓库组-员工 (role_code=warehouse_role)
* - 生产组-主管 (role_code=03)
* - 生产组-拣货 (role_code=021)
*
* 幂等设计:
* - 财务组角色使用 INSERT IGNORE,已存在则跳过
* - 权限追加使用 JSON_ARRAY_APPEND,不重复添加
*/
const NEW_PAGE_IDS = [524, 525];
// 财务组基础权限:block(518) + 所有web_pages(519,520,521,524,525) + 只读API(522,508)
const FINANCE_PERMISSIONS = [518, 519, 520, 521, 524, 525, 522, 508];
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
const { sequelize } = queryInterface;
// ── 1. 创建财务组角色(如果不存在)──
await sequelize.query(`
INSERT IGNORE INTO wms_role (role_code, role_name, description, role_type, scope, is_system, status, pid, created_by, permissions, created_at, updated_at)
VALUES ('finance', '财务组', '售后模块财务审核角色', 1, 1, 1, 1, 8, 1, ?, NOW(), NOW())
`, {
replacements: [JSON.stringify(FINANCE_PERMISSIONS)],
});
// ── 2. 为已有角色追加页面权限 ──
const targetRoleCodes = ['2', '05', '04', 'warehouse', 'warehouse_role', '03', '021'];
for (const roleCode of targetRoleCodes) {
for (const permId of NEW_PAGE_IDS) {
// 仅当该角色的 permissions 数组中不包含此权限ID时才追加
// JSON_CONTAINS 检查是否已存在
// 注意:permissions 列为 LONGTEXT,JSON 函数需显式 CAST
// 安全守卫:permissions 必须是合法 JSON 数组(以 [ 开头且非 NULL),
// 避免在非法 JSON(如旧版范围格式 [4-121])或 NULL 上执行 JSON_ARRAY_APPEND 导致权限被清空。
await sequelize.query(
`UPDATE wms_role
SET permissions = JSON_ARRAY_APPEND(CAST(permissions AS JSON), '$', CAST(? AS UNSIGNED)),
updated_at = NOW()
WHERE role_code = ?
AND permissions IS NOT NULL
AND permissions != ''
AND permissions != '*'
AND JSON_VALID(permissions) = 1
AND LEFT(permissions, 1) = '['
AND JSON_CONTAINS(CAST(permissions AS JSON), CAST(? AS JSON), '$') = 0`,
{ replacements: [permId, roleCode, String(permId)] }
);
}
}
},
// eslint-disable-next-line no-unused-vars
async down(queryInterface, Sequelize) {
const { sequelize } = queryInterface;
// ── 1. 移除财务组角色 ──
await sequelize.query(
"DELETE FROM wms_role WHERE role_code = 'finance'"
);
// ── 2. 从各角色移除页面权限 ──
const targetRoleCodes = ['2', '05', '04', 'warehouse', 'warehouse_role', '03', '021'];
for (const roleCode of targetRoleCodes) {
for (const permId of NEW_PAGE_IDS) {
// 从 JSON 数组中移除指定值(MySQL 5.7+ 无直接 JSON_REMOVE_BY_VALUE,用 JSON_SEARCH)
// 注意:permissions 列为 LONGTEXT,JSON 函数需显式 CAST
// 安全守卫:同 up(),防止在非法 JSON 上操作
await sequelize.query(
`UPDATE wms_role
SET permissions = JSON_REMOVE(
CAST(permissions AS JSON),
REPLACE(JSON_UNQUOTE(JSON_SEARCH(CAST(permissions AS JSON), 'one', CAST(? AS CHAR), NULL, '$')), '', '')
),
updated_at = NOW()
WHERE role_code = ?
AND permissions IS NOT NULL
AND permissions != ''
AND permissions != '*'
AND JSON_VALID(permissions) = 1
AND LEFT(permissions, 1) = '['
AND JSON_CONTAINS(CAST(permissions AS JSON), CAST(? AS JSON), '$') = 1`,
{ replacements: [permId, roleCode, String(permId)] }
);
}
}
},
};