- move some funcs from controller to jxutils.
This commit is contained in:
@@ -2,16 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/scheduler"
|
||||
_ "git.rosy.net.cn/jx-callback/business/scheduler/defsch" // 导入缺省订单调度器
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
@@ -28,41 +25,6 @@ func init() {
|
||||
scheduler.CurrentScheduler.RegisterOrderManager(OrderManager)
|
||||
}
|
||||
|
||||
func StandardCoordinate2Int(value float64) int {
|
||||
return int(math.Round(value * 1000000))
|
||||
}
|
||||
|
||||
func IntCoordinate2Standard(value int) float64 {
|
||||
return float64(value) / 1000000
|
||||
}
|
||||
|
||||
func IntCoordinate2MarsStandard(gpsLng, gpsLat int, coordinateType int) (marsLng, marsLat float64, err error) {
|
||||
marsLng = IntCoordinate2Standard(gpsLng)
|
||||
marsLat = IntCoordinate2Standard(gpsLat)
|
||||
coordSys := ""
|
||||
switch coordinateType {
|
||||
case model.CoordinateTypeGPS:
|
||||
coordSys = autonavi.CoordSysGPS
|
||||
case model.CoordinateTypeMars:
|
||||
coordSys = autonavi.CoordSysAutonavi
|
||||
case model.CoordinateTypeBaiDu:
|
||||
coordSys = autonavi.CoordSysBaidu
|
||||
case model.CoordinateTypeMapbar:
|
||||
coordSys = autonavi.CoordSysMapbar
|
||||
default:
|
||||
globals.SugarLogger.Errorf("known coordinate type:%d", coordinateType)
|
||||
}
|
||||
return api.AutonaviAPI.CoordinateConvert(marsLng, marsLat, coordSys)
|
||||
}
|
||||
|
||||
func IntPrice2Standard(value int64) float64 {
|
||||
return float64(value) / 100
|
||||
}
|
||||
|
||||
func StandardPrice2Int(value float64) int64 {
|
||||
return int64(math.Round(value * 100))
|
||||
}
|
||||
|
||||
func addOrderOrWaybillStatus(status *model.OrderStatus, db orm.Ormer) (isDuplicated bool, err error) {
|
||||
status.ID = 0
|
||||
created, _, err := db.ReadOrCreate(status, "VendorOrderID", "VendorID", "OrderType", "VendorStatus", "StatusTime")
|
||||
|
||||
@@ -32,7 +32,7 @@ func (c *WaybillController) onWaybillMsg(msg *dadaapi.CallbackMsg) (retVal *dada
|
||||
order.Status = model.WaybillStatusNew
|
||||
case dadaapi.OrderStatusAccepted:
|
||||
if result, err := api.DadaAPI.QueryOrderInfo(msg.OrderID); err == nil {
|
||||
order.DesiredFee = controller.StandardPrice2Int(utils.Interface2FloatWithDefault(result["deliveryFee"], 0.0))
|
||||
order.DesiredFee = jxutils.StandardPrice2Int(utils.Interface2FloatWithDefault(result["deliveryFee"], 0.0))
|
||||
}
|
||||
order.Status = model.WaybillStatusAccepted
|
||||
case dadaapi.OrderStatusDelivering:
|
||||
@@ -70,14 +70,14 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
billParams := &dadaapi.OperateOrderRequiredParams{
|
||||
ShopNo: utils.Int2Str(order.StoreID), // 当前达达的门店号与京西是一样的
|
||||
OriginID: jxutils.ComposeUniversalOrderID(order.VendorOrderID, order.VendorID),
|
||||
CargoPrice: controller.IntPrice2Standard(order.SalePrice),
|
||||
CargoPrice: jxutils.IntPrice2Standard(order.SalePrice),
|
||||
IsPrepay: 0,
|
||||
ReceiverName: order.ConsigneeName,
|
||||
ReceiverAddress: order.ConsigneeAddress,
|
||||
ReceiverPhone: order.ConsigneeMobile,
|
||||
}
|
||||
if billParams.CityCode, err = controller.GetDataCityCodeFromOrder(order); err == nil {
|
||||
billParams.ReceiverLng, billParams.ReceiverLat, _ = controller.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
billParams.ReceiverLng, billParams.ReceiverLat, _ = jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
addParams := map[string]interface{}{
|
||||
"info": order.BuyerComment,
|
||||
"origin_mark": model.VendorNames[order.VendorID],
|
||||
|
||||
@@ -147,8 +147,8 @@ func (c *OrderController) getOrderInfo(orderID string) (order *model.GoodsOrder,
|
||||
deliveryGeo := strings.Split(utils.Interface2String(result["deliveryGeo"]), ",")
|
||||
if len(deliveryGeo) == 2 {
|
||||
order.CoordinateType = model.CoordinateTypeMars
|
||||
order.ConsigneeLng = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[0]))
|
||||
order.ConsigneeLat = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1]))
|
||||
order.ConsigneeLng = jxutils.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[0]))
|
||||
order.ConsigneeLat = jxutils.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1]))
|
||||
}
|
||||
|
||||
for _, group2 := range result["groups"].([]interface{}) {
|
||||
@@ -162,7 +162,7 @@ func (c *OrderController) getOrderInfo(orderID string) (order *model.GoodsOrder,
|
||||
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)),
|
||||
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
|
||||
SkuName: product["name"].(string),
|
||||
SalePrice: controller.StandardPrice2Int(utils.MustInterface2Float64(product["userPrice"])),
|
||||
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["userPrice"])),
|
||||
Weight: int(math.Round(utils.Interface2FloatWithDefault(product["weight"], 0.0))),
|
||||
OrderCreatedAt: order.OrderCreatedAt,
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func (c *WaybillController) onWaybillStatusMsg(msg *elmapi.CallbackWaybillStatus
|
||||
order.Status = model.WaybillStatusNew
|
||||
} else if msg.MsgType == elmapi.MsgTypeWaybillPickingUp {
|
||||
if result, err := api.ElmAPI.GetOrder(msg.OrderID); err == nil {
|
||||
order.DesiredFee = controller.StandardPrice2Int(utils.Interface2FloatWithDefault(result["deliverFee"], 0.0) +
|
||||
order.DesiredFee = jxutils.StandardPrice2Int(utils.Interface2FloatWithDefault(result["deliverFee"], 0.0) +
|
||||
utils.Interface2FloatWithDefault(result["vipDeliveryFeeDiscount"], 0.0))
|
||||
}
|
||||
order.Status = model.WaybillStatusAccepted
|
||||
|
||||
@@ -96,8 +96,8 @@ func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *mode
|
||||
order.CoordinateType = model.CoordinateTypeGPS
|
||||
}
|
||||
}
|
||||
order.ConsigneeLng = controller.StandardCoordinate2Int(originalLng)
|
||||
order.ConsigneeLat = controller.StandardCoordinate2Int(originalLat)
|
||||
order.ConsigneeLng = jxutils.StandardCoordinate2Int(originalLng)
|
||||
order.ConsigneeLat = jxutils.StandardCoordinate2Int(originalLat)
|
||||
// discounts := result["discount"].(map[string]interface{})
|
||||
for _, product2 := range result["product"].([]interface{}) {
|
||||
product := product2.(map[string]interface{})
|
||||
|
||||
@@ -108,31 +108,31 @@ func (c *WaybillController) calculateDeliveryFee(bill *model.Waybill) (retVal in
|
||||
|
||||
lng := utils.Str2Float64(lists[0][1].(string))
|
||||
lat := utils.Str2Float64(lists[0][2].(string))
|
||||
lng2, lat2, _ := controller.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
lng2, lat2, _ := jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
|
||||
distance := jxutils.EarthDistance(lat, lng, lat2, lng2) * 1.4
|
||||
if distance < 3 {
|
||||
} else if distance < 5 {
|
||||
delieveryFee += controller.StandardPrice2Int(math.Ceil(distance - 3))
|
||||
delieveryFee += jxutils.StandardPrice2Int(math.Ceil(distance - 3))
|
||||
} else {
|
||||
delieveryFee += controller.StandardPrice2Int(2 + 2*math.Ceil(distance-5))
|
||||
delieveryFee += jxutils.StandardPrice2Int(2 + 2*math.Ceil(distance-5))
|
||||
}
|
||||
|
||||
if order.Weight < 5*1000 {
|
||||
} else if order.Weight < 10*1000 {
|
||||
delieveryFee += controller.StandardPrice2Int(0.5 * float64(order.Weight/1000-5))
|
||||
delieveryFee += jxutils.StandardPrice2Int(0.5 * float64(order.Weight/1000-5))
|
||||
} else if order.Weight < 20*1000 {
|
||||
delieveryFee += controller.StandardPrice2Int(2.5 + 1*float64(order.Weight/1000-10))
|
||||
delieveryFee += jxutils.StandardPrice2Int(2.5 + 1*float64(order.Weight/1000-10))
|
||||
} else {
|
||||
delieveryFee += controller.StandardPrice2Int(2.5 + 10 + 2*float64(order.Weight/1000-20))
|
||||
delieveryFee += jxutils.StandardPrice2Int(2.5 + 10 + 2*float64(order.Weight/1000-20))
|
||||
}
|
||||
|
||||
hour, min, sec := bill.WaybillCreatedAt.Clock()
|
||||
totalSeconds := hour*3600 + min*60 + sec
|
||||
if totalSeconds >= 11*3600+30*60 && totalSeconds <= 13*3600 { // 11:30 -- 13:00
|
||||
delieveryFee += controller.StandardPrice2Int(3)
|
||||
delieveryFee += jxutils.StandardPrice2Int(3)
|
||||
} else if totalSeconds >= 21*3600 || totalSeconds <= 6*3600 { // 21:00 -- 06:00
|
||||
delieveryFee += controller.StandardPrice2Int(3)
|
||||
delieveryFee += jxutils.StandardPrice2Int(3)
|
||||
}
|
||||
return delieveryFee
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
|
||||
db := orm.NewOrm()
|
||||
// 忽略坐标转换错误,即使是转换出错,也只能当成转换成功来处理,底层会有错误日志输出
|
||||
lngFloat, latFloat, _ := controller.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
lngFloat, latFloat, _ := jxutils.IntCoordinate2MarsStandard(order.ConsigneeLng, order.ConsigneeLat, order.CoordinateType)
|
||||
billParams := &mtpsapi.CreateOrderByShopParam{
|
||||
OrderID: jxutils.ComposeUniversalOrderID(order.VendorOrderID, order.VendorID),
|
||||
DeliveryServiceCode: mtpsapi.DeliveryServiceCodeRapid,
|
||||
@@ -152,9 +152,9 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
ReceiverAddress: order.ConsigneeAddress,
|
||||
ReceiverPhone: order.ConsigneeMobile,
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
ReceiverLng: controller.StandardCoordinate2Int(lngFloat),
|
||||
ReceiverLat: controller.StandardCoordinate2Int(latFloat),
|
||||
GoodsValue: controller.IntPrice2Standard(order.SalePrice), // todo 超价处理
|
||||
ReceiverLng: jxutils.StandardCoordinate2Int(lngFloat),
|
||||
ReceiverLat: jxutils.StandardCoordinate2Int(latFloat),
|
||||
GoodsValue: jxutils.IntPrice2Standard(order.SalePrice), // todo 超价处理
|
||||
GoodsWeight: float64(order.Weight) / 1000,
|
||||
ExpectedDeliveryTime: order.ExpectedDeliveredTime.Unix(),
|
||||
OrderType: mtpsapi.OrderTypeASAP,
|
||||
@@ -168,7 +168,7 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
goodItem := &mtpsapi.GoodsItem{
|
||||
GoodCount: sku.Count,
|
||||
GoodName: sku.SkuName,
|
||||
GoodPrice: controller.IntPrice2Standard(sku.SalePrice),
|
||||
GoodPrice: jxutils.IntPrice2Standard(sku.SalePrice),
|
||||
GoodUnit: "", //这个应该不是必须的,商品名里已经有UNIT的字样了
|
||||
}
|
||||
goods.Goods = append(goods.Goods, goodItem)
|
||||
|
||||
@@ -151,8 +151,8 @@ func (c *OrderController) legacyWriteJxOrder(order *model.GoodsOrder, db orm.Orm
|
||||
BuyerFullAddress: order.ConsigneeAddress,
|
||||
BuyerMobile: order.ConsigneeMobile,
|
||||
BuyerCoordType: legacyMapCoordinateType(order.CoordinateType),
|
||||
BuyerLng: IntCoordinate2Standard(order.ConsigneeLng),
|
||||
BuyerLat: IntCoordinate2Standard(order.ConsigneeLat),
|
||||
BuyerLng: jxutils.IntCoordinate2Standard(order.ConsigneeLng),
|
||||
BuyerLat: jxutils.IntCoordinate2Standard(order.ConsigneeLat),
|
||||
CityName: "all",
|
||||
OrderStartTime: utils.Time2Str(order.OrderCreatedAt),
|
||||
JdStoreId: order.VendorStoreID,
|
||||
|
||||
@@ -8,8 +8,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -101,3 +104,38 @@ func EarthDistance(lat1, lng1, lat2, lng2 float64) float64 {
|
||||
dist := math.Acos(math.Sin(lat1)*math.Sin(lat2) + math.Cos(lat1)*math.Cos(lat2)*math.Cos(theta))
|
||||
return dist * radius
|
||||
}
|
||||
|
||||
func StandardCoordinate2Int(value float64) int {
|
||||
return int(math.Round(value * 1000000))
|
||||
}
|
||||
|
||||
func IntCoordinate2Standard(value int) float64 {
|
||||
return float64(value) / 1000000
|
||||
}
|
||||
|
||||
func IntCoordinate2MarsStandard(gpsLng, gpsLat int, coordinateType int) (marsLng, marsLat float64, err error) {
|
||||
marsLng = IntCoordinate2Standard(gpsLng)
|
||||
marsLat = IntCoordinate2Standard(gpsLat)
|
||||
coordSys := ""
|
||||
switch coordinateType {
|
||||
case model.CoordinateTypeGPS:
|
||||
coordSys = autonavi.CoordSysGPS
|
||||
case model.CoordinateTypeMars:
|
||||
coordSys = autonavi.CoordSysAutonavi
|
||||
case model.CoordinateTypeBaiDu:
|
||||
coordSys = autonavi.CoordSysBaidu
|
||||
case model.CoordinateTypeMapbar:
|
||||
coordSys = autonavi.CoordSysMapbar
|
||||
default:
|
||||
globals.SugarLogger.Errorf("known coordinate type:%d", coordinateType)
|
||||
}
|
||||
return api.AutonaviAPI.CoordinateConvert(marsLng, marsLat, coordSys)
|
||||
}
|
||||
|
||||
func IntPrice2Standard(value int64) float64 {
|
||||
return float64(value) / 100
|
||||
}
|
||||
|
||||
func StandardPrice2Int(value float64) int64 {
|
||||
return int64(math.Round(value * 100))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user