WMS_MAIN/database/migrations/20260813110000-add-return-received-menu-permission.js
liufumingren f4ed985556 feat: 新增退回收到模块(returnReceived)
- 新增退回收到登记表 wms_return_received 及模型、建表迁移
- 新增扫码登记/列表/详情/删除接口(systemMethods + systems 分层)
- 退回收到联动:标记运单 is_back、完结拦截工单、订单退回状态、操作记录
- 新增权限 527/528/529 + 菜单 530,授权仓库/客服角色
- 解除拦截不再清除 is_back(由退回收货流程单独管理)
- 同步 API 文档、method 路由速查
2026-08-13 01:58:55 +08:00

83 lines
2.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';
/**
* 快递菜单下新增 web_pages 子菜单「快递收件」(id=530),并授权客服员工及以上角色。
*
* 权限明细:
* 530 — returnReceived(web_pages 菜单,parent_id=19 快递/物流)
*
* 角色授权(系统预设角色,不含通配符角色):
* 530 → 客服组-员工(30) → 客服组-主管(28)(客服员工及以上)
* 经理(8)/仓库管理员(2)/超级管理员(7) 已持有 * 通配符,自动拥有所有权限,无需处理
*
* 幂等: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 = {
530: [ 30, 28 ],
};
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
// ── 1. 创建 web_pages 菜单权限(固定 ID,parent_id=19 快递/物流)──
await queryInterface.sequelize.query(
`INSERT IGNORE INTO \`${TABLE}\` (${COLUMNS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())`,
{ replacements: [ 530, 'returnReceived', '@/views/express/returnReceived/index', 'returnReceived', null, '快递收件', null, 0, 0, 19, 'web_pages', 1, 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 = JSON.parse(record.permissions || '[]');
} catch (err) {
continue;
}
if (!Array.isArray(perms)) {
continue;
}
if (perms.includes(permId)) {
continue;
}
perms.push(permId);
perms.sort((a, b) => a - 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 \`${TABLE}\` WHERE id = 530`
);
},
};