playersendmsglogic.go 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package logic
  2. import (
  3. "context"
  4. "encoding/json"
  5. "time"
  6. "ylink/core/cmd/rpc/internal/svc"
  7. "ylink/core/cmd/rpc/pb"
  8. "ylink/ext/model"
  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. msg, _ := json.Marshal(model.ChatMessage{
  26. CreateTime: time.Now().Format("2006-01-02 15:04:05"),
  27. Content: in.Content,
  28. Pic: in.Pic,
  29. ReceiverId: "",
  30. SenderId: in.PlayerId,
  31. GameId: in.GameId,
  32. })
  33. _, _, err := l.svcCtx.SendBoxProducer.SendMessage(string(msg), in.PlayerId)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return &pb.PlayerSendMsgResp{}, nil
  38. }