- mtps, dada create waybill
- create legacy jxorder(not finished).
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/controller"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/scheduler"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
@@ -46,33 +48,52 @@ func (c *OrderController) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi
|
||||
default:
|
||||
status.Status = model.OrderStatusUnknown
|
||||
}
|
||||
retVal = jdapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||
err := controller.OrderManager.OnOrderStatusChanged(status)
|
||||
if globals.HandleLegacyJxOrder && err == nil {
|
||||
c.legacyJdOrderStatusChanged(status)
|
||||
}
|
||||
retVal = jdapi.Err2CallbackResponse(err, status.VendorStatus)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *model.GoodsOrder, orderSkus []*model.OrderSku, err error) {
|
||||
func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *model.GoodsOrder, err error) {
|
||||
result, err := api.JdAPI.QuerySingleOrder(msg.BillID)
|
||||
// globals.SugarLogger.Info(result)
|
||||
if err == nil {
|
||||
order = &model.GoodsOrder{
|
||||
VendorOrderID: msg.BillID,
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorStoreID: result["produceStationNo"].(string),
|
||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["produceStationNoIsv"]), 0)),
|
||||
StoreName: result["produceStationName"].(string),
|
||||
ConsigneeName: result["buyerFullName"].(string),
|
||||
ConsigneeMobile: result["buyerMobile"].(string),
|
||||
ConsigneeAddress: result["buyerFullAddress"].(string),
|
||||
ConsigneeLat: controller.StandardCoordinate2Int(utils.MustInterface2Float64(result["buyerLat"])),
|
||||
ConsigneeLng: controller.StandardCoordinate2Int(utils.MustInterface2Float64(result["buyerLng"])),
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
VendorStatus: msg.StatusID,
|
||||
OrderCreatedAt: utils.Str2Time(result["orderStartTime"].(string)),
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
VendorOrderID: msg.BillID,
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorStoreID: result["produceStationNo"].(string),
|
||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["produceStationNoIsv"]), 0)),
|
||||
StoreName: result["produceStationName"].(string),
|
||||
ConsigneeName: result["buyerFullName"].(string),
|
||||
ConsigneeMobile: result["buyerMobile"].(string),
|
||||
ConsigneeAddress: result["buyerFullAddress"].(string),
|
||||
CoordinateType: model.CoordinateTypeMars,
|
||||
BuyerComment: utils.Interface2String(result["orderBuyerRemark"]),
|
||||
ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["orderPreEndDeliveryTime"]), utils.DefaultTimeValue),
|
||||
VendorStatus: msg.StatusID,
|
||||
OrderCreatedAt: utils.Str2Time(result["orderStartTime"].(string)),
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
Skus: []*model.OrderSku{},
|
||||
}
|
||||
coordinateType := utils.Interface2Int64WithDefault(result["buyerCoordType"], 1)
|
||||
originalLng := utils.MustInterface2Float64(result["buyerLng"])
|
||||
originalLat := utils.MustInterface2Float64(result["buyerLat"])
|
||||
if coordinateType == 1 {
|
||||
lng, lat, err2 := api.AutonaviAPI.CoordinateConvert(originalLng, originalLat, autonavi.CoordSysGPS)
|
||||
if err2 == nil {
|
||||
originalLng = lng
|
||||
originalLat = lat
|
||||
} else {
|
||||
// 如果没有转成功,保留原始数据
|
||||
order.CoordinateType = model.CoordinateTypeGPS
|
||||
}
|
||||
}
|
||||
order.ConsigneeLng = controller.StandardCoordinate2Int(originalLng)
|
||||
order.ConsigneeLat = controller.StandardCoordinate2Int(originalLat)
|
||||
// discounts := result["discount"].(map[string]interface{})
|
||||
orderSkus = []*model.OrderSku{}
|
||||
for _, product2 := range result["product"].([]interface{}) {
|
||||
product := product2.(map[string]interface{})
|
||||
sku := &model.OrderSku{
|
||||
@@ -84,33 +105,43 @@ func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *mode
|
||||
SkuName: product["skuName"].(string),
|
||||
Weight: int(utils.MustInterface2Float64(product["skuWeight"]) * 1000),
|
||||
SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]),
|
||||
PromotionType: int(utils.MustInterface2Int64(product["skuJdPrice"])),
|
||||
OrderCreatedAt: order.OrderCreatedAt,
|
||||
}
|
||||
orderSkus = append(orderSkus, sku)
|
||||
if product["isGift"].(bool) {
|
||||
sku.SkuType = 1
|
||||
}
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice
|
||||
order.Weight += sku.Weight
|
||||
}
|
||||
}
|
||||
return order, orderSkus, err
|
||||
return order, err
|
||||
}
|
||||
|
||||
//
|
||||
func (c *OrderController) onOrderNew(msg *jdapi.CallbackOrderMsg) (response *jdapi.CallbackResponse) {
|
||||
order, orderSkus, err := c.getOrderInfo(msg)
|
||||
order, err := c.getOrderInfo(msg)
|
||||
if err == nil {
|
||||
order.Status = model.OrderStatusNew
|
||||
err = controller.OrderManager.OnOrderNew(order, orderSkus)
|
||||
err = controller.OrderManager.OnOrderNew(order)
|
||||
if err == nil {
|
||||
c.legacyWriteJdOrder(order, false)
|
||||
}
|
||||
}
|
||||
return jdapi.Err2CallbackResponse(err, "jd onOrderNew")
|
||||
}
|
||||
|
||||
func (c *OrderController) onOrderAdjust(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
||||
order, orderSkus, err := c.getOrderInfo(msg)
|
||||
order, err := c.getOrderInfo(msg)
|
||||
if err == nil {
|
||||
order.Status = model.OrderStatusAdjust
|
||||
err = controller.OrderManager.OnOrderAdjust(order, orderSkus)
|
||||
err = controller.OrderManager.OnOrderAdjust(order)
|
||||
if globals.HandleLegacyJxOrder && err == nil {
|
||||
c.legacyWriteJdOrder(order, true)
|
||||
}
|
||||
}
|
||||
return jdapi.Err2CallbackResponse(err, "jd onOrderAdjust")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user