fix
This commit is contained in:
parent
46430a1ce6
commit
46418f2338
@ -6,6 +6,7 @@ import (
|
|||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
|
"fusenapi/utils/step_price"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -52,27 +53,43 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo
|
|||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get price list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get price list")
|
||||||
}
|
}
|
||||||
//处理价格信息
|
//处理价格信息
|
||||||
mapRsp := make(map[string]interface{})
|
mapRsp := make(map[string]*types.GetPriceByPidRsp)
|
||||||
for _, v := range priceList {
|
for _, price := range priceList {
|
||||||
mapKey := fmt.Sprintf("_%d", v.Id)
|
stepNumSlice, err := format.StrSlicToIntSlice(strings.Split(*price.StepNum, ","))
|
||||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*v.StepNum, ","))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", price.Id))
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", v.Id))
|
|
||||||
}
|
}
|
||||||
/*$price['step_num'] = explode(',', $price['step_num']);
|
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*price.StepPrice, ","))
|
||||||
$price['step_price'] = explode(',', $price['step_price']);
|
if err != nil {
|
||||||
while ($price['min_buy_num'] < end($price['step_num']) + 5) {
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step price,id = %d", price.Id))
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
|
lenStepNum := len(stepNumSlice)
|
||||||
$outData["{$price['size_id']}"]['min_price'] = floatval(end($price['step_price']) / 100);
|
itemList := make([]types.PriceItem, 0, 10)
|
||||||
$outData["{$price['size_id']}"]['max_price'] = floatval(reset($price['step_price']) / 100);*/
|
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++
|
||||||
}
|
}
|
||||||
return resp.SetStatus(basic.CodeOK)
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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"`
|
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 {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,3 +325,13 @@ type GetModelByPidReq {
|
|||||||
type GetPriceByPidReq {
|
type GetPriceByPidReq {
|
||||||
Pid string `form:"pid"`
|
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…
x
Reference in New Issue
Block a user