oms/backend/app/model/shop.js
liufumingren 7c8e531362 feat(shop): 店铺/店铺商品关联货主与打单平台权限限制
- shops、shop_products 新增 subsidiary_id,店铺商品货主跟随店铺并按店铺回填历史数据
- 店铺列表/详情/新增/编辑/删除按货主范围隔离:货主权限仅可见/可维护自己所属公司的店铺,
  新增必须选货主,货主下拉仅自己所属公司;集团改店铺货主时店铺商品同步跟随
- 外部打单平台导入的店铺(type=2)在货主权限下只读:仅保留拉取订单、同步商品,不可编辑/删除
- 打单平台相关接口(平台资料、账号、商家、快递接口、外部发货)加集团权限门禁;添加店铺必须指定货主
- 货主权限菜单隐藏「外部打单平台」;店铺商品列表/绑定按货主范围隔离
- 店铺与店铺商品导出新增货主列并按范围收窄

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 02:15:42 +08:00

50 lines
3.4 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';
/**
* 店铺模型,对应 shops 表(归属于主体,一个主体可有多个平台店铺)
* @param {Egg.Application} app egg application
* @return {object} shop model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, INTEGER, JSON, DATE } = app.Sequelize;
const Shop = app.model.define('shop', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
subsidiary_id: { type: BIGINT.UNSIGNED, comment: '所属货主(下属公司ID)' },
code: { type: STRING(50), allowNull: false, comment: '店铺编码(平台店铺ID或自定义编码,OMS 内新建时按 OMS 前缀自动生成)' },
name: { type: STRING(100), allowNull: false, comment: '店铺名称' },
platform: { type: STRING(50), comment: '所属平台:taobao/pdd/douyin/jd/other' },
contact_name: { type: STRING(50), comment: '联系人' },
contact_phone: { type: STRING(20), comment: '联系电话' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
type: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '店铺类型:1平台店铺 2外部打单平台商家 3数据库模式(预留)' },
external_print_account_id: { type: BIGINT.UNSIGNED, comment: '来源外部打单账号ID(type=2 时有值)' },
external_data: { type: JSON, comment: '外部打单平台返回的商家原始结构' },
db_host: { type: STRING(255), comment: '数据库地址(type=3 数据库模式店铺使用,预留)' },
db_port: { type: INTEGER, comment: '数据库端口(type=3 数据库模式店铺使用,预留)' },
db_name: { type: STRING(100), comment: '数据库名(type=3 数据库模式店铺使用,预留)' },
db_username: { type: STRING(100), comment: '数据库账号(type=3 数据库模式店铺使用,预留)' },
db_password: { type: STRING(255), comment: '数据库密码(type=3 数据库模式店铺使用,预留,接口不回显)' },
auto_fetch_order: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '是否自动拉取订单:1是 0否' },
auto_fetch_interval: { type: INTEGER, allowNull: false, defaultValue: 3, comment: '自动拉取订单间隔(分钟,最小 3)' },
last_order_sync_at: { type: DATE, comment: '最近一次拉取订单时间' },
last_order_sync_msg: { type: STRING(255), comment: '最近一次拉取订单结果/失败原因' },
extra: { type: JSON, comment: '扩展配置 JSON:授权信息、接口参数等' },
remark: { type: STRING(255), comment: '备注' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
Shop.associate = () => {
app.model.Shop.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.Shop.belongsTo(app.model.PrincipalSubsidiary, { foreignKey: 'subsidiary_id', as: 'subsidiary' });
app.model.Shop.belongsTo(app.model.ExternalPrintAccount, { foreignKey: 'external_print_account_id', as: 'externalPrintAccount' });
app.model.Shop.hasMany(app.model.ShopProduct, { foreignKey: 'shop_id', as: 'shopProducts' });
app.model.Shop.hasMany(app.model.Order, { foreignKey: 'shop_id', as: 'orders' });
app.model.Shop.hasMany(app.model.OrderItem, { foreignKey: 'shop_id', as: 'orderItems' });
};
return Shop;
};