feat(商城管理): 客户商品库后台一期
新增 /customers/mall 卡片管理、Excel 导入、上下架/描述/收藏/移出;复用客户销售价接口;修复共享报价单并发改价、i18n、迁移空 schema、并发计数。
This commit is contained in:
@@ -11,6 +11,15 @@ import { getWorkflowCtx, requireWorkflowPermission } from '../context';
|
||||
import { getEffectiveBranchCode, readOperatingBranchCode } from '../../../services/tenantScope';
|
||||
import { requireAdminRole } from '../context';
|
||||
import { getGeoProvider, isValidLatLng } from '../../../services/geoProvider';
|
||||
import {
|
||||
listMallLibrary,
|
||||
searchMallCatalog,
|
||||
addMallLibrarySkus,
|
||||
updateMallLibraryItem,
|
||||
removeMallLibrarySku,
|
||||
previewMallLibraryImport,
|
||||
importMallLibraryRows,
|
||||
} from '../../../services/customerMallAdminService';
|
||||
|
||||
/** 客户模块 workflow API */
|
||||
export function mountCustomerWorkflowRoutes(router: Router): void {
|
||||
@@ -193,4 +202,135 @@ router.delete('/customers/:customerCode', authMiddleware, async (req: AuthReques
|
||||
return res.status(error?.status || 400).json({ error: 'server_error', error_description: error?.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/customers/:customerCode/mall-products', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
const data = await listMallLibrary(String(req.params.customerCode || ''));
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '读取客户商品库失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/customers/:customerCode/mall-catalog', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
const data = await searchMallCatalog({
|
||||
customerCode: String(req.params.customerCode || ''),
|
||||
q: req.query?.q ? String(req.query.q) : null,
|
||||
limit: req.query?.limit ? Number(req.query.limit) : undefined,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '读取商品档案失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/customers/:customerCode/mall-products', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
const data = await addMallLibrarySkus({
|
||||
customerCode: String(req.params.customerCode || ''),
|
||||
skuCodes: req.body?.sku_codes,
|
||||
operatorId: req.userId || null,
|
||||
ipAddress: req.ip || null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 400).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '添加商品失败',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.patch(
|
||||
'/customers/:customerCode/mall-products/:skuCode',
|
||||
authMiddleware,
|
||||
async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
const data = await updateMallLibraryItem({
|
||||
customerCode: String(req.params.customerCode || ''),
|
||||
skuCode: String(req.params.skuCode || ''),
|
||||
customerSkuName: req.body?.customer_sku_name,
|
||||
customerUnit: req.body?.customer_unit,
|
||||
customerDescription: req.body?.description,
|
||||
isFavorite: req.body?.is_favorite,
|
||||
isListed: req.body?.is_listed,
|
||||
operatorId: req.userId || null,
|
||||
ipAddress: req.ip || null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 400).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '保存商品失败',
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/customers/:customerCode/mall-products/:skuCode',
|
||||
authMiddleware,
|
||||
async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
const data = await removeMallLibrarySku({
|
||||
customerCode: String(req.params.customerCode || ''),
|
||||
skuCode: String(req.params.skuCode || ''),
|
||||
operatorId: req.userId || null,
|
||||
ipAddress: req.ip || null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 400).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '移出商品失败',
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/customers/:customerCode/mall-products/import',
|
||||
authMiddleware,
|
||||
async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['customer_manage']);
|
||||
const dryRun = req.body?.dry_run === true;
|
||||
const data = dryRun
|
||||
? await previewMallLibraryImport({
|
||||
customerCode: String(req.params.customerCode || ''),
|
||||
rows: req.body?.rows,
|
||||
})
|
||||
: await importMallLibraryRows({
|
||||
customerCode: String(req.params.customerCode || ''),
|
||||
rows: req.body?.rows,
|
||||
operatorId: req.userId || null,
|
||||
ipAddress: req.ip || null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 400).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '导入商品失败',
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user