zhangqian
2024-07-29 985e3b7a74962d1aae5cba3451f3bff35daf5794
controllers/product_controller.go
@@ -142,23 +142,19 @@
            product.CategoryName = category.Name
         }
      }
      var reorderAmount request.ProductStatisticsAmount
      var totalAmount decimal.Decimal
      if err := models.NewOperationSearch().Orm.
         Table("wms_operation_details").
         InnerJoins("INNER JOIN wms_operation on wms_operation_details.operation_id=wms_operation.id").
         Select("wms_operation_details.product_id,SUM(wms_operation_details.amount) as total_count").
         Select("IFNULL(SUM(wms_operation_details.amount), 0) as total_count").
         Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Ready, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}).
         Group("wms_operation_details.product_id").
         //Order("wms_operation_details.product_id").
         First(&reorderAmount).Error; err != nil {
         Scan(&totalAmount).Error; err != nil {
         if !errors.Is(err, gorm.ErrRecordNotFound) {
            util.ResponseFormat(c, code.RequestParamError, "产品数据统计失败")
            return
         } else {
            reorderAmount.TotalAmount = decimal.NewFromInt(0)
         }
      }
      product.PredictionAmount = product.Amount.Add(reorderAmount.TotalAmount)
      product.PredictionAmount = product.Amount.Add(totalAmount)
      var statisticsList []*request.ProductStatistics
      if err := models.NewOperationSearch().Orm.Table("wms_operation").