cssendmsglogic.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.KqMessage{
  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. kMsg, _ := sonic.MarshalString(message)
  35. _, _, err := l.svcCtx.KqMsgBoxProducer.SendMessage(l.ctx, kMsg, message.SenderId)
  36. if err != nil {
  37. return nil, err
  38. }
  39. return &pb.CsSendMsgResp{}, nil
  40. }