| | |
| | | product.CategoryName = category.Name |
| | | } |
| | | } |
| | | var reorderAmount request.ProductStatisticsAmount |
| | | 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"). |
| | | 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 { |
| | | 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) |
| | | |
| | | var statisticsList []*request.ProductStatistics |
| | | if err := models.NewOperationSearch().Orm. |
| | | Table("wms_operation"). |
| | | InnerJoins("INNER JOIN wms_operation_details on wms_operation_details.operation_id=wms_operation.id"). |
| | | Select("SUM(wms_operation_details.amount) as total_amount,wms_operation.base_operation_type"). |
| | | Where("wms_operation_details.product_id=? and wms_operation.`status`=? and wms_operation.base_operation_type in (?)", product.ID, constvar.OperationStatus_Finish, []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeDisuse}). |
| | | Group("wms_operation.base_operation_type"). |
| | | Find(&statisticsList).Error; err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "产品数据统计失败") |
| | | return |
| | | } |
| | | for _, v := range statisticsList { |
| | | if v.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | | product.InputAmount = v.TotalAmount |
| | | } |
| | | if v.BaseOperationType == constvar.BaseOperationTypeOutgoing { |
| | | product.OutputAmount = product.OutputAmount.Add(v.TotalAmount) |
| | | } |
| | | if v.BaseOperationType == constvar.BaseOperationTypeAdjust { |
| | | product.OutputAmount = product.OutputAmount.Add(v.TotalAmount) |
| | | } |
| | | } |
| | | } |
| | | util.ResponseFormatList(c, code.Success, products, int(total)) |
| | | } |