oms/backend/app/model/operationLog.js
liufumingren a9cca6aa6f feat(log): 新增操作日志(店铺商品/系统商品/组合商品),并修正明细口径
操作日志:
- 新增 operation_logs 表与 model/service/controller,接口 GET /api/operation-logs
  (按 target_type + target_id 分页查询,主体隔离,按时间倒序)
- 店铺商品:采集进系统、平台已无此商品被移出/下架、绑定/解绑均留痕(含原绑定与受影响订单数)
- 系统商品:新增 / 修改(记录变更字段与前后值)/ 删除
- 组合商品:新增 / 修改(含子商品构成前后值)/ 删除
- 日志为旁路能力:写入失败只告警,不影响业务操作

明细口径修正:
- 已审核订单(待推送及之后)的明细在审核时已锁定,重算时按状态过滤,
  重新拉单与改绑定都不再波及(原先会覆盖老表 order_items 的解析结果)
- 组合商品构成/系统商品资料变更后,重建绑定方的待审核订单明细与商品摘要;
  并修正重建时读不到同事务内未提交构成的问题(loadBindings/loadComboItems 传事务)

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

35 lines
1.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';
/**
* 操作日志模型,对应 operation_logs 表。
*
* 三类对象(店铺商品 / 系统商品 / 组合商品)共用一张日志表,
* 通过 target_type + target_id 定位,页面按对象查历史操作记录。
* @param {Egg.Application} app egg application
* @return {object} operationLog model
*/
module.exports = app => {
const { BIGINT, STRING, JSON: JsonType, DATE } = app.Sequelize;
const OperationLog = app.model.define('operation_log', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
target_type: { type: STRING(32), allowNull: false, comment: '对象类型:shop_product / product / combo_product' },
target_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '对象ID' },
action: { type: STRING(32), allowNull: false, comment: '动作码:create / update / bind / unbind / remove / offline / delete' },
title: { type: STRING(255), allowNull: false, comment: '操作说明' },
detail: { type: JsonType, comment: '操作明细(前后值等)' },
source: { type: STRING(20), allowNull: false, defaultValue: 'ui', comment: '来源:ui / sync / system' },
operator_id: { type: BIGINT.UNSIGNED, comment: '操作人用户ID' },
operator_name: { type: STRING(50), comment: '操作人名称' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
OperationLog.associate = () => {
app.model.OperationLog.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
};
return OperationLog;
};