From d3a78e4c791821b298075b700e9fc14030d12ec2 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 29 八月 2023 15:28:43 +0800
Subject: [PATCH] 采购数量,经办人,制单人

---
 service/purchase/purchase.go |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go
index 0df0c5c..bbef0f1 100644
--- a/service/purchase/purchase.go
+++ b/service/purchase/purchase.go
@@ -2,6 +2,7 @@
 
 import (
 	"context"
+	"github.com/shopspring/decimal"
 	"github.com/spf13/cast"
 	"gorm.io/gorm"
 	"srm/global"
@@ -24,6 +25,11 @@
 
 func (slf *PurchaseService) CreatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) {
 	err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
+		var quantity decimal.Decimal
+		for _, product := range productList {
+			quantity = quantity.Add(product.Amount)
+		}
+		params.Quantity = quantity
 		err = tx.Create(&params).Error
 		if err != nil {
 			return err
@@ -60,6 +66,11 @@
 
 func (slf *PurchaseService) UpdatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) {
 	err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
+		var quantity decimal.Decimal
+		for _, product := range productList {
+			quantity = quantity.Add(product.Amount)
+		}
+		params.Quantity = quantity
 		err = tx.Where("id = ?", params.ID).Updates(params).Error
 		if err != nil {
 			return err

--
Gitblit v1.8.0