- begin mtwm callback.
This commit is contained in:
1
business/partner/purchase/mtwm/callback.go
Normal file
1
business/partner/purchase/mtwm/callback.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package mtwm
|
||||||
113
business/partner/purchase/mtwm/order.go
Normal file
113
business/partner/purchase/mtwm/order.go
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
package mtwm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
VendorStatus2StatusMap = map[string]int{
|
||||||
|
mtwmapi.OrderStatusUserCommitted: model.OrderStatusUnknown,
|
||||||
|
mtwmapi.OrderStatusNew: model.OrderStatusNew,
|
||||||
|
mtwmapi.OrderStatusReceived: model.OrderStatusAccepted,
|
||||||
|
mtwmapi.OrderStatusAccepted: model.OrderStatusFinishedPickup,
|
||||||
|
mtwmapi.OrderStatusDelivering: model.OrderStatusDelivering,
|
||||||
|
mtwmapi.OrderStatusDelivered: model.OrderStatusDelivered,
|
||||||
|
mtwmapi.OrderStatusFinished: model.OrderStatusFinished,
|
||||||
|
mtwmapi.OrderStatusCanceled: model.OrderStatusCanceled,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStatusFromVendorStatus(vendorStatus string) int {
|
||||||
|
if status, ok := VendorStatus2StatusMap[vendorStatus]; ok {
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
return model.OrderStatusUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetOrder(vendorOrderID string) (order *model.GoodsOrder, err error) {
|
||||||
|
result, err := api.MtwmAPI.OrderGetOrderDetail(utils.Str2Int64(vendorOrderID), true)
|
||||||
|
// globals.SugarLogger.Info(result)
|
||||||
|
if err == nil {
|
||||||
|
deliveryTime := utils.Interface2Int64WithDefault(result["delivery_time"], 0)
|
||||||
|
order = &model.GoodsOrder{
|
||||||
|
VendorOrderID: vendorOrderID,
|
||||||
|
VendorOrderID2: utils.Int64ToStr(utils.MustInterface2Int64(result["wm_order_id_view"])),
|
||||||
|
VendorID: model.VendorIDMTWM,
|
||||||
|
VendorStoreID: result["app_poi_code"].(string),
|
||||||
|
StoreID: int(utils.Interface2Int64WithDefault(result["app_poi_code"].(string), 0)),
|
||||||
|
StoreName: result["wm_poi_name"].(string),
|
||||||
|
ConsigneeName: result["recipient_name"].(string),
|
||||||
|
ConsigneeMobile: result["recipient_phone"].(string),
|
||||||
|
ConsigneeAddress: result["recipient_address"].(string),
|
||||||
|
CoordinateType: model.CoordinateTypeMars,
|
||||||
|
BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["caution"])),
|
||||||
|
ExpectedDeliveredTime: getTimeFromTimestamp(deliveryTime),
|
||||||
|
VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(result["status"])),
|
||||||
|
OrderSeq: int(utils.MustInterface2Int64(result["day_seq"])),
|
||||||
|
StatusTime: getTimeFromTimestamp(utils.MustInterface2Int64(result["ctime"])),
|
||||||
|
OriginalData: string(utils.MustMarshal(result)),
|
||||||
|
ActualPayPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(result["total"])),
|
||||||
|
Skus: []*model.OrderSku{},
|
||||||
|
}
|
||||||
|
if order.StoreID > math.MaxInt32 {
|
||||||
|
order.StoreID = 0
|
||||||
|
}
|
||||||
|
order.Status = p.GetStatusFromVendorStatus(order.VendorStatus)
|
||||||
|
if deliveryTime == 0 {
|
||||||
|
order.BusinessType = model.BusinessTypeImmediate
|
||||||
|
} else {
|
||||||
|
order.BusinessType = model.BusinessTypeDingshida
|
||||||
|
}
|
||||||
|
|
||||||
|
originalLng := utils.MustInterface2Float64(result["longitude"])
|
||||||
|
originalLat := utils.MustInterface2Float64(result["latitude"])
|
||||||
|
order.ConsigneeLng = jxutils.StandardCoordinate2Int(originalLng)
|
||||||
|
order.ConsigneeLat = jxutils.StandardCoordinate2Int(originalLat)
|
||||||
|
|
||||||
|
detail := result["detail"].([]interface{})
|
||||||
|
for _, product2 := range detail {
|
||||||
|
product := product2.(map[string]interface{})
|
||||||
|
skuName := product["food_name"].(string)
|
||||||
|
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName)
|
||||||
|
skuID := utils.Interface2String(product["sku_id"])
|
||||||
|
sku := &model.OrderSku{
|
||||||
|
VendorOrderID: order.VendorOrderID,
|
||||||
|
VendorID: model.VendorIDMTWM,
|
||||||
|
Count: int(utils.MustInterface2Float64(product["quantity"])),
|
||||||
|
SkuID: int(utils.Str2Int64WithDefault(skuID, 0)),
|
||||||
|
VendorSkuID: skuID,
|
||||||
|
SkuName: skuName,
|
||||||
|
Weight: jxutils.FormatSkuWeight(specQuality, specUnit), // 订单信息里没有重量,只有名字里尝试找
|
||||||
|
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
|
||||||
|
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
|
||||||
|
}
|
||||||
|
if sku.Weight == 0 {
|
||||||
|
sku.Weight = 222 // 如果名字里找不到缺省给半斤左右的一个特别值
|
||||||
|
}
|
||||||
|
// if product["isGift"].(bool) {
|
||||||
|
// sku.SkuType = 1
|
||||||
|
// }
|
||||||
|
order.Skus = append(order.Skus, sku)
|
||||||
|
order.SkuCount++
|
||||||
|
order.GoodsCount += sku.Count
|
||||||
|
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||||
|
order.Weight += sku.Weight * sku.Count
|
||||||
|
}
|
||||||
|
// setOrederDetailFee(result, order)
|
||||||
|
}
|
||||||
|
return order, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTimeFromTimestamp(timeStamp int64) time.Time {
|
||||||
|
if timeStamp < 1538103149 { // 立即达订单给的是1(而不是空,0),1538103149不是特殊值,只是一个任意之前的时间,这样写可以处理
|
||||||
|
return utils.DefaultTimeValue
|
||||||
|
}
|
||||||
|
return utils.Timestamp2Time(timeStamp)
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
@@ -8,3 +9,40 @@ import (
|
|||||||
type MtwmController struct {
|
type MtwmController struct {
|
||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) onCallbackMsg(msgType string) {
|
||||||
|
c.Data["json"] = mtwmapi.Err2CallbackResponse(nil, "")
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) WaybillStatus() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeWaybillStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) NewOrder() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeNewOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) OrderAccpted() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderAccepted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) OrderFinished() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderFinished)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) OrderFinancial() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderFinancial)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) UserUrgeOrder() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeUserUrgeOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) NumberDowngrade() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypePrivateNumberDowngrade)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *MtwmController) OrderModified() {
|
||||||
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderModified)
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ func init() {
|
|||||||
beego.AutoRouter(&controllers.ElemeController{})
|
beego.AutoRouter(&controllers.ElemeController{})
|
||||||
beego.AutoRouter(&controllers.DadaDeliveryController{})
|
beego.AutoRouter(&controllers.DadaDeliveryController{})
|
||||||
beego.AutoRouter(&controllers.EbaiController{})
|
beego.AutoRouter(&controllers.EbaiController{})
|
||||||
|
beego.AutoRouter(&controllers.MtwmController{})
|
||||||
|
|
||||||
// 如下都是用于检测存活的空接口
|
// 如下都是用于检测存活的空接口
|
||||||
beego.Any("/", func(ctx *beecontext.Context) {
|
beego.Any("/", func(ctx *beecontext.Context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user