操作日志: - 新增 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>
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
'use strict';
|
||
|
||
const { Controller } = require('egg');
|
||
|
||
/**
|
||
* @controller OperationLogController 操作日志
|
||
* 记录店铺商品 / 系统商品 / 组合商品的关键操作,按对象查询历史记录
|
||
*/
|
||
class OperationLogController extends Controller {
|
||
/**
|
||
* @summary 操作日志列表
|
||
* @description 按 target_type + target_id 查询某个对象的操作记录,按时间倒序分页返回
|
||
* @router get /api/operation-logs
|
||
* @apikey
|
||
* @request query string *target_type 对象类型:shop_product 店铺商品 / product 系统商品 / combo_product 组合商品
|
||
* @request query integer *target_id 对象ID
|
||
* @request query integer page 页码,默认 1
|
||
* @request query integer pageSize 每页条数,默认 20
|
||
* @request query integer principal_id 所属主体ID(必填,需当前账号已绑定该主体)
|
||
* @response 200 operationLogListResponse success
|
||
*/
|
||
async index() {
|
||
const { ctx } = this;
|
||
const targetType = String(ctx.query.target_type || '').trim();
|
||
const targetId = Number(ctx.query.target_id);
|
||
|
||
if (![ 'shop_product', 'product', 'combo_product' ].includes(targetType)) {
|
||
ctx.status = 400;
|
||
ctx.body = { code: 400, message: 'target_type 只能为 shop_product / product / combo_product' };
|
||
return;
|
||
}
|
||
if (!targetId) {
|
||
ctx.status = 400;
|
||
ctx.body = { code: 400, message: 'target_id 为必填项' };
|
||
return;
|
||
}
|
||
|
||
ctx.body = {
|
||
code: 0,
|
||
message: 'success',
|
||
data: await ctx.service.operationLog.page({ targetType, targetId }),
|
||
};
|
||
}
|
||
}
|
||
|
||
module.exports = OperationLogController;
|