animeic 2 years ago
parent
commit
daca08db18
1 changed files with 22 additions and 25 deletions
  1. 22 25
      boxcost/api/supplier.go

+ 22 - 25
boxcost/api/supplier.go

@@ -113,7 +113,7 @@ func GetSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	page, size, query := UtilQueryPageSize(c)
-	//category =>根据内容查询 供应对应内容的供应商
+
 	emtyPage := &repo.PageResult{
 		Total: 0,
 		Size:  size,
@@ -121,35 +121,36 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		List:  []map[string]interface{}{},
 	}
 	listOut := []map[string]interface{}{}
-	if len(query) == 0 {
-		option := &repo.PageSearchOptions{
-			CollectName: repo.CollectionSupplier,
-			Query:       query,
-			Page:        page,
-			Size:        size,
-			Sort:        bson.M{"createTime": -1},
-		}
-		return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
+
+	flag := false
+	if query["matId"] != nil || query["craftId"] != nil || query["productId"] != nil {
+		flag = true
 	}
+
+	filtter := repo.Map{}
 	if _name, ok := query["name"]; ok {
-		delete(query, "name")
-		query["name"] = bson.M{"$regex": _name.(string)}
+		filtter["name"] = bson.M{"$regex": _name.(string)}
 	}
 
 	if cate, ok := query["category"]; ok {
-		delete(query, "category")
-		query["categorys"] = bson.M{"$in": []string{cate.(string)}}
+		filtter["categorys"] = bson.M{"$in": []string{cate.(string)}}
+	}
+
+	if !flag {
 		option := &repo.PageSearchOptions{
 			CollectName: repo.CollectionSupplier,
 			// Query:       repo.Map{"categorys": bson.M{"$in": []string{cate.(string)}}},
-			Query: query,
+			Query: filtter,
 			Page:  page,
 			Size:  size,
 			Sort:  bson.M{"createTime": -1},
 		}
 		return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
+
 	}
 
+	//category =>根据内容查询 供应对应内容的供应商
+
 	if query["matId"] != nil {
 		matId := query["matId"].(string)
 		if len(matId) < 1 {
@@ -169,11 +170,6 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 
 	if query["craftId"] != nil {
-
-		// if query["craftId"] == nil {
-		// 	return nil, fmt.Errorf("参数错误 craftId 或matId不能为空")
-		// }
-
 		cratf := &model.Craft{}
 
 		ok, _ := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
@@ -271,13 +267,14 @@ func GetPlanSuppliers(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return emtyPage, nil
 	}
 
-	query["_id"] = bson.M{"$in": suppliers}
+	filtter["_id"] = bson.M{"$in": suppliers}
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionSupplier,
-		Query:       repo.Map{"_id": bson.M{"$in": suppliers}},
-		Page:        page,
-		Size:        size,
-		Sort:        bson.M{"createTime": -1},
+		Query:       filtter,
+		// Query:       repo.Map{"_id": bson.M{"$in": suppliers}},
+		Page: page,
+		Size: size,
+		Sort: bson.M{"createTime": -1},
 	}
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
 }