60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
|
package topup
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"tianyuan-api/apps/user/user"
|
||
|
|
||
|
"tianyuan-api/apps/gateway/internal/svc"
|
||
|
"tianyuan-api/apps/gateway/internal/types"
|
||
|
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type TopListLogic struct {
|
||
|
logx.Logger
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
}
|
||
|
|
||
|
func NewTopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopListLogic {
|
||
|
return &TopListLogic{
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (l *TopListLogic) TopList(req *types.GetTopUpListReq) (resp *types.GetTopUpListResp, err error) {
|
||
|
userId, ok := l.ctx.Value("userId").(int64)
|
||
|
if !ok {
|
||
|
return nil, errors.New("无法获取 userId")
|
||
|
}
|
||
|
list, err := l.svcCtx.Wallets.GetRechargeList(l.ctx, &user.RechargeRequest{
|
||
|
UserId: userId,
|
||
|
Page: req.Page,
|
||
|
PageSize: req.PageSize,
|
||
|
})
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var topUpItemList []types.TopUpItem
|
||
|
|
||
|
for _, p := range list.List {
|
||
|
topUpItemList = append(topUpItemList, types.TopUpItem{
|
||
|
Id: p.Id,
|
||
|
UserId: p.UserId,
|
||
|
TransactionId: p.TransactionId,
|
||
|
OutTradeNo: p.OutTradeNo,
|
||
|
Amount: float64(p.Amount),
|
||
|
PaymentMethod: p.PaymentMethod,
|
||
|
CreatedAt: p.CreatedAt,
|
||
|
UpdatedAt: p.UpdatedAt,
|
||
|
})
|
||
|
}
|
||
|
return &types.GetTopUpListResp{
|
||
|
Total: list.Total,
|
||
|
List: topUpItemList,
|
||
|
}, nil
|
||
|
}
|