handler.go 1.47 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5
package server

import (
	"context"
	"gomicro-base/api/member"
6
	"gomicro-base/common/errm"
kzkzzzz's avatar
kzkzzzz committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20
	"gomicro-base/common/hashutil"
	"gomicro-base/common/validate"
	"gomicro-base/service/member/internal/model"
	"gomicro-base/service/member/internal/service"
	"gorm.io/gorm"
)

// 检查接口实现
var _ member.MemberHandler = &handler{}

type handler struct {
	svc *service.MemberService
}

21 22 23 24 25 26 27 28
func (h *handler) CheckLoginStatus(ctx context.Context, req *member.CheckLoginReq, resp *member.CheckLoginResp) error {
	return h.svc.CheckLoginStatus(ctx, req)
}

func (h *handler) SetCredit1(ctx context.Context, req *member.SetCredit1Req, resp *member.SetCredit1Resp) error {
	return h.svc.SetCredit1(ctx, req)
}

kzkzzzz's avatar
kzkzzzz committed
29 30 31
func (h *handler) GetMemberInfo(ctx context.Context, req *member.MemberInfoReq, resp *member.MemberInfoResp) error {
	err := validate.Struct(req)
	if err != nil {
32
		return errm.TransParamsError(err)
kzkzzzz's avatar
kzkzzzz committed
33 34 35 36 37
	}

	m, err := h.svc.GetMemberInfo(ctx, req)
	if err != nil {
		if err == gorm.ErrRecordNotFound {
38
			return errm.NotFound(err.Error())
kzkzzzz's avatar
kzkzzzz committed
39 40 41 42 43 44 45 46 47 48 49 50
		}
		return err
	}
	*resp = *h.convertMemberModel(m)
	return nil
}

func (h *handler) convertMemberModel(m *model.ImsDbPlayMember) (resp *member.MemberInfoResp) {
	return &member.MemberInfoResp{
		UserId:   int64(m.Id),
		UserNo:   int64(m.UserNo),
		Avatar:   hashutil.Base64Decode(m.Nickname),
51
		Coins:    m.Credit1.IntPart(),
kzkzzzz's avatar
kzkzzzz committed
52 53 54 55
		CoinIcon: "https://image.whoisamy.shop/attachment/2022/02/15/ca8515b15ad91375537e4c6b67dbfbbbdb30c95b.png",
		RoomId:   "10001",
	}
}