jiangshuai
2023-10-26 be19d957b591ad27a47057929c4a8694f0776a1a
controllers/report_forms_controller.go
@@ -183,10 +183,7 @@
      util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
      return
   }
   search := models.NewLocationProductSearch()
   if params.PageInfo.Check() {
      search.SetPage(params.Page, params.PageSize)
   }
   //查询位置
   locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll()
   if err != nil {
@@ -198,36 +195,24 @@
      ids = append(ids, location.Id)
   }
   find, total, err := search.SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查询上架规则失败")
      return
   }
   ruleIds := make([]int, 0)
   for _, product := range find {
      ruleIds = append(ruleIds, product.Id)
   }
   amounts, err := models.NewLocationProductAmountSearch().SetLocationProductIds(ruleIds).Find()
   amounts, total, err := models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage()
   if err != nil {
      util.ResponseFormat(c, code.RequestParamError, "查询数量失败")
      return
   }
   var result []response.LocationForms
   for _, product := range find {
   for _, amount := range amounts {
      var resp response.LocationForms
      for _, amount := range amounts {
         if product.Id == amount.LocationProductId {
            resp.Amount = amount.Amount
            break
         }
      }
      resp.LocationName = product.Location.Name
      resp.ProduceId = product.Product.ID
      resp.ProductName = product.Product.Name
      resp.ProductTypeName = product.ProductCategory.Name
      resp.Unit = product.Product.Unit
      resp.Value = resp.Amount.Mul(product.Product.Cost)
      resp.Amount = amount.Amount
      resp.LocationName = amount.Location.Name
      resp.ProduceId = amount.Product.ID
      resp.ProductName = amount.Product.Name
      resp.ProductTypeName = amount.ProductCategory.Name
      resp.Unit = amount.Product.Unit
      resp.Value = resp.Amount.Mul(amount.Product.Cost)
      result = append(result, resp)
   }
   util.ResponseFormatList(c, code.Success, result, int(total))
}