oms/backend/app/model/shopProduct.js
liufumingren 69b26bf7cc feat(platform): 统一系统预设平台编码,外部平台标识按预设转换
- 新增 app/lib/platformCode.js:17 个预设平台(1688/DW/DYCS/DYGX/DYXD/JD/KS/MAOCHAO/
  MTYYJK/OFFLINE/OTHER/PDD/SPH/TB/TGC/TM/XHS)+ 别名表(中英文、大小写)+ 未知落 OTHER
- 店管家硬编码 PlatformType → 预设映射(Pinduoduo→PDD、TouTiao→DYXD、WxVideo→SPH、
  Alibaba→1688、Taobao→TB、KuaiShou→KS、Tmall→TM、JingDong→JD…)
- 拉单落库统一:orders.platform_type、order_status_*.source_platform_code/name
  写预设编码与本系统中文名(推 WMS 的 sourcePlatformCode/Name 同源)
- 店铺商品 platform_type 同样落预设编码
- 新增 scripts/migrate-platform-codes.js(npm run platforms:migrate):
  按同一口径迁移历史数据,默认 dry-run;已执行迁移 14 类(订单 27 / 店铺商品 44 / 状态表 15+13)
- 前端新增 constants/platform.ts(code→中文名):店铺商品「平台类型」列显示中文名,
  订单详情新增「来源平台」行
- 新增 platformCode 单测(5 项,含未知平台落 OTHER)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-03 17:31:44 +08:00

46 lines
2.7 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';
/**
* 店铺商品模型,对应 shop_products 表
* 采集自平台店铺的商品,可单向绑定系统商品(products)或组合商品(combo_products):
* bind_type:0未绑定 1系统商品 2组合商品;未绑定时两个商品ID均为空
* @param {Egg.Application} app egg application
* @return {object} shopProduct model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, INTEGER, JSON, DATE } = app.Sequelize;
const ShopProduct = app.model.define('shop_product', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
shop_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属店铺ID' },
outer_item_id: { type: STRING(100), allowNull: false, comment: '平台商品ID' },
outer_sku_id: { type: STRING(100), comment: '平台规格ID(SKU),无规格时为空' },
title: { type: STRING(255), comment: '商品标题' },
outer_code: { type: STRING(100), comment: '商家编码,用于与系统商品匹配' },
spec: { type: STRING(255), comment: '规格' },
image: { type: STRING(255), comment: '图片' },
price: { type: DECIMAL(12, 2), comment: '店铺售价' },
stock: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '采集到的库存' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '店铺商品状态:1在售 0下架' },
platform_type: { type: STRING(32), comment: '平台类型:系统预设平台编码(PDD/DYXD/SPH…)' },
external_shop_id: { type: STRING(64), comment: '外部平台的店铺ID(如店管家 ShopId)' },
bind_type: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '绑定类型:0未绑定 1系统商品 2组合商品' },
product_id: { type: BIGINT.UNSIGNED, comment: '绑定的系统商品ID,未绑定为空' },
combo_product_id: { type: BIGINT.UNSIGNED, comment: '绑定的组合商品ID,未绑定为空' },
raw: { type: JSON, comment: '采集到的原始数据' },
synced_at: { type: DATE, comment: '最近一次采集时间' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
ShopProduct.associate = () => {
app.model.ShopProduct.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.ShopProduct.belongsTo(app.model.Shop, { foreignKey: 'shop_id', as: 'shop' });
app.model.ShopProduct.belongsTo(app.model.Product, { foreignKey: 'product_id', as: 'product' });
app.model.ShopProduct.belongsTo(app.model.ComboProduct, { foreignKey: 'combo_product_id', as: 'comboProduct' });
};
return ShopProduct;
};