playerfetchcsinfologic.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package logic
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "ylink/comm/result"
  6. "ylink/core/inner/rpc/internal/ext"
  7. "ylink/core/inner/rpc/internal/svc"
  8. "ylink/core/inner/rpc/pb"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type PlayerFetchCsInfoLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewPlayerFetchCsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PlayerFetchCsInfoLogic {
  17. return &PlayerFetchCsInfoLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *PlayerFetchCsInfoLogic) PlayerFetchCsInfo(in *pb.InnerPlayerFetchCsInfoReq) (*pb.InnerPlayerFetchCsInfoResp, error) {
  24. if playerInfo := ext.GetConnectedPlayerInfo(in.GameId, in.PlayerId); playerInfo != nil {
  25. // 玩家已连接
  26. if csInfo := ext.GetCsInfo(playerInfo.CsId); csInfo != nil {
  27. return &pb.InnerPlayerFetchCsInfoResp{
  28. CsId: csInfo.CsId,
  29. CsNickname: csInfo.CsNickname,
  30. CsAvatarUrl: csInfo.CsAvatarUrl,
  31. CsSignature: csInfo.CsSignature,
  32. OnlineStatus: csInfo.OnlineStatus,
  33. }, nil
  34. }
  35. return nil, errors.Wrap(result.NewErrMsg("查询的客服不存在"), "")
  36. }
  37. return nil, errors.Wrap(result.NewErrMsg("玩家未连接"), "")
  38. }