添加快递公司

This commit is contained in:
邹宗楠
2022-07-01 17:02:10 +08:00
parent 1ad9113e11
commit 2886cac6bc
2 changed files with 63 additions and 19 deletions

View File

@@ -15,49 +15,92 @@ import (
"time"
)
var ExpressCompany = []int{1, 2, 5, 6, 7, 8, 9, 10, 12, 13, 14} // 快递公司
var LogisticsCompany = []int{3, 4, 11, 15, 16, 17}
// 快递默认值
func checkExpressDefault(param *bida.GetExpressPriceReq) {
if param.ChannelType == 1 { // 快递
switch param.Type {
case bida.JDExpressInt:
param.PromiseTimeType = bida.JDPromiseTimeTypeDefault // 特惠送(默认值)
case bida.DBExpressInt:
param.PromiseTimeType = bida.DBPromiseTimeTypeDefault // 特惠送(默认值)
case bida.JDLogisticsExpressInt:
param.PromiseTimeType = bida.JDPromiseTimeTypeWeight // 特惠送(默认值)
case bida.SFExpressInt:
param.PromiseTimeType = bida.SFPromiseTimeTypePublic // 特惠送(默认值)
case bida.JDStoreExpressInt:
param.PromiseTimeType = bida.JDPromiseTimeTypStoreDefault // 特惠送(默认值)
}
}
if param.ChannelType == 2 { // 物流
}
}
// QueryExpressPrice 查询配送价格,获取所有快递价格
func QueryExpressPrice(param *bida.GetExpressPriceReq) (map[string]*bida.GetExpressPriceRes, error) {
if param.Weight <= 0 {
return nil, errors.New("物品重量必须大于0")
}
// 给快递默认值
result := make(map[string]*bida.GetExpressPriceRes, 0)
if param.Type == 0 {
// 渠道费每公斤加价两毛
for i := 1; i <= 14; i++ {
param.Type = i
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
continue
switch param.ChannelType {
case 1: // 快递
for i := 0; i < len(ExpressCompany); i++ {
param.Type = ExpressCompany[i]
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
continue
}
if fee.Code != 0 {
result[fmt.Sprintf("%d", ExpressCompany[i])] = fee
continue
}
if fee.Data.ChannelFee != 0 {
addFee := int(fee.Data.ChannelFee*100) + param.Weight*20
fee.Data.ChannelFee = utils.Int2Float64(addFee) / float64(100)
result[fmt.Sprintf("%d", ExpressCompany[i])] = fee
}
}
fmt.Println("原价:", fee.Data.TypeName, fee.Data.Type, fee.Data.ChannelFee)
if fee.Code != 0 {
result[fmt.Sprintf("%d", i)] = fee
continue
}
if fee.Data.ChannelFee != 0 {
addFee := int(fee.Data.ChannelFee*100) + param.Weight*20
fee.Data.ChannelFee = utils.Int2Float64(addFee) / float64(100)
result[fmt.Sprintf("%d", i)] = fee
fmt.Println("加价:", fee.Data.TypeName, fee.Data.Type, fee.Data.ChannelFee)
case 2: // 物流
for i := 0; i < len(LogisticsCompany); i++ {
param.Type = LogisticsCompany[i]
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
continue
}
if fee.Code != 0 {
result[fmt.Sprintf("%d", LogisticsCompany[i])] = fee
continue
}
if fee.Data.ChannelFee != 0 {
addFee := int(fee.Data.ChannelFee*100) + param.Weight*20
fee.Data.ChannelFee = utils.Int2Float64(addFee) / float64(100)
result[fmt.Sprintf("%d", LogisticsCompany[i])] = fee
}
}
}
} else {
fee, err := api.QBiDaAPI.GetExpressPrice(param)
if err != nil {
return nil, err
}
if fee.Code != 0 {
// result[fmt.Sprintf("%d", param.Type)] = fee
return nil, errors.New(fee.Msg)
}
fmt.Println("原价:", fee.Data.TypeName, fee.Data.Type, fee.Data.ChannelFee)
if fee.Data.ChannelFee != 0 {
addFee := int(fee.Data.ChannelFee*100) + param.Weight*20
fee.Data.ChannelFee = utils.Int2Float64(addFee) / float64(100)
result[fmt.Sprintf("%d", param.Type)] = fee
fmt.Println("加价:", fee.Data.TypeName, fee.Data.Type, fee.Data.ChannelFee)
}
}