From 2716487d13f3521adeb25a48aa07a89f885d32c7 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期一, 09 十月 2023 09:36:08 +0800
Subject: [PATCH] 仓库功能修改

---
 controllers/operation.go |   50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 872fb4c..3e1e36f 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -6,6 +6,7 @@
 	"github.com/gin-gonic/gin"
 	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
+	"sort"
 	"strconv"
 	"time"
 	"wms/constvar"
@@ -47,14 +48,43 @@
 		return
 	}
 
+	if CheckDetailsRepeat(params.Details) {
+		util.ResponseFormat(c, code.RequestParamError, "鏄庣粏涓笉鑳藉瓨鍦ㄩ噸澶嶇殑浜у搧")
+		return
+	}
+
+	operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+
 	params.Status = constvar.OperationStatus_Ready
 	params.Number = strconv.FormatInt(time.Now().Unix(), 10)
+	params.BaseOperationType = operationType.BaseOperationType
 	if err := models.NewOperationSearch().Create(&params); err != nil {
 		logx.Errorf("Operation create err: %v", err)
 		util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error())
 		return
 	}
 	util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
+}
+
+func CheckDetailsRepeat(details []*models.OperationDetails) bool {
+	detailIDs := []string{}
+	var tempID string
+	for _, v := range details {
+		detailIDs = append(detailIDs, v.ProductId)
+	}
+	sort.Strings(detailIDs)
+	for _, v := range detailIDs {
+		if v != tempID {
+			tempID = v
+		} else {
+			return true
+		}
+	}
+	return false
 }
 
 func (slf OperationController) FormatLocation(params *models.Operation) error {
@@ -146,10 +176,7 @@
 	search := models.NewOperationSearch()
 	search.SetPage(params.Page, params.PageSize)
 	if params.Number != "" {
-		search.SetNumber(params.Number)
-	}
-	if params.SourceNumber != "" {
-		search.SetSourceNumber(params.SourceNumber)
+		search.SetKeyword(params.Number)
 	}
 	list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find()
 	if err != nil {
@@ -194,6 +221,10 @@
 	}
 	if err := slf.CheckParams(params); err != nil {
 		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+	if CheckDetailsRepeat(params.Details) {
+		util.ResponseFormat(c, code.RequestParamError, "鏄庣粏涓笉鑳藉瓨鍦ㄩ噸澶嶇殑浜у搧")
 		return
 	}
 	if err := slf.FormatLocation(&params); err != nil {
@@ -323,8 +354,14 @@
 						if err := tx.Save(listProdt[k]).Error; err != nil {
 							return err
 						}
+						//TODO:鍑哄叆搴撶殑finish鍜屾姤搴熺殑finish閮借澧炲姞瀵筶ocation_product_amount琛ㄦ暟閲忕殑鏇存柊,鍥犱负姝よ〃鏈塒roductCategory瀛楁锛屾墍浠peration_details琛ㄤ腑瑕佸鍔燩roductCategoryId瀛楁
+						//var locAmount models.LocationProductAmount
+						//if err := models.NewLocationProductAmountSearch().Orm.Table("wms_location_produt_amount").Joins("inner join wms_location_product on wms_location_produt.id=wms_location_produt_amount.location_product_id").Where("wms_location_produt.product_id=? and wms_location_produt.location_id=?",operation.ToLocationID,v.ID).First(&locAmount).Error;err!=nil {
+						//	return err
+						//}
 					}
 				}
+
 			}
 			if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing {
 				for k, v := range listProdt {
@@ -372,10 +409,7 @@
 	search.SetPage(params.Page, params.PageSize)
 	search.SetPage(params.Page, params.PageSize)
 	if params.Number != "" {
-		search.SetNumber(params.Number)
-	}
-	if params.SourceNumber != "" {
-		search.SetSourceNumber(params.SourceNumber)
+		search.SetKeyword(params.Number)
 	}
 	list, total, err := search.SetPreload(true).SetOrder("created_at desc").Find()
 	if err != nil {

--
Gitblit v1.8.0