This commit is contained in:
邹宗楠
2024-07-29 08:50:21 +08:00
parent 2dbdace45c
commit 5edbd4dd49
3 changed files with 102 additions and 143 deletions

View File

@@ -2,7 +2,6 @@ package cms
import ( import (
"fmt" "fmt"
"git.rosy.net.cn/jx-callback/globals"
"math" "math"
"reflect" "reflect"
"regexp" "regexp"
@@ -759,41 +758,10 @@ func GetCyclingLine(sLng, sLat, uLng, uLat float64) (polyLineList []string, dist
} }
} }
polyLineList = utils.BaiDuCoord2Gaode2(polyLine) // 百度坐标转高德坐标
polyLineList = jxutils.BaiDuCoord2Gaode2(polyLine)
if len(polyLineList) == 0 || polyLineList == nil { if len(polyLineList) == 0 || polyLineList == nil {
polyLineList = polyLine polyLineList = polyLine
} }
return return
} }
// 美团只认识高德地图坐标点,的转一下
func baiDuCoord2Gaode(baiduCoordinat []string) ([]string, error) {
count := len(baiduCoordinat) / 100
if i := len(baiduCoordinat) % 100; i != 0 {
count += 1
}
gaoCoordinat := make([]string, 0, 0)
for i := 1; i <= count; i++ {
var discordant = make([]string, 0, 0)
if i == count {
discordant = append(discordant, baiduCoordinat[(i-1)*100:]...)
} else {
discordant = append(discordant, baiduCoordinat[(i-1)*100:i*100]...)
}
coords, err := api.BaiDuNaviAPI.BatchCoordinateConvertBai2Gao(discordant, baidunavi.CoordSysBaidu2Gaode)
if err != nil {
globals.SugarLogger.Debugf("百度坐标转换异常:%v", err)
break
}
for _, v := range coords {
gaoCoordinat = append(gaoCoordinat, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat))
}
}
if len(gaoCoordinat) == 0 || len(gaoCoordinat) != len(baiduCoordinat) {
}
return gaoCoordinat, nil
}

View File

@@ -7,6 +7,7 @@ import (
"crypto/md5" "crypto/md5"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"git.rosy.net.cn/baseapi/platformapi/autonavi"
"io/ioutil" "io/ioutil"
"math" "math"
"math/rand" "math/rand"
@@ -16,7 +17,6 @@ import (
"time" "time"
"git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi/autonavi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/routinepool" "git.rosy.net.cn/baseapi/utils/routinepool"
"git.rosy.net.cn/jx-callback/business/jxutils/excel" "git.rosy.net.cn/jx-callback/business/jxutils/excel"
@@ -230,6 +230,23 @@ func GetUniversalOrderIDFromOrderStatus(status *model.OrderStatus) string {
return ComposeUniversalOrderID(status.VendorOrderID, status.VendorID) return ComposeUniversalOrderID(status.VendorOrderID, status.VendorID)
} }
// BaiDuCoord2Gaode2 将百度坐标转换为高德坐标
func BaiDuCoord2Gaode2(baiduCoordinat []string) []string {
gaoCoordinat := make([]string, 0, 0)
for _, v := range baiduCoordinat {
var XPI = math.Pi * 3000.0 / 180.0
coords := strings.Split(v, ",")
var x = utils.Str2Float64(coords[0]) - 0.0065
var y = utils.Str2Float64(coords[1]) - 0.006
var z = math.Sqrt(x*x+y*y) - 0.00002*math.Sin(y*XPI)
var theta = math.Atan2(y, x) - 0.000003*math.Cos(x*XPI)
var gg_lng = z * math.Cos(theta)
var gg_lat = z * math.Sin(theta)
gaoCoordinat = append(gaoCoordinat, fmt.Sprintf("%.6f,%.6f", gg_lng, gg_lat))
}
return gaoCoordinat
}
// distance单位为米 // distance单位为米
func ConvertDistanceToLogLat(lng, lat, distance, angle float64) (newLng, newLat float64) { func ConvertDistanceToLogLat(lng, lat, distance, angle float64) (newLng, newLat float64) {
oneDu := 111319.55 // 单位为米 oneDu := 111319.55 // 单位为米
@@ -364,18 +381,6 @@ func MapValue2Scope(value, fromMin, fromMax, toMin, toMax int64) int64 {
return int64(math.Round(float64(value-fromMin)/float64(fromMax-fromMin)*float64(toMax-toMin) + float64(toMin))) return int64(math.Round(float64(value-fromMin)/float64(fromMax-fromMin)*float64(toMax-toMin) + float64(toMin)))
} }
func Errs2Str(sep string, errs ...error) (retVal string) {
if sep == "" {
sep = "\n"
}
for _, err := range errs {
if err != nil {
retVal += err.Error() + sep
}
}
return retVal
}
func IntWeight2Float(weight int) float32 { func IntWeight2Float(weight int) float32 {
return float32(weight) / 1000.0 return float32(weight) / 1000.0
} }

View File

@@ -5,23 +5,19 @@ import (
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math" "math"
"strings" "strings"
"time" "time"
"git.rosy.net.cn/jx-callback/business/authz/autils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
beego "github.com/astaxie/beego/server/web"
"git.rosy.net.cn/baseapi/platformapi/dadaapi"
"git.rosy.net.cn/baseapi/platformapi/dingdingapi" "git.rosy.net.cn/baseapi/platformapi/dingdingapi"
"git.rosy.net.cn/baseapi/platformapi/jcqapi" "git.rosy.net.cn/baseapi/platformapi/jcqapi"
"git.rosy.net.cn/baseapi/platformapi/jdshopapi" "git.rosy.net.cn/baseapi/platformapi/jdshopapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/authz/autils"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner" "git.rosy.net.cn/jx-callback/business/partner"
@@ -308,12 +304,7 @@ func result2Orders(msg *jdshopapi.CallBackResult) (order *model.GoodsOrder, err
if order.OrderType == model.OrderTypeAddressErr { if order.OrderType == model.OrderTypeAddressErr {
buildOrderTo102919(order) buildOrderTo102919(order)
} }
// billParams, _ := GetDaDaBillParams(db, order)
// if result, err := api.DadaAPI.QueryDeliverFee(billParams); err == nil {
// if result.Fee > 10 {
// buildOrderTo102919(order)
// }
// }
if store != nil { if store != nil {
distance := jxutils.EarthDistance(jxutils.IntCoordinate2Standard(order.ConsigneeLng), jxutils.IntCoordinate2Standard(order.ConsigneeLat), jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat)) distance := jxutils.EarthDistance(jxutils.IntCoordinate2Standard(order.ConsigneeLng), jxutils.IntCoordinate2Standard(order.ConsigneeLat), jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat))
if distance > 4 { if distance > 4 {
@@ -328,12 +319,6 @@ func result2Orders(msg *jdshopapi.CallBackResult) (order *model.GoodsOrder, err
} }
func buildOrderTo102919(order *model.GoodsOrder) { func buildOrderTo102919(order *model.GoodsOrder) {
// if order.VendorOrgCode == "1" {
// order.StoreID = 102919
// order.JxStoreID = 102919
// order.StoreName = "商城模板(成都发货)"
// order.VendorStoreID = model.JdShopMainVendorStoreID
// } else {
order.StoreID = model.JdShopMainStoreID order.StoreID = model.JdShopMainStoreID
order.JxStoreID = model.JdShopMainStoreID order.JxStoreID = model.JdShopMainStoreID
order.StoreName = "商城模板店2" order.StoreName = "商城模板店2"
@@ -403,81 +388,82 @@ func getAllRealOrderID(orderID string) (orders []*model.GoodsOrder) {
return orders return orders
} }
func GetDaDaBillParams(db *dao.DaoDB, order *model.GoodsOrder) (billParams *dadaapi.OperateOrderParams, err error) { //
billParams = &dadaapi.OperateOrderParams{ //func GetDaDaBillParams(db *dao.DaoDB, order *model.GoodsOrder) (billParams *dadaapi.OperateOrderParams, err error) {
OriginID: jxutils.ComposeUniversalOrderID(order.VendorOrderID, order.VendorID), // billParams = &dadaapi.OperateOrderParams{
CargoPrice: jxutils.IntPrice2Standard(limitOrderPrice(order.ActualPayPrice)), // OriginID: jxutils.ComposeUniversalOrderID(order.VendorOrderID, order.VendorID),
IsPrepay: 0, // CargoPrice: jxutils.IntPrice2Standard(limitOrderPrice(order.ActualPayPrice)),
ReceiverName: utils.FilterMb4(order.ConsigneeName), // IsPrepay: 0,
ReceiverAddress: utils.FilterMb4(order.ConsigneeAddress), // ReceiverName: utils.FilterMb4(order.ConsigneeName),
ReceiverPhone: order.ConsigneeMobile, // ReceiverAddress: utils.FilterMb4(order.ConsigneeAddress),
} // ReceiverPhone: order.ConsigneeMobile,
if billParams.ShopNo, err = getDadaShopID(order, db); err == nil { // }
if billParams.CityCode, err = getDataCityCodeFromOrder(order, db); err == nil { // if billParams.ShopNo, err = getDadaShopID(order, db); err == nil {
// storeTel := "" // if billParams.CityCode, err = getDataCityCodeFromOrder(order, db); err == nil {
// storeID := jxutils.GetSaleStoreIDFromOrder(order) // // storeTel := ""
// storeDeatail, _ := dao.GetStoreDetail(db, storeID, order.VendorID) // // storeID := jxutils.GetSaleStoreIDFromOrder(order)
// if storeDeatail.Tel2 != "" { // // storeDeatail, _ := dao.GetStoreDetail(db, storeID, order.VendorID)
// storeTel = ",门店电话:" + storeDeatail.Tel2 // // if storeDeatail.Tel2 != "" {
// } // // storeTel = ",门店电话:" + storeDeatail.Tel2
billParams.ReceiverLng, billParams.ReceiverLat, _ = jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType) // // }
billParams.Info = fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, utils.FilterMb4("客户电话:"+order.ConsigneeMobile+","+order.BuyerComment+"配送遇到问题可联系18048531223取消配送单禁止未配送直接完成定单")) // billParams.ReceiverLng, billParams.ReceiverLat, _ = jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
billParams.CargoType = dadaapi.CargoTypeFresh // billParams.Info = fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, utils.FilterMb4("客户电话:"+order.ConsigneeMobile+","+order.BuyerComment+"配送遇到问题可联系18048531223取消配送单禁止未配送直接完成定单"))
billParams.CargoWeight = float64(jxutils.IntWeight2Float(limitOrderWeight(order.Weight))) // billParams.CargoType = dadaapi.CargoTypeFresh
billParams.CargoNum = order.GoodsCount // billParams.CargoWeight = float64(jxutils.IntWeight2Float(limitOrderWeight(order.Weight)))
} // billParams.CargoNum = order.GoodsCount
} // }
return billParams, err // }
} // return billParams, err
//}
func limitOrderPrice(price int64) int64 { //
var maxOrderPrice int64 = 6399 //func limitOrderPrice(price int64) int64 {
if price > maxOrderPrice { // var maxOrderPrice int64 = 6399
return maxOrderPrice // if price > maxOrderPrice {
} // return maxOrderPrice
return price // }
} // return price
//}
func limitOrderWeight(weight int) int { //
maxOrderWeight := 5000 // 5公斤 //func limitOrderWeight(weight int) int {
if weight > maxOrderWeight { // maxOrderWeight := 5000 // 5公斤
return maxOrderWeight // if weight > maxOrderWeight {
} // return maxOrderWeight
return weight // }
} // return weight
//}
func getDadaShopID(order *model.GoodsOrder, db *dao.DaoDB) (retVal string, err error) { //
saleStoreID := jxutils.GetSaleStoreIDFromOrder(order) //func getDadaShopID(order *model.GoodsOrder, db *dao.DaoDB) (retVal string, err error) {
storeCourierList, err2 := dao.GetOpenedStoreCouriersByStoreID(db, saleStoreID, model.VendorIDDada) // saleStoreID := jxutils.GetSaleStoreIDFromOrder(order)
if err = err2; err != nil && !dao.IsNoRowsError(err) { // storeCourierList, err2 := dao.GetOpenedStoreCouriersByStoreID(db, saleStoreID, model.VendorIDDada)
return "", err // if err = err2; err != nil && !dao.IsNoRowsError(err) {
} // return "", err
if len(storeCourierList) == 0 { // }
return "", partner.ErrStoreHaveNoCourier // if len(storeCourierList) == 0 {
} // return "", partner.ErrStoreHaveNoCourier
retVal = storeCourierList[0].VendorStoreID // }
if beego.BConfig.RunMode == "dev" { // retVal = storeCourierList[0].VendorStoreID
retVal = "test_0001" // if beego.BConfig.RunMode == "dev" {
} // retVal = "test_0001"
return retVal, nil // }
} // return retVal, nil
//}
func getDataCityCodeFromOrder(order *model.GoodsOrder, db *dao.DaoDB) (retVal string, err error) { //
jxStoreID := jxutils.GetSaleStoreIDFromOrder(order) //func getDataCityCodeFromOrder(order *model.GoodsOrder, db *dao.DaoDB) (retVal string, err error) {
sql := ` // jxStoreID := jxutils.GetSaleStoreIDFromOrder(order)
SELECT t2.tel_code // sql := `
FROM store t1 // SELECT t2.tel_code
JOIN place t2 on t1.city_code = t2.code // FROM store t1
WHERE t1.id = ? // JOIN place t2 on t1.city_code = t2.code
` // WHERE t1.id = ?
codeInfo := &struct { // `
TelCode string // codeInfo := &struct {
}{} // TelCode string
if err = dao.GetRow(db, codeInfo, sql, jxStoreID); err != nil { // }{}
if err == nil { // if err = dao.GetRow(db, codeInfo, sql, jxStoreID); err != nil {
err = errors.New("不能找到美团配送站点配置") // if err == nil {
} // err = errors.New("不能找到美团配送站点配置")
return "", err // }
} // return "", err
return codeInfo.TelCode, nil // }
} // return codeInfo.TelCode, nil
//}