diff --git a/model/gmodel/fs_user_stock_logic.go b/model/gmodel/fs_user_stock_logic.go index bc122752..0814c30f 100644 --- a/model/gmodel/fs_user_stock_logic.go +++ b/model/gmodel/fs_user_stock_logic.go @@ -1,6 +1,8 @@ package gmodel -import "context" +import ( + "context" +) // TODO: 使用model的属性做你想做的 type GetStockListReq struct { @@ -12,7 +14,7 @@ type GetStockListReq struct { } func (s *FsUserStockModel) GetStockList(ctx context.Context, req GetStockListReq) (resp []FsUserStock, total int64, err error) { - db := s.db.WithContext(ctx).Model(&FsUserStock{}) + db := s.db.Debug().WithContext(ctx).Model(&FsUserStock{}) if req.UserId > 0 { db = db.Where("`user_id` = ?", req.UserId) } diff --git a/server/inventory/internal/logic/getcloudlistlogic.go b/server/inventory/internal/logic/getcloudlistlogic.go index 261a481f..e02f7315 100644 --- a/server/inventory/internal/logic/getcloudlistlogic.go +++ b/server/inventory/internal/logic/getcloudlistlogic.go @@ -7,7 +7,9 @@ import ( "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/format" + "fusenapi/utils/image" "fusenapi/utils/step_price" + "math" "strings" "context" @@ -40,7 +42,12 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a req.Page = constants.DEFAULT_PAGE } if req.PageSize <= 0 || req.PageSize > 200 { - req.Page = constants.DEFAULT_PAGE_SIZE + req.PageSize = constants.DEFAULT_PAGE_SIZE + } + sizeFlag := false + if req.Size >= 200 { + sizeFlag = true + req.Size = int64(image.GetCurrentSize(uint32(req.Size))) } //获取个人云仓列表 getStockListStatus := int64(1) @@ -77,13 +84,13 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a templateIds := make([]int64, 0, len(productDesignList)) //配件ids optionalIds := make([]int64, 0, len(productDesignList)) - mapProductDesign := make(map[int64]int) - for k, v := range productDesignList { + mapProductDesign := make(map[int64]gmodel.FsProductDesign) + for _, v := range productDesignList { sizeIds = append(sizeIds, *v.SizeId) productIds = append(productIds, *v.ProductId) templateIds = append(templateIds, *v.TemplateId) optionalIds = append(optionalIds, *v.OptionalId) - mapProductDesign[v.Id] = k + mapProductDesign[v.Id] = v } //获取尺寸信息 sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIdsWithoutStatus(l.ctx, sizeIds, "") @@ -91,9 +98,9 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list") } - mapSize := make(map[int64]int) - for k, v := range sizeList { - mapSize[v.Id] = k + mapSize := make(map[int64]gmodel.FsProductSize) + for _, v := range sizeList { + mapSize[v.Id] = v } //获取产品信息 productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIdsWithoutStatus(l.ctx, productIds, "") @@ -101,9 +108,9 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list") } - mapProduct := make(map[int64]int) - for k, v := range productList { - mapProduct[v.Id] = k + mapProduct := make(map[int64]gmodel.FsProduct) + for _, v := range productList { + mapProduct[v.Id] = v } //获取模板信息 productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIdsWithoutStatus(l.ctx, templateIds) @@ -111,9 +118,9 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list") } - mapTemplate := make(map[int64]int) - for k, v := range productTemplateList { - mapTemplate[v.Id] = k + mapTemplate := make(map[int64]gmodel.FsProductTemplateV2) + for _, v := range productTemplateList { + mapTemplate[v.Id] = v } //获取配件列表 productModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsWithoutStatus(l.ctx, optionalIds) @@ -121,9 +128,9 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list") } - mapProductModel := make(map[int64]int) - for k, v := range productModel3dList { - mapProductModel[v.Id] = k + mapProductModel := make(map[int64]gmodel.FsProductModel3d) + for _, v := range productModel3dList { + mapProductModel[v.Id] = v } //根据产品ids获取产品价格 priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds) @@ -131,6 +138,8 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list") } + //根据产品id,材质,尺寸存储价格 + mapProductMaterialSizePrice := make(map[string][]types.PriceItem) for _, v := range priceList { if *v.StepNum == "" || *v.StepPrice == "" { return resp.SetStatusWithMessage(basic.CodeServiceErr, "price data`s step num or step price is empty") @@ -147,10 +156,8 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a } lenStepPrice := len(stepPrice) //不确定长度给20 - //根据产品id,材质,尺寸存储价格 - mapProductMaterialSizePrice := make(map[string][]types.PriceItem) for *v.MinBuyNum < int64(stepPrice[lenStepPrice-1]+5) { - mapKey := fmt.Sprintf("%d-%d-%d", *v.ProductId, *v.MaterialId, *v.SizeId) + mapKey := l.getMapProductMaterialSizePriceKey(*v.ProductId, *v.MaterialId, *v.SizeId) mapProductMaterialSizePrice[mapKey] = append(mapProductMaterialSizePrice[mapKey], types.PriceItem{ Num: *v.MinBuyNum, TotalNum: *v.MinBuyNum * (*v.EachBoxNum), @@ -163,110 +170,101 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a transitBoxes := int64(0) listDataRsp := make([]types.ListDataItem, 0, len(stockList)) for _, v := range stockList { + dataItem := types.ListDataItem{ + Id: v.Id, + Production: *v.Production, + EachBoxNum: *v.EachBoxNum, + Stick: *v.Stick, + Type: 1, + TakeNum: 1, // 步数 + } //设计详情 - designIndex, ok := mapProductDesign[*v.DesignId] - if !ok { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, fmt.Sprintf("product design is not exists,id = %d", v.DesignId)) + designInfo, designOk := mapProductDesign[*v.DesignId] + sizeId := int64(0) + optionalId := int64(0) + if designOk { + mapKey := l.getMapProductMaterialSizePriceKey(*v.ProductId, *designInfo.MaterialId, *designInfo.SizeId) + dataItem.DesignSn = *designInfo.Sn + dataItem.Cover = *designInfo.Cover + sizeId = *designInfo.SizeId + optionalId = *designInfo.OptionalId + dataItem.PriceList = mapProductMaterialSizePrice[mapKey] } - productIndex, ok := mapProduct[*v.ProductId] - if !ok { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, fmt.Sprintf("product is not exists,id = %d", v.ProductId)) + //模型信息 + productModel3dInfo, model3dOk := mapProductModel[optionalId] + if model3dOk { + dataItem.Fitting = *productModel3dInfo.Title + //配件下架 + if *productModel3dInfo.Status == 0 { + dataItem.IsStop = 3 + } } - cover := *productDesignList[designIndex].Cover - if req.Size > 200 { - + //模板信息 + templateInfo, templateOk := mapTemplate[*designInfo.TemplateId] + if templateOk { + //模板下架 + if *templateInfo.IsDel == 1 || *templateInfo.Status == 0 { + dataItem.IsStop = 1 + } + } + //尺寸信息 + sizeInfo, sizeOk := mapSize[sizeId] + if sizeOk { + dataItem.Size = *sizeInfo.Capacity + //尺寸下架 + if *sizeInfo.Status == 0 { + dataItem.IsStop = 1 + } + } + //产品信息 + productInfo, productOk := mapProduct[*v.ProductId] + if productOk { + dataItem.Sn = *productInfo.Sn + dataItem.Name = *productInfo.Title + if *productInfo.IsShelf == 0 || *productInfo.IsDel == 1 { + dataItem.IsStop = 2 + } + } + if sizeFlag { + coverArr := strings.Split(*designInfo.Cover, ".") + if len(coverArr) < 2 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "cover split slice item count is less than 2") + } + dataItem.Cover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1]) + } + //生产中的箱数 + if *v.EachBoxNum > 0 { + dataItem.ProductionBox = *v.Production / *v.EachBoxNum + dataItem.StickBox = *v.Stick / *v.EachBoxNum + } + //判断提示类型1 2告急 3没有了 + if *v.Stick <= 0 && *v.Production <= 0 { + dataItem.Type = 3 + } + if (*v.Stick+*v.Production) / *v.EachBoxNum <= 3 { + dataItem.Type = 2 + } + listDataRsp = append(listDataRsp, dataItem) + //累加在库数量和运输数量 + if *v.EachBoxNum != 0 { + warehouseBoxes += *v.Stick / *v.EachBoxNum + transitBoxes += *v.TransNum / *v.EachBoxNum } - listDataRsp = append(listDataRsp, types.ListDataItem{ - Id: v.Id, - Sn: *productList[productIndex].Sn, - Cover: "", - Name: "", - DesignSn: "", - Fitting: "", - Production: 0, - ProductionBox: 0, - EachBoxNum: 0, - Stick: 0, - StickBox: 0, - Type: 0, - TakeNum: 0, - Size: "", - IsStop: 0, - PriceList: nil, - }) - //动态返回图片尺寸 } - /*//循环查询库存 - foreach ($stock as $row) { - //获取库存详情 - $detail = $desgin[$row['design_id']]; - - //动态返回图片尺寸 - if ($clientSize >= 200) { - $clientSize = ImageService::getCurrentSize($clientSize); - $coverArr = explode('.', $detail['cover']); - $cover = $coverArr[0] . '_' . $clientSize . '.' . $coverArr[1]; - } else { - $cover = $detail['cover']; - } - $is_stop = 0; - //配件下架 - if (isset($option[$detail['optional_id']]) && !$option[$detail['optional_id']]['status']) { - $is_stop = 3; - } - //模板下架 - if ($productTemplate[$detail['template_id']]['is_del'] || !$productTemplate[$detail['template_id']]['status']) { - $is_stop = 1; - } - //尺寸下架 - if (!$sizes[$detail['size_id']]['status']) { - $is_stop = 1; - } - //产品下架 - if (!$products[$detail['product_id']]['is_shelf'] || $products[$detail['product_id']]['is_del']) { - $is_stop = 2; - } - - //产品名称 - $name = $products[$detail['product_id']]['title']; - $fitting = isset($option[$detail['optional_id']]) ? $option[$detail['optional_id']]['title'] : ''; - - $production = $row['production']; - $stick = $row['stick']; - $size = $sizes[$detail['size_id']]['capacity']; - - //判断提示类型 - $type = 1; - if ($stick <= 0 && $production <= 0) { - $type = 3; - } - if (($production + $stick) / $row['each_box_num'] <= 3) { - $type = 2; - } - - - $arr[] = [ - 'id' => $row['id'], - 'sn' => $products[$detail['product_id']]['sn'], - 'cover' => $cover, - 'name' => $name, - 'design_sn' => $detail['sn'], - 'fitting' => $fitting,//optionals title - 'production' => $production,//生产中 - 'production_box' => $production / $row['each_box_num'], //生产中的箱数 - 'each_box_num' => $row['each_box_num'], - 'stick' => $stick, - 'stick_box' => $stick / $row['each_box_num'], //仓库中的箱数 - 'type' => $type, // 1 2告急 3没有了, - 'takeNum' => 1, // 步数 - 'size' => $size, - 'is_stop' => $is_stop, - 'price' => $product[$detail['product_id']]['prices'][$detail['material_id'] . '_' . $detail['size_id']]['items'] - ]; - //累加在库数量和运输数量 - $warehouse_boxes = $warehouse_boxes + $stick / $row['each_box_num']; - $transit_boxes = $transit_boxes + $row['trans_num'] / $row['each_box_num']; - } - return ['list' => $arr, 'warehouse_boxes' => $warehouse_boxes, 'transit_boxes' => $transit_boxes];*/ - return resp.SetStatus(basic.CodeOK) + return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCloudListRsp{ + WarehouseBoxes: warehouseBoxes, + TransitBoxes: transitBoxes, + MinTakeNum: 3, + ListData: listDataRsp, + Pagnation: types.Pagnation{ + TotalCount: total, + TotalPage: int64(math.Ceil(float64(total) / float64(req.PageSize))), + CurPage: req.Page, + PageSize: req.PageSize, + }, + }) +} + +func (l *GetCloudListLogic) getMapProductMaterialSizePriceKey(productId int64, materialId int64, sizeId int64) string { + return fmt.Sprintf("%d-%d-%d", productId, materialId, sizeId) } diff --git a/server/inventory/internal/types/types.go b/server/inventory/internal/types/types.go index 5d7e3b54..917428bd 100644 --- a/server/inventory/internal/types/types.go +++ b/server/inventory/internal/types/types.go @@ -16,9 +16,9 @@ type TakeForm struct { } type GetCloudListReq struct { - Page int64 `json:"page"` - PageSize int64 `json:"page_size"` - Size int64 `json:"size"` + Page int64 `form:"page"` + PageSize int64 `form:"page_size"` + Size int64 `form:"size"` } type GetCloudListRsp struct { diff --git a/server_api/inventory.api b/server_api/inventory.api index 01184769..7c185715 100644 --- a/server_api/inventory.api +++ b/server_api/inventory.api @@ -28,9 +28,9 @@ type TakeForm { } //获取云仓库存列表 type GetCloudListReq { - Page int64 `json:"page"` - PageSize int64 `json:"page_size"` - Size int64 `json:"size"` + Page int64 `form:"page"` + PageSize int64 `form:"page_size"` + Size int64 `form:"size"` } type GetCloudListRsp { WarehouseBoxes int64 `json:"warehouse_boxes"`