fix
This commit is contained in:
parent
46430a1ce6
commit
46418f2338
|
@ -6,6 +6,7 @@ import (
|
|||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/step_price"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
|
@ -52,27 +53,43 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
|||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get price list")
|
||||
}
|
||||
//处理价格信息
|
||||
mapRsp := make(map[string]interface{})
|
||||
for _, v := range priceList {
|
||||
mapKey := fmt.Sprintf("_%d", v.Id)
|
||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*v.StepNum, ","))
|
||||
mapRsp := make(map[string]*types.GetPriceByPidRsp)
|
||||
for _, price := range priceList {
|
||||
stepNumSlice, err := format.StrSlicToIntSlice(strings.Split(*price.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", v.Id))
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", price.Id))
|
||||
}
|
||||
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*price.StepPrice, ","))
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", price.Id))
|
||||
}
|
||||
lenStepNum := len(stepNumSlice)
|
||||
itemList := make([]types.PriceItem, 0, 10)
|
||||
for *price.MinBuyNum < (int64(stepNumSlice[lenStepNum-1]) + 5) {
|
||||
itemList = append(itemList, types.PriceItem{
|
||||
Num: *price.MinBuyNum,
|
||||
TotalNum: (*price.MinBuyNum) * (*price.EachBoxNum),
|
||||
Price: step_price.GetCentStepPrice(int(*price.MinBuyNum), stepNumSlice, stepPriceSlice),
|
||||
})
|
||||
*price.MinBuyNum++
|
||||
}
|
||||
minPrice := float64(stepPriceSlice[len(stepPriceSlice)-1]) / 100
|
||||
maxPrice := float64(stepPriceSlice[0]) / 100
|
||||
mapKey := l.getSizePriceMapKey(*price.SizeId)
|
||||
if _, ok := mapRsp[mapKey]; ok {
|
||||
mapRsp[mapKey].Items = append(mapRsp[mapKey].Items, itemList...)
|
||||
mapRsp[mapKey].MinPrice = minPrice
|
||||
mapRsp[mapKey].MaxPrice = maxPrice
|
||||
} else {
|
||||
mapRsp[mapKey] = &types.GetPriceByPidRsp{
|
||||
Items: itemList,
|
||||
MinPrice: minPrice,
|
||||
MaxPrice: maxPrice,
|
||||
}
|
||||
}
|
||||
/*$price['step_num'] = explode(',', $price['step_num']);
|
||||
$price['step_price'] = explode(',', $price['step_price']);
|
||||
while ($price['min_buy_num'] < end($price['step_num']) + 5) {
|
||||
$outData["{$price['size_id']}"]['items'][] = [
|
||||
'num' => intval($price['min_buy_num']),
|
||||
'total_num' => $price['min_buy_num'] * $price['each_box_num'],
|
||||
'price' => ProductPriceService::getPrice($price['min_buy_num'], $price['step_num'], $price['step_price'])
|
||||
];
|
||||
$price['min_buy_num'] += 1;
|
||||
}
|
||||
|
||||
$outData["{$price['size_id']}"]['min_price'] = floatval(end($price['step_price']) / 100);
|
||||
$outData["{$price['size_id']}"]['max_price'] = floatval(reset($price['step_price']) / 100);*/
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
||||
}
|
||||
func (l *GetPriceByPidLogic) getSizePriceMapKey(sizeId int64) string {
|
||||
return fmt.Sprintf("_%d", sizeId)
|
||||
}
|
||||
|
|
|
@ -301,6 +301,18 @@ type GetPriceByPidReq struct {
|
|||
Pid string `form:"pid"`
|
||||
}
|
||||
|
||||
type GetPriceByPidRsp struct {
|
||||
Items []PriceItem `json:"items"`
|
||||
MinPrice float64 `json:"min_price"`
|
||||
MaxPrice float64 `json:"max_price"`
|
||||
}
|
||||
|
||||
type PriceItem struct {
|
||||
Num int64 `json:"num"`
|
||||
TotalNum int64 `json:"total_num"`
|
||||
Price int64 `json:"price"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -324,4 +324,14 @@ type GetModelByPidReq {
|
|||
//获取产品阶梯价格
|
||||
type GetPriceByPidReq {
|
||||
Pid string `form:"pid"`
|
||||
}
|
||||
type GetPriceByPidRsp {
|
||||
Items []PriceItem `json:"items"`
|
||||
MinPrice float64 `json:"min_price"`
|
||||
MaxPrice float64 `json:"max_price"`
|
||||
}
|
||||
type PriceItem {
|
||||
Num int64 `json:"num"`
|
||||
TotalNum int64 `json:"total_num"`
|
||||
Price int64 `json:"price"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user