cfb253d96f
Closes HIF-38 owner 业务定义:commission_refund 这个分类只应返回「下级退单导致用户拿到的佣金被扣回」记录。 改动: - queryWithdrawalLogLogic.go: ?biz_type=commission_refund 分支 SQL 过滤从 IN(333,337,338) 改为 = 333 - 同步更新 logic/handler 单测 不在范围: - /commission_return_log(新推荐接口)继续返回 333/337/338 — 前端暂未切,owner 决定不动 - 337/338 不另外开 UI 入口 — 提现记录 status 字段(rejected/cancelled)已表达
117 lines
3.6 KiB
Go
117 lines
3.6 KiB
Go
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"
|
|
"github.com/perfect-panel/server/pkg/constant"
|
|
"github.com/perfect-panel/server/pkg/logger"
|
|
"github.com/perfect-panel/server/pkg/xerr"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
withdrawalLogBizTypeWithdrawal = "withdrawal"
|
|
withdrawalLogBizTypeCommissionRefund = "commission_refund"
|
|
)
|
|
|
|
type QueryWithdrawalLogLogic struct {
|
|
logger.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// NewQueryWithdrawalLogLogic Query Withdrawal Log
|
|
func NewQueryWithdrawalLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryWithdrawalLogLogic {
|
|
return &QueryWithdrawalLogLogic{
|
|
Logger: logger.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *QueryWithdrawalLogLogic) QueryWithdrawalLog(req *types.QueryWithdrawalLogListRequest) (resp *types.QueryWithdrawalLogListResponse, err error) {
|
|
u, ok := l.ctx.Value(constant.CtxKeyUser).(*user.User)
|
|
if !ok {
|
|
l.Error("current user is not found in context")
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
|
|
}
|
|
|
|
page, size := normalizePagination(req.Page, req.Size)
|
|
|
|
switch req.BizType {
|
|
case "", withdrawalLogBizTypeWithdrawal:
|
|
return l.queryWithdrawalLogs(u.Id, page, size)
|
|
case withdrawalLogBizTypeCommissionRefund:
|
|
return l.queryCommissionRefundLogs(u.Id, page, size)
|
|
default:
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "invalid biz_type: %s", req.BizType)
|
|
}
|
|
}
|
|
|
|
func (l *QueryWithdrawalLogLogic) queryWithdrawalLogs(userID int64, page, size int) (*types.QueryWithdrawalLogListResponse, error) {
|
|
query := l.svcCtx.DB.WithContext(l.ctx).Model(&user.Withdrawal{}).Where("user_id = ?", userID)
|
|
|
|
var total int64
|
|
if err := query.Count(&total).Error; err != nil {
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "count withdrawal logs failed: %v", err)
|
|
}
|
|
|
|
var rows []user.Withdrawal
|
|
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 withdrawal logs failed: %v", err)
|
|
}
|
|
|
|
list := make([]types.WithdrawalLog, 0, len(rows))
|
|
for _, row := range rows {
|
|
list = append(list, types.WithdrawalLog{
|
|
Id: row.Id,
|
|
BizType: withdrawalLogBizTypeWithdrawal,
|
|
UserId: row.UserId,
|
|
Amount: row.Amount,
|
|
Content: row.Content,
|
|
Status: row.Status,
|
|
Reason: row.Reason,
|
|
Method: row.Method,
|
|
Account: row.Account,
|
|
QrCodeUrl: row.QrCodeUrl,
|
|
CreatedAt: row.CreatedAt.UnixMilli(),
|
|
UpdatedAt: row.UpdatedAt.UnixMilli(),
|
|
})
|
|
}
|
|
|
|
return &types.QueryWithdrawalLogListResponse{
|
|
List: list,
|
|
Total: total,
|
|
}, nil
|
|
}
|
|
|
|
func (l *QueryWithdrawalLogLogic) queryCommissionRefundLogs(userID int64, page, size int) (*types.QueryWithdrawalLogListResponse, error) {
|
|
queryLogic := NewQueryCommissionReturnLogLogic(l.ctx, l.svcCtx)
|
|
rows, total, err := queryLogic.queryCommissionReturnLogRecordsByEventTypes(userID, page, size, log.CommissionTypeRefund)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := make([]types.WithdrawalLog, 0, len(rows))
|
|
for _, row := range rows {
|
|
list = append(list, types.WithdrawalLog{
|
|
Id: row.LogID,
|
|
BizType: withdrawalLogBizTypeCommissionRefund,
|
|
UserId: row.UserID,
|
|
Amount: row.Amount,
|
|
Content: row.Content,
|
|
CreatedAt: row.CreatedAt,
|
|
UpdatedAt: row.UpdatedAt,
|
|
})
|
|
}
|
|
|
|
return &types.QueryWithdrawalLogListResponse{
|
|
List: list,
|
|
Total: total,
|
|
}, nil
|
|
}
|