'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;