oms/backend/database/migrations/20261106090000-add-default-warehouse-to-shops.js
liufumingren 74ddeca3c0 feat(shop): 店铺支持设置默认发货仓库,拉单与未审核订单自动带仓库
- shops 新增 default_warehouse_id(迁移 + 模型 + 契约),仓库须存在、启用且属于店铺货主

- 新增 PUT /api/shops/:id/default-warehouse 单独维护该字段,外部打单平台店铺的货主权限也可配置

- 新增 shopWarehouse 服务:保存后把该店铺待审核订单中仓库为空或是旧默认值的订单回填为新仓库(手工改过的不覆盖)

- 打单平台与数据库店铺拉单落待审核时自动带上默认仓库(含 warehouse_code 快照);一键拉单店铺查询补 default_warehouse_id

- 前端:店铺列表新增「默认仓库」列与配置弹窗,新增/编辑表单增加默认发货仓库下拉(按货主过滤),详情面板展示

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-06 22:23:23 +08:00

28 lines
991 B
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';
/**
* 店铺增加「默认发货仓库」。
*
* 取值来自店铺所属货主(下属公司)的仓库;设置后:
* - 拉取订单(打单平台 / 数据库店铺)落待审核时自动带上该仓库;
* - 该店铺尚未审核的订单也会回填为该仓库(已有仓库且不是旧默认值的保持不动)。
*/
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('shops', 'default_warehouse_id', {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '默认发货仓库ID(关联 warehouses,须属于店铺货主)',
after: 'subsidiary_id',
});
await queryInterface.addIndex('shops', [ 'default_warehouse_id' ], {
name: 'idx_shops_default_warehouse',
});
},
async down(queryInterface) {
await queryInterface.removeIndex('shops', 'idx_shops_default_warehouse');
await queryInterface.removeColumn('shops', 'default_warehouse_id');
},
};