cssendmsglogic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 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: in.CsId,
  37. ReceiverId: uniqueId,
  38. GameId: in.GameId,
  39. Uid: in.CsId,
  40. Ext: "",
  41. })
  42. _, _, err := l.svcCtx.KqMsgBoxProducer.SendMessage(l.ctx, kMsg, in.CsId)
  43. if err != nil {
  44. return nil, err
  45. }
  46. return &pb.CsSendMsgResp{}, nil
  47. }