From 1d5cb2f03c706c4b1cc36f50fd431f98fdbe7101 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期三, 13 十二月 2023 15:23:33 +0800
Subject: [PATCH] 对number的验证及不重复

---
 controllers/operation.go |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 2a0b25e..e467303 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -77,8 +77,19 @@
 	}
 
 	params.Status = constvar.OperationStatus_Ready
-	params.Number = strconv.FormatInt(time.Now().Unix(), 10)
+	//params.Number = strconv.FormatInt(time.Now().Unix(), 10)
 	params.BaseOperationType = operationType.BaseOperationType
+
+	var numberNum int64
+	if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+	if numberNum > 0 {
+		util.ResponseFormat(c, code.RequestParamError, "鍗曞彿宸插瓨鍦�")
+		return
+	}
+
 	if err := models.NewOperationSearch().Create(&params); err != nil {
 		logx.Errorf("Operation create err: %v", err)
 		util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error())
@@ -145,6 +156,10 @@
 		return errors.New("璇峰~鍏ユ簮鍗曞彿")
 	}
 
+	if params.Number == "" {
+		return errors.New("璇峰~鍏ュ崟鍙�")
+	}
+
 	if params.OperationTypeId == 0 && int(params.BaseOperationType) == 0 {
 		return errors.New("鏈瘑鍒璁板綍绫诲瀷")
 	}

--
Gitblit v1.8.0