oms/backend/app/model/warehouseApi.js
liufumingren cbd16752a5 feat(backend): 商品、店铺、组合商品、仓库与库存模块
- 商品/商品图片、店铺、店铺商品、组合商品及明细
- 仓库、仓库商品(WMS itemId 映射)、仓库接口配置与字段定义(warehouseApi/warehouseApiField)
- 库存:stock_items、product_stocks(ZC/CC 双维度)与库存重算工具(utils/recalcStock.js)
- 库存单据与对接日志:stock orders、api_outbound_logs
- 相关迁移:shops/shop_products/stock_orders/warehouses/warehouse_apis/warehouse_products/product_stocks/files-images 等表与字段
2026-09-13 02:23:39 +08:00

47 lines
2.2 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';
const { readFieldValues } = require('../lib/warehouseApiFields');
/**
* 仓库接口配置模型,对应 warehouse_apis 表
* 一个仓库可有多条接口配置(当前对接方式统一为「类奇门JSON接口」)
* @param {Egg.Application} app egg application
* @return {object} warehouseApi model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, JSON, DATE } = app.Sequelize;
const WarehouseApi = app.model.define('warehouse_api', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
warehouse_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属仓库ID' },
name: { type: STRING(100), allowNull: false, comment: '接口配置名称' },
type: { type: STRING(50), defaultValue: 'qimen', comment: '接口类型:qimen=类奇门JSON接口(当前系统仅支持这一种)' },
base_url: { type: STRING(255), comment: '接口基础地址' },
app_key: { type: STRING(100), comment: '应用Key' },
app_secret: { type: STRING(255), comment: '应用密钥' },
extra: { type: JSON, comment: '接口配置项值 JSON 对象:{ 字段名: 值 },未配置的字段按硬编码默认值读取' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
remark: { type: STRING(255), comment: '备注' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
/**
* 【统一读取方法】取本接口配置的配置项值
* 返回 { 字段名: 值 } JSON 对象,未配置的字段用硬编码默认值兜底,
* 调用方(接口返回、推送业务)统一走这里,不要直接解析 extra
* @return {Object} { 字段key: 字段值 }
*/
WarehouseApi.prototype.getFieldValues = function getFieldValues() {
return readFieldValues(this.extra);
};
WarehouseApi.associate = () => {
app.model.WarehouseApi.belongsTo(app.model.Warehouse, { foreignKey: 'warehouse_id', as: 'warehouse' });
app.model.WarehouseApi.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
};
return WarehouseApi;
};