animeic 1 year ago
parent
commit
6c65667eba
4 changed files with 32 additions and 76 deletions
  1. 1 25
      boxcost/api/bill-produce.go
  2. 1 25
      boxcost/api/bill-product.go
  3. 1 26
      boxcost/api/bill.go
  4. 29 0
      boxcost/api/utils.go

+ 1 - 25
boxcost/api/bill-produce.go

@@ -160,33 +160,9 @@ func GetProduceBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
-	if query["packId"] != nil {
-		query["packId"], _ = primitive.ObjectIDFromHex(query["packId"].(string))
-	}
-	if query["planId"] != nil {
-		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
-	}
-
-	// 时间范围查询
-	// createTime 选中的当天时间
-	st, ok1 := query["startTime"]
-	delete(query, "startTime")
-	et, ok2 := query["endTime"]
-	delete(query, "endTime")
-	if ok1 && ok2 {
-		startTime := st.(string)
-		endTime := et.(string)
-		start, end := getTimeRange(startTime, endTime)
-		query["createTime"] = bson.M{"$gte": start, "$lte": end}
-	}
-	if productName, ok := query["productName"]; ok {
-		delete(query, "productName")
-		query["productName"] = bson.M{"$regex": productName.(string)}
-	}
-
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillProduce,
-		Query:       query,
+		Query:       makeBillQuery(query),
 		Page:        page,
 		Size:        size,
 		Sort:        bson.M{"createTime": -1},

+ 1 - 25
boxcost/api/bill-product.go

@@ -160,33 +160,9 @@ func GetProductBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
-	if query["packId"] != nil {
-		query["packId"], _ = primitive.ObjectIDFromHex(query["packId"].(string))
-	}
-	if query["planId"] != nil {
-		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
-	}
-
-	// 时间范围查询
-	// createTime 选中的当天时间
-	st, ok1 := query["startTime"]
-	delete(query, "startTime")
-	et, ok2 := query["endTime"]
-	delete(query, "endTime")
-	if ok1 && ok2 {
-		startTime := st.(string)
-		endTime := et.(string)
-		start, end := getTimeRange(startTime, endTime)
-		query["createTime"] = bson.M{"$gte": start, "$lte": end}
-	}
-	if productName, ok := query["productName"]; ok {
-		delete(query, "productName")
-		query["productName"] = bson.M{"$regex": productName.(string)}
-	}
-
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillProduct,
-		Query:       query,
+		Query:       makeBillQuery(query),
 		Page:        page,
 		Size:        size,
 		Sort:        bson.M{"createTime": -1},

+ 1 - 26
boxcost/api/bill.go

@@ -168,34 +168,9 @@ func GetBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
-	if query["packId"] != nil {
-		query["packId"], _ = primitive.ObjectIDFromHex(query["packId"].(string))
-	}
-	if query["planId"] != nil {
-		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
-	}
-
-	// 时间范围查询
-	// createTime 选中的当天时间
-	st, ok1 := query["startTime"]
-	delete(query, "startTime")
-	et, ok2 := query["endTime"]
-	delete(query, "endTime")
-	if ok1 && ok2 {
-		startTime := st.(string)
-		endTime := et.(string)
-		start, end := getTimeRange(startTime, endTime)
-		query["createTime"] = bson.M{"$gte": start, "$lte": end}
-	}
-
-	if productName, ok := query["productName"]; ok {
-		delete(query, "productName")
-		query["productName"] = bson.M{"$regex": productName.(string)}
-	}
-
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillPurchase,
-		Query:       query,
+		Query:       makeBillQuery(query),
 		Page:        page,
 		Size:        size,
 		Sort:        bson.M{"createTime": -1},

+ 29 - 0
boxcost/api/utils.go

@@ -20,6 +20,35 @@ import (
 
 var SignatureDir string = "https://www.3dqueen.cloud/box/v1/boxcost/public/"
 
+func makeBillQuery(query map[string]interface{}) map[string]interface{} {
+	if query["packId"] != nil {
+		query["packId"], _ = primitive.ObjectIDFromHex(query["packId"].(string))
+	}
+	if query["planId"] != nil {
+		query["planId"], _ = primitive.ObjectIDFromHex(query["planId"].(string))
+	}
+
+	// 时间范围查询
+	// createTime 选中的当天时间
+	st, ok1 := query["startTime"]
+	delete(query, "startTime")
+	et, ok2 := query["endTime"]
+	delete(query, "endTime")
+	if ok1 && ok2 {
+		startTime := st.(string)
+		endTime := et.(string)
+		start, end := getTimeRange(startTime, endTime)
+		query["createTime"] = bson.M{"$gte": start, "$lte": end}
+	}
+
+	if productName, ok := query["productName"]; ok {
+		delete(query, "productName")
+		query["productName"] = bson.M{"$regex": productName.(string)}
+	}
+
+	return query
+}
+
 // func getRowHeight(content string, width float64,lineHeight float64) float64 {
 // 第一个参数为 行宽 第二个参数为 行高
 func getRowHeight(content string, params ...float64) float64 {