boweniac 7 months ago
parent
commit
4c83482bc7

+ 1 - 0
internal/logic/contact/get_contact_list_logic.go

@@ -57,6 +57,7 @@ func (l *GetContactListLogic) GetContactList(req *types.ContactListReq) (*types.
 			labelrelationship.HasLabelsWith(
 				label.IDIn(req.LabelIDs...),
 			),
+			labelrelationship.DeletedAtIsNil(),
 		))
 	}
 	if req.WxWxid != nil {

+ 12 - 2
internal/logic/label/delete_label_logic.go

@@ -2,7 +2,9 @@ package label
 
 import (
 	"context"
+	"fmt"
 	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/ent/contact"
 	"wechat-api/ent/label"
 	"wechat-api/ent/labelrelationship"
 	"wechat-api/internal/svc"
@@ -29,16 +31,24 @@ func NewDeleteLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delet
 
 func (l *DeleteLabelLogic) DeleteLabel(req *types.IDsReq) (*types.BaseMsgResp, error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
-
+	fmt.Printf("req.Ids: %+v", req.Ids)
 	data, err := l.svcCtx.DB.LabelRelationship.Query().
 		Where(
-			labelrelationship.LabelIDIn(req.Ids...),          // Filter by ID
+			labelrelationship.HasLabelsWith(
+				label.IDIn(req.Ids...),
+			), // Filter by ID
 			labelrelationship.OrganizationID(organizationId), // Additional filter by organizationId
+			labelrelationship.DeletedAtIsNil(),
+			labelrelationship.HasContactsWith(
+				contact.OrganizationIDEQ(organizationId),
+				contact.DeletedAtIsNil(),
+			),
 		).
 		Only(l.ctx)
 	//if err != nil {
 	//	return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	//}
+	fmt.Printf("data: %+v", data)
 	if data == nil {
 		_, err := l.svcCtx.DB.Label.Delete().Where(label.IDIn(req.Ids...), label.OrganizationIDEQ(organizationId)).Exec(l.ctx)