cssendmsglogic.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 CsSendMsgLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewCsSendMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CsSendMsgLogic {
  17. return &CsSendMsgLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *CsSendMsgLogic) CsSendMsg(in *pb.CsSendMsgReq) (*pb.CsSendMsgResp, error) {
  24. // 投递到自己的发件箱
  25. message := &model.ChatMessage{
  26. CreateTime: time.Now().Format("2006-01-02 15:04:05"),
  27. Content: in.Content,
  28. Pic: in.Pic,
  29. ReceiverId: in.GameId + "_" + in.PlayerId,
  30. SenderId: in.CsId,
  31. GameId: in.GameId,
  32. Uid: in.CsId,
  33. }
  34. payload, _ := sonic.MarshalString(message)
  35. kMsg, _ := sonic.MarshalString(&model.KqMessage{
  36. Opt: model.CMD_SEND_MESSAGE,
  37. Payload: payload,
  38. Ext: "",
  39. })
  40. _, _, err := l.svcCtx.KqMsgBoxProducer.SendMessage(l.ctx, kMsg, message.SenderId)
  41. if err != nil {
  42. return nil, err
  43. }
  44. return &pb.CsSendMsgResp{}, nil
  45. }