playersendmsglogic.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package logic
  2. import (
  3. "context"
  4. "github.com/bytedance/sonic"
  5. "time"
  6. "ylink/comm/model"
  7. "ylink/core/cmd/rpc/internal/svc"
  8. "ylink/core/cmd/rpc/pb"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type PlayerSendMsgLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewPlayerSendMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PlayerSendMsgLogic {
  17. return &PlayerSendMsgLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *PlayerSendMsgLogic) PlayerSendMsg(in *pb.PlayerSendMsgReq) (*pb.PlayerSendMsgResp, error) {
  24. // 投递到自己的发件箱
  25. message := &model.KqMessage{
  26. CreateTime: time.Now().Format("2006-01-02 15:04:05"),
  27. Content: in.Content,
  28. Pic: in.Pic,
  29. SenderId: in.GameId + "_" + in.PlayerId,
  30. GameId: in.GameId,
  31. Uid: in.PlayerId,
  32. }
  33. kMsg, _ := sonic.MarshalString(message)
  34. _, _, err := l.svcCtx.KqMsgBoxProducer.SendMessage(l.ctx, kMsg, message.SenderId)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return &pb.PlayerSendMsgResp{}, nil
  39. }