This commit is contained in:
laodaming 2023-06-28 12:25:40 +08:00
parent 19f41f6dbc
commit 5b9a814fbb
4 changed files with 128 additions and 128 deletions

View File

@ -1,6 +1,8 @@
package gmodel package gmodel
import "context" import (
"context"
)
// TODO: 使用model的属性做你想做的 // TODO: 使用model的属性做你想做的
type GetStockListReq struct { 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) { 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 { if req.UserId > 0 {
db = db.Where("`user_id` = ?", req.UserId) db = db.Where("`user_id` = ?", req.UserId)
} }

View File

@ -7,7 +7,9 @@ import (
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"fusenapi/utils/format" "fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/step_price" "fusenapi/utils/step_price"
"math"
"strings" "strings"
"context" "context"
@ -40,7 +42,12 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a
req.Page = constants.DEFAULT_PAGE req.Page = constants.DEFAULT_PAGE
} }
if req.PageSize <= 0 || req.PageSize > 200 { 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) getStockListStatus := int64(1)
@ -77,13 +84,13 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a
templateIds := make([]int64, 0, len(productDesignList)) templateIds := make([]int64, 0, len(productDesignList))
//配件ids //配件ids
optionalIds := make([]int64, 0, len(productDesignList)) optionalIds := make([]int64, 0, len(productDesignList))
mapProductDesign := make(map[int64]int) mapProductDesign := make(map[int64]gmodel.FsProductDesign)
for k, v := range productDesignList { for _, v := range productDesignList {
sizeIds = append(sizeIds, *v.SizeId) sizeIds = append(sizeIds, *v.SizeId)
productIds = append(productIds, *v.ProductId) productIds = append(productIds, *v.ProductId)
templateIds = append(templateIds, *v.TemplateId) templateIds = append(templateIds, *v.TemplateId)
optionalIds = append(optionalIds, *v.OptionalId) optionalIds = append(optionalIds, *v.OptionalId)
mapProductDesign[v.Id] = k mapProductDesign[v.Id] = v
} }
//获取尺寸信息 //获取尺寸信息
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIdsWithoutStatus(l.ctx, sizeIds, "") 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) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list")
} }
mapSize := make(map[int64]int) mapSize := make(map[int64]gmodel.FsProductSize)
for k, v := range sizeList { for _, v := range sizeList {
mapSize[v.Id] = k mapSize[v.Id] = v
} }
//获取产品信息 //获取产品信息
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIdsWithoutStatus(l.ctx, productIds, "") 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) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
} }
mapProduct := make(map[int64]int) mapProduct := make(map[int64]gmodel.FsProduct)
for k, v := range productList { for _, v := range productList {
mapProduct[v.Id] = k mapProduct[v.Id] = v
} }
//获取模板信息 //获取模板信息
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIdsWithoutStatus(l.ctx, templateIds) 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) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list")
} }
mapTemplate := make(map[int64]int) mapTemplate := make(map[int64]gmodel.FsProductTemplateV2)
for k, v := range productTemplateList { for _, v := range productTemplateList {
mapTemplate[v.Id] = k mapTemplate[v.Id] = v
} }
//获取配件列表 //获取配件列表
productModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsWithoutStatus(l.ctx, optionalIds) 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) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")
} }
mapProductModel := make(map[int64]int) mapProductModel := make(map[int64]gmodel.FsProductModel3d)
for k, v := range productModel3dList { for _, v := range productModel3dList {
mapProductModel[v.Id] = k mapProductModel[v.Id] = v
} }
//根据产品ids获取产品价格 //根据产品ids获取产品价格
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds) 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) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list")
} }
//根据产品id,材质,尺寸存储价格
mapProductMaterialSizePrice := make(map[string][]types.PriceItem)
for _, v := range priceList { for _, v := range priceList {
if *v.StepNum == "" || *v.StepPrice == "" { if *v.StepNum == "" || *v.StepPrice == "" {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "price data`s step num or step price is empty") 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) lenStepPrice := len(stepPrice)
//不确定长度给20 //不确定长度给20
//根据产品id,材质,尺寸存储价格
mapProductMaterialSizePrice := make(map[string][]types.PriceItem)
for *v.MinBuyNum < int64(stepPrice[lenStepPrice-1]+5) { 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{ mapProductMaterialSizePrice[mapKey] = append(mapProductMaterialSizePrice[mapKey], types.PriceItem{
Num: *v.MinBuyNum, Num: *v.MinBuyNum,
TotalNum: *v.MinBuyNum * (*v.EachBoxNum), TotalNum: *v.MinBuyNum * (*v.EachBoxNum),
@ -163,110 +170,101 @@ func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *a
transitBoxes := int64(0) transitBoxes := int64(0)
listDataRsp := make([]types.ListDataItem, 0, len(stockList)) listDataRsp := make([]types.ListDataItem, 0, len(stockList))
for _, v := range stockList { for _, v := range stockList {
//设计详情 dataItem := types.ListDataItem{
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, Id: v.Id,
Sn: *productList[productIndex].Sn, Production: *v.Production,
Cover: "", EachBoxNum: *v.EachBoxNum,
Name: "", Stick: *v.Stick,
DesignSn: "", Type: 1,
Fitting: "", TakeNum: 1, // 步数
Production: 0,
ProductionBox: 0,
EachBoxNum: 0,
Stick: 0,
StickBox: 0,
Type: 0,
TakeNum: 0,
Size: "",
IsStop: 0,
PriceList: nil,
})
//动态返回图片尺寸
} }
/*//循环查询库存 //设计详情
foreach ($stock as $row) { designInfo, designOk := mapProductDesign[*v.DesignId]
//获取库存详情 sizeId := int64(0)
$detail = $desgin[$row['design_id']]; optionalId := int64(0)
if designOk {
//动态返回图片尺寸 mapKey := l.getMapProductMaterialSizePriceKey(*v.ProductId, *designInfo.MaterialId, *designInfo.SizeId)
if ($clientSize >= 200) { dataItem.DesignSn = *designInfo.Sn
$clientSize = ImageService::getCurrentSize($clientSize); dataItem.Cover = *designInfo.Cover
$coverArr = explode('.', $detail['cover']); sizeId = *designInfo.SizeId
$cover = $coverArr[0] . '_' . $clientSize . '.' . $coverArr[1]; optionalId = *designInfo.OptionalId
} else { dataItem.PriceList = mapProductMaterialSizePrice[mapKey]
$cover = $detail['cover'];
} }
$is_stop = 0; //模型信息
productModel3dInfo, model3dOk := mapProductModel[optionalId]
if model3dOk {
dataItem.Fitting = *productModel3dInfo.Title
//配件下架 //配件下架
if (isset($option[$detail['optional_id']]) && !$option[$detail['optional_id']]['status']) { if *productModel3dInfo.Status == 0 {
$is_stop = 3; dataItem.IsStop = 3
} }
}
//模板信息
templateInfo, templateOk := mapTemplate[*designInfo.TemplateId]
if templateOk {
//模板下架 //模板下架
if ($productTemplate[$detail['template_id']]['is_del'] || !$productTemplate[$detail['template_id']]['status']) { if *templateInfo.IsDel == 1 || *templateInfo.Status == 0 {
$is_stop = 1; dataItem.IsStop = 1
} }
}
//尺寸信息
sizeInfo, sizeOk := mapSize[sizeId]
if sizeOk {
dataItem.Size = *sizeInfo.Capacity
//尺寸下架 //尺寸下架
if (!$sizes[$detail['size_id']]['status']) { if *sizeInfo.Status == 0 {
$is_stop = 1; dataItem.IsStop = 1
} }
//产品下架
if (!$products[$detail['product_id']]['is_shelf'] || $products[$detail['product_id']]['is_del']) {
$is_stop = 2;
} }
//产品信息
//产品名称 productInfo, productOk := mapProduct[*v.ProductId]
$name = $products[$detail['product_id']]['title']; if productOk {
$fitting = isset($option[$detail['optional_id']]) ? $option[$detail['optional_id']]['title'] : ''; dataItem.Sn = *productInfo.Sn
dataItem.Name = *productInfo.Title
$production = $row['production']; if *productInfo.IsShelf == 0 || *productInfo.IsDel == 1 {
$stick = $row['stick']; dataItem.IsStop = 2
$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;
} }
if sizeFlag {
coverArr := strings.Split(*designInfo.Cover, ".")
$arr[] = [ if len(coverArr) < 2 {
'id' => $row['id'], return resp.SetStatusWithMessage(basic.CodeServiceErr, "cover split slice item count is less than 2")
'sn' => $products[$detail['product_id']]['sn'], }
'cover' => $cover, dataItem.Cover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1])
'name' => $name, }
'design_sn' => $detail['sn'], //生产中的箱数
'fitting' => $fitting,//optionals title if *v.EachBoxNum > 0 {
'production' => $production,//生产中 dataItem.ProductionBox = *v.Production / *v.EachBoxNum
'production_box' => $production / $row['each_box_num'], //生产中的箱数 dataItem.StickBox = *v.Stick / *v.EachBoxNum
'each_box_num' => $row['each_box_num'], }
'stick' => $stick, //判断提示类型1 2告急 3没有了
'stick_box' => $stick / $row['each_box_num'], //仓库中的箱数 if *v.Stick <= 0 && *v.Production <= 0 {
'type' => $type, // 1 2告急 3没有了, dataItem.Type = 3
'takeNum' => 1, // 步数 }
'size' => $size, if (*v.Stick+*v.Production) / *v.EachBoxNum <= 3 {
'is_stop' => $is_stop, dataItem.Type = 2
'price' => $product[$detail['product_id']]['prices'][$detail['material_id'] . '_' . $detail['size_id']]['items'] }
]; listDataRsp = append(listDataRsp, dataItem)
//累加在库数量和运输数量 //累加在库数量和运输数量
$warehouse_boxes = $warehouse_boxes + $stick / $row['each_box_num']; if *v.EachBoxNum != 0 {
$transit_boxes = $transit_boxes + $row['trans_num'] / $row['each_box_num']; warehouseBoxes += *v.Stick / *v.EachBoxNum
transitBoxes += *v.TransNum / *v.EachBoxNum
} }
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)
} }

View File

@ -16,9 +16,9 @@ type TakeForm struct {
} }
type GetCloudListReq struct { type GetCloudListReq struct {
Page int64 `json:"page"` Page int64 `form:"page"`
PageSize int64 `json:"page_size"` PageSize int64 `form:"page_size"`
Size int64 `json:"size"` Size int64 `form:"size"`
} }
type GetCloudListRsp struct { type GetCloudListRsp struct {

View File

@ -28,9 +28,9 @@ type TakeForm {
} }
//获取云仓库存列表 //获取云仓库存列表
type GetCloudListReq { type GetCloudListReq {
Page int64 `json:"page"` Page int64 `form:"page"`
PageSize int64 `json:"page_size"` PageSize int64 `form:"page_size"`
Size int64 `json:"size"` Size int64 `form:"size"`
} }
type GetCloudListRsp { type GetCloudListRsp {
WarehouseBoxes int64 `json:"warehouse_boxes"` WarehouseBoxes int64 `json:"warehouse_boxes"`