273 lines
9.1 KiB
Go
273 lines
9.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"fmt"
|
|
"fusenapi/constants"
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
"fusenapi/utils/format"
|
|
"fusenapi/utils/step_price"
|
|
"strings"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/inventory/internal/svc"
|
|
"fusenapi/server/inventory/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetCloudListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetCloudListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCloudListLogic {
|
|
return &GetCloudListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetCloudListLogic) GetCloudList(req *types.GetCloudListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
|
}
|
|
if req.Page <= 0 {
|
|
req.Page = constants.DEFAULT_PAGE
|
|
}
|
|
if req.PageSize <= 0 || req.PageSize > 200 {
|
|
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)
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user stock list")
|
|
}
|
|
if len(stockList) == 0 {
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCloudListRsp{
|
|
ListData: []types.ListDataItem{},
|
|
})
|
|
}
|
|
designIds := make([]int64, 0, len(stockList))
|
|
for _, v := range stockList {
|
|
designIds = append(designIds, *v.DesignId)
|
|
}
|
|
//获取设计数据
|
|
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")
|
|
}
|
|
//尺寸ids
|
|
sizeIds := make([]int64, 0, len(productDesignList))
|
|
//产品ids
|
|
productIds := make([]int64, 0, len(productDesignList))
|
|
//模板ids
|
|
templateIds := make([]int64, 0, len(productDesignList))
|
|
//配件ids
|
|
optionalIds := make([]int64, 0, len(productDesignList))
|
|
mapProductDesign := make(map[int64]int)
|
|
for k, 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
|
|
}
|
|
//获取尺寸信息
|
|
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIdsWithoutStatus(l.ctx, sizeIds, "")
|
|
if err != nil {
|
|
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
|
|
}
|
|
//获取产品信息
|
|
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIdsWithoutStatus(l.ctx, productIds, "")
|
|
if err != nil {
|
|
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
|
|
}
|
|
//获取模板信息
|
|
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIdsWithoutStatus(l.ctx, templateIds)
|
|
if err != nil {
|
|
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
|
|
}
|
|
//获取配件列表
|
|
productModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsWithoutStatus(l.ctx, optionalIds)
|
|
if err != nil {
|
|
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
|
|
}
|
|
//根据产品ids获取产品价格
|
|
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list")
|
|
}
|
|
for _, v := range priceList {
|
|
if *v.StepNum == "" || *v.StepPrice == "" {
|
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "price data`s step num or step price is empty")
|
|
}
|
|
stepNum, err := format.StrSlicToIntSlice(strings.Split(*v.StepNum, ","))
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse step num err")
|
|
}
|
|
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)
|
|
}
|