fix
This commit is contained in:
parent
84088a7a12
commit
19f41f6dbc
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"`
|
||||
}
|
|
@ -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])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user