This commit is contained in:
liufumingren 2026-05-17 23:36:18 +08:00
parent 1d70c01631
commit 608d7741c1
5 changed files with 100 additions and 49 deletions

View File

@ -4,19 +4,7 @@ module.exports = app => {
const { BIGINT, TEXT, STRING, DATE, TINYINT, INTEGER, JSON: JSON_TYPE } = app.Sequelize;
const POLICY_CONFIG_FIELDS = Object.freeze([
Object.freeze({
key: 'receive_mode',
name: '收货模式',
type: 'enum',
default: 'standard',
required: false,
description: '控制货主在该仓下的收货校验模式',
options: [
Object.freeze({ value: 'standard', label: '标准收货' }),
Object.freeze({ value: 'strict', label: '严格收货' }),
Object.freeze({ value: 'manual', label: '人工收货' }),
],
}),
Object.freeze({
key: 'auto_allocate_bin',
name: '自动分配库位',
@ -99,6 +87,14 @@ module.exports = app => {
required: false,
description: '控制货主推送订单创建后是否必须进入审批流程',
}),
Object.freeze({
key: 'enable_external_express_code',
name: '启用外部快递编码',
type: 'flag',
default: 0,
required: false,
description: '控制该货主在当前仓库下是否允许使用外部快递编码,为否的时候默认使用下方的默认快递',
}),
Object.freeze({
key: 'default_express_code',
name: '默认快递',
@ -115,37 +111,6 @@ module.exports = app => {
required: false,
description: '货主在当前仓下默认使用的平台编码',
}),
Object.freeze({
key: 'print_recharge_price',
name: '面单充值元/单',
type: 'number',
default: 0,
required: false,
description: '面单充值元/单,支持 2 位小数',
min: 0,
max: 1000000,
precision: 2,
step: 0.01,
}),
Object.freeze({
key: 'max_daily_inbound',
name: '单日最大收货量',
type: 'integer',
default: 0,
required: false,
description: '限制该货主在仓库内的日收货上限',
min: 0,
max: 1000000,
}),
Object.freeze({
key: 'remark',
name: '策略备注',
type: 'string',
default: '',
required: false,
description: '补充说明该货主在仓库内的特殊约束',
maxLength: 200,
}),
Object.freeze({
key: 'sender_name',
name: '发件人姓名',

View File

@ -1741,7 +1741,7 @@ class SettingStoreWarehouseService extends Service {
const qimenConfig = await this.getSingleQimenConfig(relation.id, {
allowDisabled: true,
});
const policyConfig = await this.loadPolicyConfigByContractId(relation.id);
const policyConfig = await this.getEffectivePolicyConfigByContractId(relation.id);
return {
code: 200,
@ -1771,6 +1771,7 @@ class SettingStoreWarehouseService extends Service {
data.policy_config !== undefined ? data.policy_config : data.policy
);
await this.savePolicyConfigByContractId(relation.id, policyConfig, transaction);
const effectivePolicyConfig = this.mergePolicyConfigWithDefaults(policyConfig);
const result = await ctx.model.StoreWarehouse.findByPk(relation.id, {
include: this.getRelationIncludes(),
@ -1808,7 +1809,7 @@ class SettingStoreWarehouseService extends Service {
code: 200,
data: {
contract_id: Number(relation.id || 0),
policy_config: policyConfig,
policy_config: effectivePolicyConfig,
contract: this.serializeRelation(result, currentSubject, qimenConfig),
},
};

View File

@ -1956,5 +1956,20 @@
],
"type": "updated",
"module": "store"
},
{
"version": "2026.05.17-system-12",
"date": "2026-05-17",
"summary": "storeWarehouse.store 策略配置文档新增 enable_external_express_code 字段说明(向后兼容)",
"methods": [
"storeWarehouse.store.getPolicyConfig",
"storeWarehouse.store.savePolicyConfig"
],
"notes": [
"在 getPolicyConfig / savePolicyConfig 的出参说明中补充 data.policy_config.enable_external_express_code 字段,明确为 flag(0=关闭,1=开启),默认 0。",
"在 savePolicyConfig 的入参说明中补充 policy_config.enable_external_express_code 字段定义。",
"本次为向后兼容的文档增强:新增可选策略字段说明,不影响现有调用。"
],
"type": "updated"
}
]

View File

@ -15581,7 +15581,26 @@
"description": "签约关系ID,兼容 contract_id"
}
],
"response": [],
"response": [
{
"name": "data.contract_id",
"type": "number",
"required": true,
"description": "签约关系ID"
},
{
"name": "data.policy_config",
"type": "object",
"required": true,
"description": "策略配置对象(包含默认值补齐后的字段)"
},
{
"name": "data.policy_config.enable_external_express_code",
"type": "number",
"required": true,
"description": "是否启用外部快递编码(flag:0=关闭,1=开启;默认 0)"
}
],
"errors": []
},
{
@ -15627,10 +15646,36 @@
"type": "object",
"required": true,
"source": "body",
"description": "策略配置对象;仅支持 receive_mode、auto_allocate_bin、auto_allocate_express(是否自动分配快递)、auto_allocate_storage(是否自动分配储位)、allow_mix_batch、allow_temp_storage、storage_separation、print_recharge_price(面单充值元/单,支持 2 位小数)、max_daily_inbound、remark、waybill_custom_display_type(面单自定义显示类型:1=隐藏,2=商品名称和数量,3=拣货库位和条码和数量,4=拣货库位和条码后5位和数量,5=拣货库位商品名称条码和数量)"
"description": "策略配置对象;支持 receive_mode、auto_allocate_bin、auto_allocate_express(是否自动分配快递)、auto_allocate_storage(是否自动分配储位)、allow_mix_batch、allow_temp_storage、storage_separation、print_recharge_price(面单充值元/单,支持 2 位小数)、max_daily_inbound、remark、waybill_custom_display_type(面单自定义显示类型:1=隐藏,2=商品名称和数量,3=拣货库位和条码和数量,4=拣货库位和条码后5位和数量,5=拣货库位商品名称条码和数量)、enable_external_express_code(是否启用外部快递编码,flag:0=关闭,1=开启;默认 0)"
},
{
"name": "policy_config.enable_external_express_code",
"type": "number",
"required": false,
"source": "body.policy_config",
"description": "是否启用外部快递编码(flag:0=关闭,1=开启;默认 0)"
}
],
"response": [
{
"name": "data.contract_id",
"type": "number",
"required": true,
"description": "签约关系ID"
},
{
"name": "data.policy_config",
"type": "object",
"required": true,
"description": "保存后并补齐默认值的策略配置对象"
},
{
"name": "data.policy_config.enable_external_express_code",
"type": "number",
"required": true,
"description": "是否启用外部快递编码(flag:0=关闭,1=开启;默认 0)"
}
],
"response": [],
"errors": []
},
{

View File

@ -198,6 +198,7 @@ describe('test/app/controller/system.setting.storeWarehouse.test.js', () => {
allow_mix_batch: 0,
max_daily_inbound: 5000,
need_order_approval: 1,
enable_external_express_code: 1,
remark: `autotest_${Date.now()}`,
};
@ -217,6 +218,7 @@ describe('test/app/controller/system.setting.storeWarehouse.test.js', () => {
assert.equal(Number(saveRes.body?.data?.policy_config?.auto_allocate_storage || 0), 1, '保存后 auto_allocate_storage 应为 1');
assert.equal(Number(saveRes.body?.data?.policy_config?.storage_separation || 0), 1, '保存后 storage_separation 应为 1');
assert.equal(Number(saveRes.body?.data?.policy_config?.need_order_approval || 0), 1, '保存后 need_order_approval 应为 1');
assert.equal(Number(saveRes.body?.data?.policy_config?.enable_external_express_code || 0), 1, '保存后 enable_external_express_code 应为 1');
const getRes = await invokeSystemMethod(`${METHOD_PREFIX}.getPolicyConfig`, {
id: Number(candidate.id),
@ -235,6 +237,29 @@ describe('test/app/controller/system.setting.storeWarehouse.test.js', () => {
assert.equal(Number(getRes.body?.data?.policy_config?.auto_allocate_storage || 0), 1, '读取后 auto_allocate_storage 应为 1');
assert.equal(Number(getRes.body?.data?.policy_config?.storage_separation || 0), 1, '读取后 storage_separation 应为 1');
assert.equal(Number(getRes.body?.data?.policy_config?.need_order_approval || 0), 1, '读取后 need_order_approval 应为 1');
assert.equal(Number(getRes.body?.data?.policy_config?.enable_external_express_code || 0), 1, '读取后 enable_external_express_code 应为 1');
const policyConfigWithoutExternalExpress = { ...nextPolicyConfig };
delete policyConfigWithoutExternalExpress.enable_external_express_code;
const saveDefaultRes = await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {
id: Number(candidate.id),
policy_config: policyConfigWithoutExternalExpress,
}, token, EXTRA_HEADERS);
assert.equal(saveDefaultRes.status, 200);
assert.equal(saveDefaultRes.body.flag, 'success');
assert.equal(saveDefaultRes.body.code, 200);
assert.equal(Number(saveDefaultRes.body?.data?.policy_config?.enable_external_express_code || 0), 0, '未传 enable_external_express_code 时应默认关闭');
const getDefaultRes = await invokeSystemMethod(`${METHOD_PREFIX}.getPolicyConfig`, {
id: Number(candidate.id),
}, token, EXTRA_HEADERS);
assert.equal(getDefaultRes.status, 200);
assert.equal(getDefaultRes.body.flag, 'success');
assert.equal(getDefaultRes.body.code, 200);
assert.equal(Number(getDefaultRes.body?.data?.policy_config?.enable_external_express_code || 0), 0, '读取时缺省 enable_external_express_code 应视为关闭');
} finally {
if (originalPolicyConfig) {
await invokeSystemMethod(`${METHOD_PREFIX}.savePolicyConfig`, {