playersendmsglogic.go 1.1 KB

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