Browse Source

add bill list sort

sun-pc-linux 1 month ago
parent
commit
883fbf7f8c
3 changed files with 31 additions and 3 deletions
  1. 10 1
      boxcost/api/bill-produce.go
  2. 11 1
      boxcost/api/bill-product.go
  3. 10 1
      boxcost/api/bill.go

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

@@ -176,13 +176,22 @@ func GetProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 func GetProduceBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
+	sort := "createTime"
+	if v, ok := query["sort"]; ok {
+		if _sort, ok := v.(string); ok {
+			if len(_sort) > 0 {
+				sort = _sort
+			}
+		}
+		delete(query, "sort")
+	}
 
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillProduce,
 		Query:       makeBillQuery(query),
 		Page:        page,
 		Size:        size,
-		Sort:        bson.M{"createTime": -1},
+		Sort:        bson.M{sort: -1},
 	}
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
 }

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

@@ -176,12 +176,22 @@ func GetProductBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
+	sort := "createTime"
+	if v, ok := query["sort"]; ok {
+		if _sort, ok := v.(string); ok {
+			if len(_sort) > 0 {
+				sort = _sort
+			}
+		}
+		delete(query, "sort")
+	}
+
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillProduct,
 		Query:       makeBillQuery(query),
 		Page:        page,
 		Size:        size,
-		Sort:        bson.M{"createTime": -1},
+		Sort:        bson.M{sort: -1},
 	}
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
 }

+ 10 - 1
boxcost/api/bill.go

@@ -225,13 +225,22 @@ func GetBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 func GetBills(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
+	sort := "createTime"
+	if v, ok := query["sort"]; ok {
+		if _sort, ok := v.(string); ok {
+			if len(_sort) > 0 {
+				sort = _sort
+			}
+		}
+		delete(query, "sort")
+	}
 
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionBillPurchase,
 		Query:       makeBillQuery(query),
 		Page:        page,
 		Size:        size,
-		Sort:        bson.M{"createTime": -1},
+		Sort:        bson.M{sort: -1},
 	}
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), option)
 }