From 19f41f6dbc6406a6467f5300fef6673a33610cba Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 27 Jun 2023 18:35:26 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_design_logic.go | 10 ++ .../internal/logic/getcloudlistlogic.go | 128 +++++++++++++++++- server/inventory/internal/types/types.go | 6 +- server_api/inventory.api | 6 +- utils/step_price/price.go | 17 +++ 5 files changed, 156 insertions(+), 11 deletions(-) diff --git a/model/gmodel/fs_product_design_logic.go b/model/gmodel/fs_product_design_logic.go index 0f3fd90e..afd82d0b 100755 --- a/model/gmodel/fs_product_design_logic.go +++ b/model/gmodel/fs_product_design_logic.go @@ -18,3 +18,13 @@ func (d *FsProductDesignModel) GetAllByIds(ctx context.Context, ids []int64) (re } return } +func (d *FsProductDesignModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsProductDesign, err error) { + if len(ids) == 0 { + return + } + err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`id` in (?)", ids).Find(&resp).Error + if err != nil { + return nil, err + } + return +} diff --git a/server/inventory/internal/logic/getcloudlistlogic.go b/server/inventory/internal/logic/getcloudlistlogic.go index 47be6dd1..261a481f 100644 --- a/server/inventory/internal/logic/getcloudlistlogic.go +++ b/server/inventory/internal/logic/getcloudlistlogic.go @@ -1,11 +1,13 @@ package logic import ( + "fmt" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/format" + "fusenapi/utils/step_price" "strings" "context" @@ -41,10 +43,12 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a req.Page = constants.DEFAULT_PAGE_SIZE } //获取个人云仓列表 + getStockListStatus := int64(1) stockList, total, err := l.svcCtx.AllModels.FsUserStock.GetStockList(l.ctx, gmodel.GetStockListReq{ UserId: userinfo.UserId, Page: int(req.Page), Limit: int(req.PageSize), + Status: &getStockListStatus, }) if err != nil { logx.Error(err) @@ -60,7 +64,7 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a designIds = append(designIds, *v.DesignId) } //获取设计数据 - productDesignList, err := l.svcCtx.AllModels.FsProductDesign.GetAllByIds(l.ctx, designIds) + productDesignList, err := l.svcCtx.AllModels.FsProductDesign.GetAllByIdsWithoutStatus(l.ctx, designIds) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product design list") @@ -136,19 +140,133 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse step num err") } - lenStepNum := len(stepNum) stepPrice, err := format.StrSlicToIntSlice(strings.Split(*v.StepPrice, ",")) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse step price err") } 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) + mapProductMaterialSizePrice[mapKey] = append(mapProductMaterialSizePrice[mapKey], types.PriceItem{ + Num: *v.MinBuyNum, + TotalNum: *v.MinBuyNum * (*v.EachBoxNum), + Price: step_price.GetCentStepPrice(int(*v.MinBuyNum), stepNum, stepPrice), + }) *v.MinBuyNum++ } - } + warehouseBoxes := int64(0) + transitBoxes := int64(0) + listDataRsp := make([]types.ListDataItem, 0, len(stockList)) + for _, v := range stockList { + //设计详情 + designIndex, ok := mapProductDesign[*v.DesignId] + if !ok { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, fmt.Sprintf("product design is not exists,id = %d", v.DesignId)) + } + productIndex, ok := mapProduct[*v.ProductId] + if !ok { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, fmt.Sprintf("product is not exists,id = %d", v.ProductId)) + } + cover := *productDesignList[designIndex].Cover + if req.Size > 200 { + + } + 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) } diff --git a/server/inventory/internal/types/types.go b/server/inventory/internal/types/types.go index c7fc0c67..5d7e3b54 100644 --- a/server/inventory/internal/types/types.go +++ b/server/inventory/internal/types/types.go @@ -49,9 +49,9 @@ type ListDataItem struct { } type PriceItem struct { - Num int `json:"num"` - TotalNum int `json:"total_num"` - Price int `json:"price"` + Num int64 `json:"num"` + TotalNum int64 `json:"total_num"` + Price int64 `json:"price"` } type Request struct { diff --git a/server_api/inventory.api b/server_api/inventory.api index 0e9908eb..01184769 100644 --- a/server_api/inventory.api +++ b/server_api/inventory.api @@ -58,7 +58,7 @@ type ListDataItem { PriceList []PriceItem `json:"price"` } type PriceItem { - Num int `json:"num"` - TotalNum int `json:"total_num"` - Price int `json:"price"` + Num int64 `json:"num"` + TotalNum int64 `json:"total_num"` + Price int64 `json:"price"` } \ No newline at end of file diff --git a/utils/step_price/price.go b/utils/step_price/price.go index 6c50ee6c..0cfe5d09 100644 --- a/utils/step_price/price.go +++ b/utils/step_price/price.go @@ -1,5 +1,6 @@ package step_price +// 返回美元 func GetStepPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 { if minBuyNum > stepNum[len(stepNum)-1] { return float64(stepPrice[len(stepPrice)-1]) / float64(100) @@ -14,3 +15,19 @@ func GetStepPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 { } return float64(stepPrice[len(stepPrice)-1]) / float64(100) } + +// 返回美分 +func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 { + if minBuyNum > stepNum[len(stepNum)-1] { + return int64(stepPrice[len(stepPrice)-1]) + } + for k, v := range stepNum { + if minBuyNum <= v { + if k <= (len(stepPrice) - 1) { + return int64(stepPrice[k]) + } + return int64(stepPrice[len(stepPrice)-1]) + } + } + return int64(stepPrice[len(stepPrice)-1]) +}