三方运单计价各管各,不在以美团为基准,创建运单只有一个限制条件,最高运费:maxDeliveryFee

优化美团运费计算,两点距离用高德API实际计算行走距离
This commit is contained in:
gazebo
2019-09-26 15:47:18 +08:00
parent 860040e6f1
commit 78930d9c1a
12 changed files with 168 additions and 125 deletions

View File

@@ -208,6 +208,16 @@ func EarthDistance(lng1, lat1, lng2, lat2 float64) float64 {
return dist * radius
}
// 返回结果单元为公里
func WalkingDistance(lng1, lat1, lng2, lat2 float64) (distance float64) {
if distance = api.AutonaviAPI.WalkingDistance(lng1, lat1, lng2, lat2); distance == 0 {
distance = EarthDistance(lng1, lat1, lng2, lat2) * 1.4
} else {
distance /= 1000
}
return distance
}
func StandardCoordinate2Int(value float64) int {
return int(math.Round(value * 1000000))
}
@@ -743,3 +753,16 @@ func GetShortNameFromURL(strURL string) (shortName string) {
}
return shortName
}
// 阶梯计算总量
// stageList是一个二维数组第一维要求是从大到小排序的第二维是级别及单位代价
func CalcStageValue(stageList [][]float64, totalVolume float64) (value float64) {
for _, v := range stageList {
if totalVolume > v[0] {
used := math.Ceil(totalVolume - v[0])
value += v[1] * used
totalVolume -= used
}
}
return value
}

View File

@@ -205,3 +205,57 @@ func TestGetShortNameFromURL(t *testing.T) {
}
}
}
func TestCalcStageValue(t *testing.T) {
type tTestType struct {
DesiredValue float64
Params1 [][]float64
Params2 float64
}
priceStage := [][]float64{
[]float64{
7,
300,
},
[]float64{
5,
200,
},
[]float64{
3,
100,
},
}
for _, v := range []*tTestType{
&tTestType{
DesiredValue: 0,
Params1: priceStage,
Params2: 3,
},
&tTestType{
DesiredValue: 0,
Params1: priceStage,
Params2: 0,
},
&tTestType{
DesiredValue: 200,
Params1: priceStage,
Params2: 5,
},
&tTestType{
DesiredValue: 400,
Params1: priceStage,
Params2: 5.01,
},
&tTestType{
DesiredValue: 600,
Params1: priceStage,
Params2: 7,
},
} {
value := CalcStageValue(v.Params1, v.Params2)
if value != v.DesiredValue {
t.Errorf("DesiredValue:%f, value:%f", v.DesiredValue, value)
}
}
}