lishihai
2024-07-03 91d7ca06128f996844aa7d2d691d083c944bdf1d
service/operation.go
@@ -4,6 +4,7 @@
   "errors"
   "fmt"
   "github.com/gin-gonic/gin"
   "github.com/mitchellh/mapstructure"
   "github.com/shopspring/decimal"
   "gorm.io/gorm"
   "strconv"
@@ -138,11 +139,11 @@
         if locAmount, aok := mapLocAmount[strconv.Itoa(roleProduct.LocationId)+v.ProductId]; aok {
            locAmount.Amount = locAmount.Amount.Add(v.Amount)
            if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
               return res.Error
            if err := models.NewLocationProductAmountSearch().SetOrm(tx).SetID(int(locAmount.ID)).Save(locAmount); err != nil {
               return err
            }
         } else {
            if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{
            if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&models.LocationProductAmount{
               LocationId:        roleProduct.LocationId,
               ProductCategoryID: v.Product.CategoryId,
               ProductId:         v.ProductId,
@@ -164,11 +165,11 @@
            if locAmount, aok := mapLocAmount[strconv.Itoa(roleCategory.LocationId)+v.ProductId]; aok {
               locAmount.Amount = locAmount.Amount.Add(v.Amount)
               if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                  return res.Error
               if err := models.NewLocationProductAmountSearch().SetOrm(tx).SetID(int(locAmount.ID)).Save(locAmount); err != nil {
                  return err
               }
            } else {
               if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{
               if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&models.LocationProductAmount{
                  LocationId:        roleCategory.LocationId,
                  ProductCategoryID: v.Product.CategoryId,
                  ProductId:         v.ProductId,
@@ -181,11 +182,11 @@
         } else {
            if locAmount, aok := mapLocAmount[strconv.Itoa(operation.LocationID)+v.ProductId]; aok {
               locAmount.Amount = locAmount.Amount.Add(v.Amount)
               if res := models.NewLocationProductAmountSearch().Orm.Where("id=?", locAmount.ID).Save(locAmount); res.Error != nil {
                  return res.Error
               if err := models.NewLocationProductAmountSearch().SetOrm(tx).SetID(int(locAmount.ID)).Save(locAmount); err != nil {
                  return err
               }
            } else {
               if err := models.NewLocationProductAmountSearch().Create(&models.LocationProductAmount{
               if err := models.NewLocationProductAmountSearch().SetOrm(tx).Create(&models.LocationProductAmount{
                  LocationId:        operation.LocationID,
                  ProductCategoryID: v.Product.CategoryId,
                  ProductId:         v.ProductId,
@@ -239,14 +240,18 @@
            return errors.New(fmt.Sprintf("产品:%v,库存:%v,出库:%v,数量不够,无法完成出库操作", v.Product.Name, locAmount.Amount.String(), v.Amount.String()))
         }
         locAmount.Amount = locAmount.Amount.Sub(v.Amount)
         if err := models.NewLocationProductAmountSearch().SetID(locAmount.Id).Update(locAmount); err != nil {
         if err := models.NewLocationProductAmountSearch().SetOrm(tx).SetID(locAmount.Id).Save(locAmount); err != nil {
            return err
         }
      } else {
         return errors.New("当前仓库没有该产品,请先入库")
      }
      if v.IsInternalOutput {
         internalInputDetails = append(internalInputDetails, v)
         var inputDetail models.OperationDetails
         mapstructure.Decode(v, &inputDetail)
         inputDetail.Id = 0
         inputDetail.OperationID = 0
         internalInputDetails = append(internalInputDetails, &inputDetail)
      }
   }
   if len(internalInputDetails) > 0 {