浏览代码

// 普通用户:只能查自己的组织
// 超管1未传,查自己的 2. // 传了正整数,查传入的 3传了 0:不加任何条件(查全部)

lichangdong 1 周之前
父节点
当前提交
039d494339
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      internal/logic/Wx/get_select_wx_list_logic.go

+ 12 - 2
internal/logic/Wx/get_select_wx_list_logic.go

@@ -32,18 +32,28 @@ func (l *GetSelectWxListLogic) GetSelectWxList(req *types.WxSelectListReq) (resp
 	organizationId := l.ctx.Value("organizationId").(uint64)
 	isAdmin := l.ctx.Value("isAdmin").(bool)
 	var predicates []predicate.Wx
-	var ctype uint64 = 1
+	ctype := uint64(1)
 	if req.Ctype != nil && *req.Ctype > 0 {
 		ctype = *req.Ctype
 	}
 	predicates = append(predicates, wx.Ctype(ctype))
+
+	// 组织 ID 条件逻辑
 	if !isAdmin {
+		// 普通用户:只能查自己的组织
 		predicates = append(predicates, wx.OrganizationIDEQ(organizationId))
 	} else {
-		if req.OrganizationId != nil && *req.OrganizationId != 0 {
+		// 超管
+		if req.OrganizationId == nil {
+			// 未传,查自己的
+			predicates = append(predicates, wx.OrganizationIDEQ(organizationId))
+		} else if *req.OrganizationId > 0 {
+			// 传了正整数,查传入的
 			predicates = append(predicates, wx.OrganizationIDEQ(*req.OrganizationId))
 		}
+		// 传了 0:不加任何条件(查全部)
 	}
+
 	data, err := l.svcCtx.DB.Wx.Query().Where(predicates...).Order(ent.Desc(wx.FieldOrganizationID)).All(l.ctx)
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)