新功能(#26): 拆分退款日志查询接口

拆分用户中心退款日志查询:

- 新增 GET /v1/public/user/commission_return_log(333/337/338)
- 旧 GET /v1/public/user/withdrawal_log?biz_type=commission_refund 复用新逻辑做兼容
- 默认 withdrawal_log 行为不变(仍查 withdrawals 表)
- 单测覆盖 333/337/338 happy path、坏 JSON 跳过、object_id 隔离、handler 级 HTTP 响应

父 issue: HIF-25
子 issue: HIF-26
This commit is contained in:
2026-06-11 22:02:22 -07:00
committed by GitHub
parent 3e6318dcdf
commit f11097ab83
9 changed files with 494 additions and 70 deletions
@@ -3,7 +3,6 @@ package user
import (
"context"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/model/user"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
@@ -40,14 +39,7 @@ func (l *QueryWithdrawalLogLogic) QueryWithdrawalLog(req *types.QueryWithdrawalL
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
}
page := req.Page
size := req.Size
if page <= 0 {
page = 1
}
if size <= 0 {
size = 10
}
page, size := normalizePagination(req.Page, req.Size)
switch req.BizType {
case "", withdrawalLogBizTypeWithdrawal:
@@ -97,46 +89,22 @@ func (l *QueryWithdrawalLogLogic) queryWithdrawalLogs(userID int64, page, size i
}
func (l *QueryWithdrawalLogLogic) queryCommissionRefundLogs(userID int64, page, size int) (*types.QueryWithdrawalLogListResponse, error) {
query := l.svcCtx.DB.WithContext(l.ctx).
Model(&log.SystemLog{}).
Where("`type` = ? AND object_id = ? AND `content` LIKE ?", log.TypeCommission.Uint8(), userID, "%\"type\":333%")
var total int64
if err := query.Count(&total).Error; err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count commission refund logs failed: %v", err)
}
var rows []log.SystemLog
if err := query.Order("id DESC").Limit(size).Offset((page - 1) * size).Find(&rows).Error; err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query commission refund logs failed: %v", err)
queryLogic := NewQueryCommissionReturnLogLogic(l.ctx, l.svcCtx)
rows, total, err := queryLogic.queryCommissionReturnLogRecords(userID, page, size)
if err != nil {
return nil, err
}
list := make([]types.WithdrawalLog, 0, len(rows))
for _, row := range rows {
var content log.Commission
if err := content.Unmarshal([]byte(row.Content)); err != nil {
l.Errorw("unmarshal commission refund log content failed",
logger.Field("log_id", row.Id),
logger.Field("error", err.Error()),
)
continue
}
if content.Type != log.CommissionTypeRefund {
continue
}
timestamp := content.Timestamp
if timestamp == 0 {
timestamp = row.CreatedAt.UnixMilli()
}
list = append(list, types.WithdrawalLog{
Id: row.Id,
Id: row.LogID,
BizType: withdrawalLogBizTypeCommissionRefund,
UserId: row.ObjectID,
Amount: content.Amount,
UserId: row.UserID,
Amount: row.Amount,
Content: row.Content,
CreatedAt: timestamp,
UpdatedAt: timestamp,
CreatedAt: row.CreatedAt,
UpdatedAt: row.UpdatedAt,
})
}