boweniac 3 месяцев назад
Родитель
Сommit
8afdd2d706

+ 3 - 1
internal/logic/Wxhook/get_friends_and_groups_logic.go

@@ -99,7 +99,6 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 					OnConflict().
 					UpdateNewValues().
 					ID(l.ctx)
-				l.Infof("----------------l.svcCtx.DB.Contact.Create err--------------: %+v", err)
 				if err == nil {
 					lags := splitStringToIntArray(friend.Lag)
 					newFriendIds[id] = lags
@@ -176,6 +175,7 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 					SetGname(chatroom.Gname).
 					SetMarkname(chatroom.Markname).
 					SetV3(chatroom.V3).
+					SetOrganizationID(organizationId).
 					OnConflict().
 					UpdateNewValues().
 					ID(l.ctx)
@@ -193,6 +193,7 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 					SetNickname(gh.Nickname).
 					SetMarkname(gh.Markname).
 					SetV3(gh.V3).
+					SetOrganizationID(organizationId).
 					OnConflict().
 					UpdateNewValues().
 					ID(l.ctx)
@@ -229,6 +230,7 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 				SetNickname(friend.Nickname).
 				SetHeadimg(friend.Avatar).
 				SetSex(cast.ToInt(friend.Gender)).
+				SetOrganizationID(organizationId).
 				OnConflict().
 				UpdateNewValues().
 				SetOrganizationID(organizationId).

+ 8 - 1
internal/logic/contact/add_new_friend_logic.go

@@ -2,6 +2,7 @@ package contact
 
 import (
 	"context"
+	"wechat-api/ent/predicate"
 	"wechat-api/hook"
 
 	"wechat-api/ent/wx"
@@ -27,7 +28,13 @@ func NewAddNewFriendLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddN
 
 func (l *AddNewFriendLogic) AddNewFriend(req *types.AddNewFriendReq) (*types.BaseMsgResp, error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
-	wxInfo, err := l.svcCtx.DB.Wx.Query().Where(wx.Wxid(req.OwnerWxid), wx.OrganizationIDEQ(organizationId)).First(l.ctx)
+	isAdmin := l.ctx.Value("isAdmin").(bool)
+	var predicates []predicate.Wx
+	predicates = append(predicates, wx.Wxid(req.OwnerWxid))
+	if !isAdmin {
+		predicates = append(predicates, wx.OrganizationIDEQ(organizationId))
+	}
+	wxInfo, err := l.svcCtx.DB.Wx.Query().Where(predicates...).First(l.ctx)
 	if err != nil {
 		l.Error("查询微信信息失败", err)
 		return nil, err