Browse Source

更新状态处理

sun-pc-linux 7 months ago
parent
commit
ae11f5005b
4 changed files with 59 additions and 12 deletions
  1. 12 4
      boxcost/api/bill-produce.go
  2. 13 4
      boxcost/api/bill-product.go
  3. 13 4
      boxcost/api/bill.go
  4. 21 0
      boxcost/api/utils.go

+ 12 - 4
boxcost/api/bill-produce.go

@@ -214,13 +214,21 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.ID)
 	user, _ := getUserById(apictx, userId)
 	logType := "update"
-	// 计算结算价格
+	// 更改状态
+	ok, err := isCompareStatus(apictx, repo.CollectionBillProduce, bill.Id, bill.Status)
+	if err != nil {
+		return nil, err
+	}
 	if bill.Status == "complete" {
-		bill.CompleteTime = time.Now()
-		logType = "complete"
+		if !ok {
+			bill.CompleteTime = time.Now()
+			logType = "complete"
+		}
 	}
 	if bill.Status == "deprecated" {
-		logType = "deprecated"
+		if !ok {
+			logType = "deprecated"
+		}
 	}
 
 	if bill.Remark == "" {

+ 13 - 4
boxcost/api/bill-product.go

@@ -214,13 +214,22 @@ func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.ID)
 	user, _ := getUserById(apictx, userId)
 	logType := "update"
-	// 计算结算价格
+	// 更改状态
+	ok, err := isCompareStatus(apictx, repo.CollectionBillProduct, bill.Id, bill.Status)
+	if err != nil {
+		return nil, err
+	}
 	if bill.Status == "complete" {
-		bill.CompleteTime = time.Now()
-		logType = "complete"
+		if !ok {
+			bill.CompleteTime = time.Now()
+			logType = "complete"
+		}
 	}
 	if bill.Status == "deprecated" {
-		logType = "deprecated"
+		if !ok {
+			logType = "deprecated"
+		}
+
 	}
 
 	if bill.Remark == "" {

+ 13 - 4
boxcost/api/bill.go

@@ -350,14 +350,23 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	userId, _ := primitive.ObjectIDFromHex(apictx.User.ID)
 	user, _ := getUserById(apictx, userId)
+
 	logType := "update"
-	// 计算结算价格
+	// 更改状态
+	ok, err := isCompareStatus(apictx, repo.CollectionBillPurchase, bill.Id, bill.Status)
+	if err != nil {
+		return nil, err
+	}
 	if bill.Status == "complete" {
-		bill.CompleteTime = time.Now()
-		logType = "complete"
+		if !ok {
+			bill.CompleteTime = time.Now()
+			logType = "complete"
+		}
 	}
 	if bill.Status == "deprecated" {
-		logType = "deprecated"
+		if !ok {
+			logType = "deprecated"
+		}
 	}
 	if bill.Remark == "" {
 		bill.Remark = " "

+ 21 - 0
boxcost/api/utils.go

@@ -5,6 +5,7 @@ import (
 	"box-cost/db/repo"
 	"box-cost/log"
 	"bytes"
+	"errors"
 	"fmt"
 	"math"
 	"math/rand"
@@ -22,6 +23,26 @@ import (
 
 var SignatureDir string = "https://www.3dqueen.cloud/box/v1/boxcost/public/"
 
+func isCompareStatus(apictx *ApiSession, collection string, id primitive.ObjectID, sv string) (bool, error) {
+	ok, ret := repo.RepoSeachDocMap(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: collection,
+		Query:       repo.Map{"_id": id},
+		Project:     []string{"status"},
+	})
+	if !ok {
+		return false, errors.New("未找到该单据")
+	}
+	if _, ok := ret["status"]; !ok {
+		return false, errors.New("状态为空")
+	}
+	// 更新状态和完成状态相同
+	if ret["status"].(string) == sv {
+		return true, nil
+	}
+
+	return false, nil
+}
+
 func makeBillQuery(query map[string]interface{}) map[string]interface{} {
 	if query["packId"] != nil {
 		query["packId"], _ = primitive.ObjectIDFromHex(query["packId"].(string))