package sys_payment

import (
	"context"

	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"

	v1 "kami/api/sys_payment/v1"

	"github.com/gogf/gf/v2/errors/gcode"
)

func (c *ControllerV1) SysPaymentRecordsGet(ctx context.Context, req *v1.SysPaymentRecordsGetReq) (res *v1.SysPaymentRecordsGetRes, err error) {
	userInfo, err := service.SysAuth().LoginWithIFrameAndLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "权限不足")
		return
	}
	if userInfo.Id != "" {
		req.UserId = userInfo.Id
	}
	total, data, err := service.SysUserPayment().ListRecords(ctx, model.SysUserRecordListInput{
		SysPaymentRecordsGetReq: *req,
	})
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "获取用户充值记录失败")
	}
	res = &v1.SysPaymentRecordsGetRes{}
	res.Total = total
	res.List = data
	return
}
