playersendmsglogic.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. uniqueId := in.GameId + "_" + in.PlayerId
  26. t := time.Now()
  27. payload, _ := sonic.MarshalString(&model.ChatMessage{
  28. CreateTime: t.Format("2006-01-02 15:04:05"),
  29. Content: in.Content,
  30. Pic: in.Pic,
  31. })
  32. kMsg, _ := sonic.MarshalString(&model.KqMessage{
  33. Opt: model.CMD_SEND_MESSAGE,
  34. CreateTs: t.Unix(),
  35. Payload: payload,
  36. SenderId: uniqueId,
  37. GameId: in.GameId,
  38. Uid: in.PlayerId,
  39. Ext: "",
  40. })
  41. _, _, err := l.svcCtx.KqMsgBoxProducer.SendMessage(l.ctx, kMsg, uniqueId)
  42. if err != nil {
  43. return nil, err
  44. }
  45. return &pb.PlayerSendMsgResp{}, nil
  46. }