add_friend_by_phone_logic.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package add_friend
  2. import (
  3. "context"
  4. "wechat-api/internal/logic/chat"
  5. "wechat-api/internal/service/addfriend"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. "github.com/suyuan32/simple-admin-common/enum/errorcode"
  9. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type AddFriendByPhoneLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewAddFriendByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFriendByPhoneLogic {
  18. return &AddFriendByPhoneLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx}
  22. }
  23. /*
  24. func getWeChatIds(ids any) []string {
  25. nids := []string{}
  26. switch rv := ids.(type) {
  27. case []string:
  28. nids = rv
  29. case string:
  30. nids = append(nids, rv)
  31. }
  32. return nids
  33. }
  34. */
  35. func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddWechatFriendLogInfo) (resp *types.BaseMsgResp, err error) {
  36. // todo: add your logic here and delete this line
  37. if req.Type != 2 {
  38. req.Type = 1
  39. }
  40. if len(req.WeChatIds) == 0 {
  41. req.WeChatIds = append(req.WeChatIds, "")
  42. }
  43. for _, wechatId := range req.WeChatIds {
  44. nreq := &types.AddFriendByPhoneReq{Type: req.Type, WeChatId: wechatId, Phone: req.Phone, Message: req.Message}
  45. //fmt.Println(typekit.PrettyPrint(nreq))
  46. id, err := chat.AppendWechaFriendAddLog(l.ctx, l.svcCtx, nreq)
  47. if err != nil {
  48. logx.Errorf("chat.AppendWechaFriendAddLog err : %s", err)
  49. continue
  50. }
  51. logx.Infof("chat.AppendWechaFriendAddLog succ,get id:%d",
  52. id)
  53. if req.Type != 1 {
  54. continue //企微忽略后面
  55. }
  56. ret := addfriend.NewAddWechatFriendService(l.ctx, l.svcCtx).
  57. FindFriendByContent(wechatId, req.Phone)
  58. if ret {
  59. logx.Infof("call addfriend.NewAddWechatFriendService.FindFriendByContent('%s','%s') maybe succ", wechatId, req.Phone)
  60. }
  61. }
  62. resp = &types.BaseMsgResp{
  63. Msg: errormsg.Success,
  64. Code: errorcode.OK,
  65. }
  66. return resp, nil
  67. }