| | |
| | | if params.PageInfo.Check() { |
| | | search.SetPage(params.Page, params.PageSize) |
| | | } |
| | | find, total, err := search.SetKeyword(params.KeyWord).FindByPage() |
| | | //查询位置 |
| | | locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询位置失败") |
| | | return |
| | | } |
| | | ids := make([]int, 0) |
| | | for _, location := range locations { |
| | | 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() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询数量失败") |
| | | return |
| | | } |
| | | var result []response.LocationForms |
| | | for _, product := range find { |
| | | 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.Amount = product.Product.Amount |
| | | resp.Unit = product.Product.Unit |
| | | resp.Value = product.Product.Amount.Mul(product.Product.Cost) |
| | | resp.Value = resp.Amount.Mul(product.Product.Cost) |
| | | result = append(result, resp) |
| | | } |
| | | util.ResponseFormatList(c, code.Success, result, int(total)) |