From 20acdf9648c20c4b1e0b03af98bd0010bab66f7b Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期二, 05 九月 2023 10:31:50 +0800 Subject: [PATCH] fix --- api/v1/purchase/purchase.go | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/api/v1/purchase/purchase.go b/api/v1/purchase/purchase.go index 388ddd7..0a5c918 100644 --- a/api/v1/purchase/purchase.go +++ b/api/v1/purchase/purchase.go @@ -1,8 +1,8 @@ package purchase import ( + "fmt" "github.com/gin-gonic/gin" - "github.com/mitchellh/mapstructure" "go.uber.org/zap" "gorm.io/gorm" "srm/global" @@ -12,6 +12,7 @@ purchaserequest "srm/model/purchase/request" "strconv" "strings" + "time" //"srm/model/purchase" @@ -42,7 +43,7 @@ } var purchaseRecord purchase.Purchase - if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil { + if err := utils.AssignTo(params.Purchase, &purchaseRecord); err != nil { global.GVA_LOG.Error("Add Purchase failed", zap.Error(err)) response.FailWithMessage(err.Error(), c) return @@ -52,6 +53,8 @@ purchaseRecord.Status = purchase.OrderStatusConfirmed purchaseRecord.HandledBy = "admin" purchaseRecord.Creator = "admin" + purchaseRecord.Number = fmt.Sprintf("CG%v", time.Now().Unix()) + purchaseRecord.Principal = "admin" if !purchaseRecord.WholeDiscountType.IsValid(purchaseRecord.TotalPrice, purchaseRecord.WholeDiscount) { response.FailWithMessage("鏁村崟鎶樻墸鏁板�间笉姝g‘", c) @@ -71,7 +74,7 @@ return } global.GVA_LOG.Error("鍒涘缓澶辫触!", zap.Error(err)) - response.FailWithMessage("鍒涘缓澶辫触", c) + response.FailWithMessage(err.Error(), c) return } response.OkWithMessage("鍒涘缓鎴愬姛", c) @@ -119,7 +122,7 @@ } var purchaseRecord purchase.Purchase - if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil { + if err := utils.AssignTo(params.Purchase, &purchaseRecord); err != nil { response.FailWithMessage(err.Error(), c) return } @@ -163,7 +166,7 @@ return } respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) - err = mapstructure.Decode(productList, &respProductList) + err = utils.AssignTo(productList, &respProductList) if err != nil { global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) response.FailWithMessage("鑾峰彇澶辫触", c) @@ -173,7 +176,7 @@ respProductList[k].Amount = item.Amount respProductList[k].Price = item.Price respProductList[k].Total = item.Total - err = mapstructure.Decode(item.Product, &respProductList[k]) + err = utils.AssignTo(item.Product, &respProductList[k]) if err != nil { global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) response.FailWithMessage("鑾峰彇澶辫触", c) @@ -261,7 +264,7 @@ } purchaseTypeList := make([]*purchase.PurchaseType, 0, len(params)) - if err := mapstructure.Decode(params, &purchaseTypeList); err != nil { + if err := utils.AssignTo(params, &purchaseTypeList); err != nil { response.FailWithMessage(err.Error(), c) return } -- Gitblit v1.8.0