Files
hi-server/internal/logic/public/user/queryWithdrawalLogLogic.go
T
shanshanzhong147 2be25df7d2 feat: 提现优化 — 取消状态 + 收款方式 + TableName 修复 (HIF-42)
- P04: 修复 Withdrawal.TableName() 返回正确表名 withdrawals
- P03: 新增提现状态常量 (constant/withdrawal.go),消除魔法数字 0/1/2/3;
       新增 CommissionTypeWithdrawCancel (338) 和 WithdrawalCancelForbidden 错误码
- P02: 迁移 02123 为 withdrawals 表添加 method/account/qr_code_url 列;
       扩展 Withdrawal GORM 模型和 API 类型(CommissionWithdrawRequest、WithdrawalLog);
       申请提现时增加收款方式校验逻辑
- P01: 新增用户取消提现接口 POST /v1/public/user/withdrawal_cancel;
       仅可取消自己的待审核提现,退还佣金并写佣金日志
- P05: 管理端提现列表新增 method 过滤参数

Co-authored-by: multica-agent <github@multica.ai>
2026-05-25 20:39:45 -07:00

80 lines
2.2 KiB
Go

package user
import (
"context"
"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"
)
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 := req.Page
size := req.Size
if page <= 0 {
page = 1
}
if size <= 0 {
size = 10
}
query := l.svcCtx.DB.WithContext(l.ctx).Model(&user.Withdrawal{}).Where("user_id = ?", u.Id)
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,
UserId: row.UserId,
Amount: row.Amount,
Method: row.Method,
Account: row.Account,
QrCodeUrl: row.QrCodeUrl,
Content: row.Content,
Status: row.Status,
Reason: row.Reason,
CreatedAt: row.CreatedAt.UnixMilli(),
UpdatedAt: row.UpdatedAt.UnixMilli(),
})
}
return &types.QueryWithdrawalLogListResponse{
List: list,
Total: total,
}, nil
}