fix
This commit is contained in:
parent
19f41f6dbc
commit
5b9a814fbb
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
||||||
|
Id: v.Id,
|
||||||
|
Production: *v.Production,
|
||||||
|
EachBoxNum: *v.EachBoxNum,
|
||||||
|
Stick: *v.Stick,
|
||||||
|
Type: 1,
|
||||||
|
TakeNum: 1, // 步数
|
||||||
|
}
|
||||||
//设计详情
|
//设计详情
|
||||||
designIndex, ok := mapProductDesign[*v.DesignId]
|
designInfo, designOk := mapProductDesign[*v.DesignId]
|
||||||
if !ok {
|
sizeId := int64(0)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, fmt.Sprintf("product design is not exists,id = %d", v.DesignId))
|
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 {
|
productModel3dInfo, model3dOk := mapProductModel[optionalId]
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, fmt.Sprintf("product is not exists,id = %d", v.ProductId))
|
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,
|
|
||||||
})
|
|
||||||
//动态返回图片尺寸
|
|
||||||
}
|
}
|
||||||
/*//循环查询库存
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCloudListRsp{
|
||||||
foreach ($stock as $row) {
|
WarehouseBoxes: warehouseBoxes,
|
||||||
//获取库存详情
|
TransitBoxes: transitBoxes,
|
||||||
$detail = $desgin[$row['design_id']];
|
MinTakeNum: 3,
|
||||||
|
ListData: listDataRsp,
|
||||||
//动态返回图片尺寸
|
Pagnation: types.Pagnation{
|
||||||
if ($clientSize >= 200) {
|
TotalCount: total,
|
||||||
$clientSize = ImageService::getCurrentSize($clientSize);
|
TotalPage: int64(math.Ceil(float64(total) / float64(req.PageSize))),
|
||||||
$coverArr = explode('.', $detail['cover']);
|
CurPage: req.Page,
|
||||||
$cover = $coverArr[0] . '_' . $clientSize . '.' . $coverArr[1];
|
PageSize: req.PageSize,
|
||||||
} else {
|
},
|
||||||
$cover = $detail['cover'];
|
})
|
||||||
}
|
}
|
||||||
$is_stop = 0;
|
|
||||||
//配件下架
|
func (l *GetCloudListLogic) getMapProductMaterialSizePriceKey(productId int64, materialId int64, sizeId int64) string {
|
||||||
if (isset($option[$detail['optional_id']]) && !$option[$detail['optional_id']]['status']) {
|
return fmt.Sprintf("%d-%d-%d", productId, materialId, sizeId)
|
||||||
$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)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user