- 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")
|
||||
}
|
||||
|
||||
49
business/controller/jd/order_legacy.go
Normal file
49
business/controller/jd/order_legacy.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/legacyorder"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
// 为了兼容之前的表,造出原来需要的数据
|
||||
func (c *OrderController) legacyWriteJdOrder(order *model.GoodsOrder, delOldFirst bool) (err error) {
|
||||
db := orm.NewOrm()
|
||||
if delOldFirst {
|
||||
db.Raw("DELETE FROM jdorder2 WHERE jdorderid = ?", utils.Str2Int64(order.VendorOrderID)).Exec()
|
||||
}
|
||||
legacyOrder := &legacyorder.Jdorder2{
|
||||
Code: "0",
|
||||
Jdorderid: utils.Str2Int64(order.VendorOrderID),
|
||||
Orderstatus: int(utils.Str2Int64(order.VendorStatus)),
|
||||
Orderstatustime: utils.Time2Str(order.OrderCreatedAt),
|
||||
Success: 1,
|
||||
Cityname: "all",
|
||||
}
|
||||
_, err = db.Insert(legacyOrder)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Infof("legacyWriteJdOrder orderID:%v insert error:%v", order.VendorOrderID, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *OrderController) legacyJdOrderStatusChanged(status *model.OrderStatus) (err error) {
|
||||
db := orm.NewOrm()
|
||||
legacyOrder := &legacyorder.Jdorder2{
|
||||
Jdorderid: utils.Str2Int64(status.VendorOrderID),
|
||||
}
|
||||
|
||||
if err = db.Read(legacyOrder, "Jdorderid"); err == nil {
|
||||
utils.CallFuncLogError(func() error {
|
||||
legacyOrder.Orderstatus = int(utils.Str2Int64(status.VendorStatus))
|
||||
legacyOrder.Orderstatustime = utils.Time2Str(status.StatusTime)
|
||||
_, err = db.Update(legacyOrder, "Orderstatus", "Orderstatustime")
|
||||
return err
|
||||
}, "legacyJdOrderStatusChanged")
|
||||
} else {
|
||||
globals.SugarLogger.Infof("read legacyJdOrder error:%v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user