- delivery fee added.

- fixed scheduler bug
This commit is contained in:
gazebo
2018-07-19 18:05:40 +08:00
parent 56fcb4f4ed
commit a56cb64f8e
8 changed files with 111 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
package mtps
import (
"math"
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/controller"
@@ -49,6 +51,7 @@ func (c *WaybillController) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal
order := c.callbackMsg2Waybill(msg)
switch msg.Status {
case mtpsapi.OrderStatusWaitingForSchedule:
order.DesiredFee = c.calculateDeliveryFee(order)
order.Status = model.WaybillStatusNew
case mtpsapi.OrderStatusAccepted:
order.Status = model.WaybillStatusAccepted
@@ -79,6 +82,53 @@ func (c *WaybillController) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (
return retVal
}
func (c *WaybillController) calculateDeliveryFee(bill *model.Waybill) (retVal int64) {
order, err := controller.OrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID)
if err != nil {
return 0
}
var lists []orm.ParamsList
db := orm.NewOrm()
JxStoreID := jxutils.GetJxStoreIDFromOrder(order)
num, err := db.Raw(`
SELECT t2.price, t2.lng, t2.lat
FROM jxstore t1
JOIN mtpsdeliveryprice t2 ON t2.citycode = t1.area
WHERE t1.storeid = ?
`, JxStoreID).ValuesList(&lists)
var delieveryFee int64
if err == nil && num == 1 {
delieveryFee = utils.Str2Int64(lists[0][0].(string))
} else {
globals.SugarLogger.Warnf("calculateDeliveryFee can not cal delivery fee for orderid:%s", order.VendorOrderID)
return 0
}
lng := utils.Str2Float64(lists[0][1].(string))
lat := utils.Str2Float64(lists[0][2].(string))
lng2, lat2, _ := controller.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))
} else {
delieveryFee += controller.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))
} else if order.Weight < 20*1000 {
delieveryFee += controller.StandardPrice2Int(2.5 + 1*float64(order.Weight/1000-10))
} else {
delieveryFee += controller.StandardPrice2Int(2.5 + 10 + 2*float64(order.Weight/1000-20))
}
return delieveryFee
}
// DeliveryPlatformHandler
func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
globals.SugarLogger.Infof("CreateWaybill bill:%v", order)