| | |
| | | // @Summary 获取产品列表 |
| | | // @Produce application/json |
| | | // @Param object body request.GetProductList true "查询参数" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.Material} "成功" |
| | | // @Router /api-wms/v1/product/getProductList [post] |
| | | func (slf ProductController) GetProductList(c *gin.Context) { |
| | |
| | | if params.PageInfo.Check() { |
| | | search.SetPage(params.Page, params.PageSize) |
| | | } |
| | | products, total, err := search.SetPreload(true).SetKeyword(params.KeyWord).SetCategoryId(params.CategoryId).SetOrder("created_at desc").Find() |
| | | products, total, err := search.SetPreload(true). |
| | | SetKeyword(params.KeyWord). |
| | | SetCategoryId(params.CategoryId). |
| | | SetCategoryIds(params.CategoryIds). |
| | | SetOrder("created_at desc"). |
| | | Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查找失败") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "产品类型查找失败") |
| | | return |
| | | } |
| | | categoryMap := models.CategoryMap(categories) |
| | | for _, product := range products { |
| | | for _, category := range categories { |
| | | if product.CategoryId == int(category.ID) { |
| | | product.CategoryName = category.Name |
| | | } |
| | | if product.CategoryId != 0 && categoryMap[product.CategoryId] != nil { |
| | | product.CategoryName = categoryMap[product.CategoryId].Name |
| | | } |
| | | var totalAmount decimal.Decimal |
| | | if err := models.NewOperationSearch().Orm. |
| | | Table("wms_operation_details"). |
| | | db := models.NewOperationSearch().Orm |
| | | if err := db.Table("wms_operation_details"). |
| | | InnerJoins("INNER JOIN wms_operation on wms_operation_details.operation_id=wms_operation.id"). |
| | | 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}). |
| | |
| | | product.PredictionAmount = product.Amount.Add(totalAmount) |
| | | |
| | | var statisticsList []*request.ProductStatistics |
| | | if err := models.NewOperationSearch().Orm.Table("wms_operation"). |
| | | db2 := models.NewOperationSearch().Orm |
| | | if err := db2.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}). |