fix(退回对接): ingest 接口复用既有 supplier_integration 对接令牌鉴权,不再要求用户账号/权限——部署后主系统用现有凭据即可调用
This commit is contained in:
@@ -1907,9 +1907,21 @@ router.get('/after-sales/order-context/:orderCode', authMiddleware, async (req:
|
||||
*/
|
||||
router.post('/after-sales/returns/ingest', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['aftersales_manage']);
|
||||
const branchCode = String(req.body?.branch_code || ctx?.branchCode || '').trim();
|
||||
/**
|
||||
* 鉴权(2026-10-20 开发者裁定:**不新建账号**,复用既有对接凭据):
|
||||
* · `supplier_integration` 对接 token(client_id/client_secret 换来的集成令牌)⇒ 直接放行,
|
||||
* 分公司从 token 里取(主系统调用走这条,部署后即可用,无需额外开账号);
|
||||
* · 普通用户 token ⇒ 仍要求 `aftersales_manage` 权限(界面/人工补调用)。
|
||||
*/
|
||||
const isIntegration = (req as any).tokenScope === 'supplier_integration';
|
||||
let ctx: any = null;
|
||||
if (!isIntegration) {
|
||||
ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['aftersales_manage']);
|
||||
}
|
||||
const branchCode = String(
|
||||
req.body?.branch_code || (isIntegration ? (req as any).branchCode : ctx?.branchCode) || ''
|
||||
).trim();
|
||||
const body = req.body || {};
|
||||
let ourOrderCode = String(body.our_order_code || '').trim();
|
||||
const prepId = String(body.prep_id || '').trim();
|
||||
@@ -1920,7 +1932,7 @@ router.post('/after-sales/returns/ingest', authMiddleware, async (req: AuthReque
|
||||
if (!ourOrderCode) {
|
||||
return res.status(400).json({ error: 'invalid_request', error_description: '缺少 our_order_code(或 prep_id 无法定位到订单)' });
|
||||
}
|
||||
await assertOrderCodeAccess(ourOrderCode, ctx!);
|
||||
if (!isIntegration) await assertOrderCodeAccess(ourOrderCode, ctx!);
|
||||
const { ingestMainSystemReturn } = await import('../../../services/mainSystemReturnService');
|
||||
const data = await ingestMainSystemReturn({
|
||||
branchCode,
|
||||
|
||||
Reference in New Issue
Block a user