diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 4d84b0d11..578fb65ac 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -75,7 +75,7 @@ func (c *OrderManager) OnOrderNew(order *model.GoodsOrder, msgVendorStatus strin status.VendorStatus = msgVendorStatus isDuplicated, err := addOrderOrWaybillStatus(status, db) if err == nil && !isDuplicated { - if isDuplicated, err = c.saveOrder(order, false, db); err == nil && !isDuplicated { + if isDuplicated, err = c.SaveOrder(order, false, db); err == nil && !isDuplicated { err = scheduler.CurrentScheduler.OnOrderNew(order, false) } } @@ -108,7 +108,7 @@ func (c *OrderManager) OnOrderAdjust(order *model.GoodsOrder, msgVendorStatus st if err != nil { return err } - if isDuplicated, err = c.saveOrder(order, true, db); err == nil && !isDuplicated { + if isDuplicated, err = c.SaveOrder(order, true, db); err == nil && !isDuplicated { // 因为订单调度器需要的是真实状态,所以用order的状态 err = scheduler.CurrentScheduler.OnOrderNew(order, false) err = scheduler.CurrentScheduler.OnOrderStatusChanged(model.Order2Status(order), false) @@ -125,8 +125,7 @@ func (c *OrderManager) OnOrderStatusChanged(orderStatus *model.OrderStatus) (err return err } -// private -func (c *OrderManager) saveOrder(order *model.GoodsOrder, isAdjust bool, db orm.Ormer) (isDuplicated bool, err error) { +func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db orm.Ormer) (isDuplicated bool, err error) { // 忽略查找JX信息错误 c.updateOrderOtherInfo(order, db) order.ID = 0 diff --git a/business/partner/partner.go b/business/partner/partner.go index 2e990a508..a559c612b 100644 --- a/business/partner/partner.go +++ b/business/partner/partner.go @@ -9,6 +9,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" + "github.com/astaxie/beego/orm" ) const ( @@ -42,6 +43,8 @@ var ( ) type IOrderManager interface { + SaveOrder(order *model.GoodsOrder, isAdjust bool, db orm.Ormer) (isDuplicated bool, err error) + OnOrderNew(order *model.GoodsOrder, msgVendorStatus string) (err error) OnOrderAdjust(order *model.GoodsOrder, msgVendorStatus string) (err error) OnOrderStatusChanged(orderStatus *model.OrderStatus) (err error) @@ -61,6 +64,7 @@ type IOrderManager interface { type IPurchasePlatformHandler interface { GetStatusFromVendorStatus(vendorStatus string) int + Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) GetOrder(vendorOrderID string) (order *model.GoodsOrder, err error) GetStatusActionTimeout(statusType, status int) time.Duration diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index dfd15cefc..5c1d364bf 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -45,90 +45,97 @@ func (p *PurchaseHandler) GetOrder(vendorOrderID string) (order *model.GoodsOrde result, err := api.EbaiAPI.OrderGet(vendorOrderID) // globals.SugarLogger.Info(result) if err == nil { - shopMap := result["shop"].(map[string]interface{}) - orderMap := result["order"].(map[string]interface{}) - userMap := result["user"].(map[string]interface{}) - order = &model.GoodsOrder{ - VendorOrderID: vendorOrderID, - VendorOrderID2: orderMap["eleme_order_id"].(string), - VendorID: model.VendorIDEBAI, - VendorStoreID: shopMap["baidu_shop_id"].(string), - StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(shopMap["id"]), 0)), - StoreName: shopMap["name"].(string), - ConsigneeName: userMap["name"].(string), - ConsigneeMobile: userMap["phone"].(string), - ConsigneeAddress: userMap["address"].(string), - CoordinateType: model.CoordinateTypeBaiDu, - BuyerComment: utils.TrimBlankChar(utils.Interface2String(orderMap["remark"])), - ExpectedDeliveredTime: getTimeFromTimestampStr(utils.Interface2String(orderMap["send_time"])), - VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(orderMap["status"])), - OrderSeq: int(utils.Str2Int64(utils.Interface2String(orderMap["order_index"]))), - StatusTime: getTimeFromTimestampStr(utils.Interface2String(orderMap["create_time"])), - OriginalData: string(utils.MustMarshal(result)), - ActualPayPrice: utils.MustInterface2Int64(orderMap["user_fee"]), - Skus: []*model.OrderSku{}, - } - if jxutils.IsMobileFake(order.ConsigneeMobile) { - if mobileInfo, err := api.EbaiAPI.OrderPrivateInfo(vendorOrderID); err == nil { - order.ConsigneeMobile = mobileInfo.ShortNumber - } - } - if order.StoreID > math.MaxInt32 { - order.StoreID = 0 - } - order.Status = p.GetStatusFromVendorStatus(order.VendorStatus) - if utils.MustInterface2Int64(orderMap["send_immediately"]) == 1 { - order.BusinessType = model.BusinessTypeImmediate - } else { - order.BusinessType = model.BusinessTypeDingshida - } - - deliveryGeo := userMap["coord"].(map[string]interface{}) - originalLng := utils.Interface2FloatWithDefault(deliveryGeo["longitude"], 0.0) // 饿百的订单在过一段时间后,经纬度信息会变成字符串"**" - originalLat := utils.Interface2FloatWithDefault(deliveryGeo["latitude"], 0.0) - lng, lat, err2 := api.AutonaviAPI.CoordinateConvert(originalLng, originalLat, autonavi.CoordSysBaidu) - if err2 == nil { - originalLng = lng - originalLat = lat - order.CoordinateType = model.CoordinateTypeMars - } - order.ConsigneeLng = jxutils.StandardCoordinate2Int(originalLng) - order.ConsigneeLat = jxutils.StandardCoordinate2Int(originalLat) - - products := result["products"].([]interface{})[0].([]interface{}) - // discounts := result["discount"].(map[string]interface{}) - for _, product2 := range products { - product := product2.(map[string]interface{}) - skuName := product["product_name"].(string) - _, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName) - sku := &model.OrderSku{ - VendorOrderID: order.VendorOrderID, - VendorID: model.VendorIDEBAI, - Count: int(utils.MustInterface2Int64(product["product_amount"])), - SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["custom_sku_id"]), 0)), - VendorSkuID: utils.Interface2String(product["baidu_product_id"]), - SkuName: skuName, - Weight: jxutils.FormatSkuWeight(specQuality, specUnit), // 订单信息里没有重量,只有名字里尝试找 - SalePrice: utils.MustInterface2Int64(product["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) + order = p.Map2Order(result) } return order, err } +func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) { + result := orderData + shopMap := result["shop"].(map[string]interface{}) + orderMap := result["order"].(map[string]interface{}) + userMap := result["user"].(map[string]interface{}) + vendorOrderID := orderMap["order_id"].(string) + order = &model.GoodsOrder{ + VendorOrderID: vendorOrderID, + VendorOrderID2: orderMap["eleme_order_id"].(string), + VendorID: model.VendorIDEBAI, + VendorStoreID: shopMap["baidu_shop_id"].(string), + StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(shopMap["id"]), 0)), + StoreName: shopMap["name"].(string), + ConsigneeName: userMap["name"].(string), + ConsigneeMobile: userMap["phone"].(string), + ConsigneeAddress: userMap["address"].(string), + CoordinateType: model.CoordinateTypeBaiDu, + BuyerComment: utils.TrimBlankChar(utils.Interface2String(orderMap["remark"])), + ExpectedDeliveredTime: getTimeFromTimestampStr(utils.Interface2String(orderMap["send_time"])), + VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(orderMap["status"])), + OrderSeq: int(utils.Str2Int64(utils.Interface2String(orderMap["order_index"]))), + StatusTime: getTimeFromTimestampStr(utils.Interface2String(orderMap["create_time"])), + OriginalData: string(utils.MustMarshal(result)), + ActualPayPrice: utils.MustInterface2Int64(orderMap["user_fee"]), + Skus: []*model.OrderSku{}, + } + if jxutils.IsMobileFake(order.ConsigneeMobile) { + if mobileInfo, err := api.EbaiAPI.OrderPrivateInfo(vendorOrderID); err == nil { + order.ConsigneeMobile = mobileInfo.ShortNumber + } + } + if order.StoreID > math.MaxInt32 { + order.StoreID = 0 + } + order.Status = p.GetStatusFromVendorStatus(order.VendorStatus) + if utils.MustInterface2Int64(orderMap["send_immediately"]) == 1 { + order.BusinessType = model.BusinessTypeImmediate + } else { + order.BusinessType = model.BusinessTypeDingshida + } + + deliveryGeo := userMap["coord"].(map[string]interface{}) + originalLng := utils.Interface2FloatWithDefault(deliveryGeo["longitude"], 0.0) // 饿百的订单在过一段时间后,经纬度信息会变成字符串"**" + originalLat := utils.Interface2FloatWithDefault(deliveryGeo["latitude"], 0.0) + lng, lat, err2 := api.AutonaviAPI.CoordinateConvert(originalLng, originalLat, autonavi.CoordSysBaidu) + if err2 == nil { + originalLng = lng + originalLat = lat + order.CoordinateType = model.CoordinateTypeMars + } + order.ConsigneeLng = jxutils.StandardCoordinate2Int(originalLng) + order.ConsigneeLat = jxutils.StandardCoordinate2Int(originalLat) + + products := result["products"].([]interface{})[0].([]interface{}) + // discounts := result["discount"].(map[string]interface{}) + for _, product2 := range products { + product := product2.(map[string]interface{}) + skuName := product["product_name"].(string) + _, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName) + sku := &model.OrderSku{ + VendorOrderID: order.VendorOrderID, + VendorID: model.VendorIDEBAI, + Count: int(utils.MustInterface2Int64(product["product_amount"])), + SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["custom_sku_id"]), 0)), + VendorSkuID: utils.Interface2String(product["baidu_product_id"]), + SkuName: skuName, + Weight: jxutils.FormatSkuWeight(specQuality, specUnit), // 订单信息里没有重量,只有名字里尝试找 + SalePrice: utils.MustInterface2Int64(product["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 +} + func (p *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) { globals.SugarLogger.Debugf("ebai AcceptOrRefuseOrder orderID:%s", order.VendorOrderID) if globals.EnableStoreWrite && globals.EnableEbaiStoreWrite { diff --git a/business/partner/purchase/elm/order.go b/business/partner/purchase/elm/order.go index 6790068b3..b55e5a724 100644 --- a/business/partner/purchase/elm/order.go +++ b/business/partner/purchase/elm/order.go @@ -123,73 +123,80 @@ func (c *PurchaseHandler) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancel func (c *PurchaseHandler) GetOrder(orderID string) (order *model.GoodsOrder, err error) { result, err := api.ElmAPI.GetOrder(orderID) if err == nil { - phoneList := result["phoneList"].([]interface{}) - consigneeMobile := "" - if len(phoneList) > 0 { - consigneeMobile = utils.Interface2String(phoneList[0]) - } - - // globals.SugarLogger.Debug(result) - order = &model.GoodsOrder{ - VendorOrderID: orderID, - VendorID: model.VendorIDELM, - VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shopId"])), - StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["openId"]), 0)), - StoreName: result["shopName"].(string), - ConsigneeName: result["consignee"].(string), - ConsigneeMobile: consigneeMobile, - ConsigneeAddress: result["address"].(string), - BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["description"])), - ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["deliverTime"]), utils.DefaultTimeValue), - VendorStatus: utils.Interface2String(result["status"]), // 取订单的原始status,不合并消息类型(因为当前消息类型没有意义) - OrderSeq: int(utils.MustInterface2Int64(result["daySn"])), - StatusTime: utils.Str2Time(result["activeAt"].(string)), - OriginalData: string(utils.MustMarshal(result)), - ActualPayPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(result["totalPrice"])), - Skus: []*model.OrderSku{}, - } - order.Status = c.GetStatusFromVendorStatus(order.VendorStatus) - if result["book"].(bool) { - order.BusinessType = model.BusinessTypeDingshida - } else { - order.BusinessType = model.BusinessTypeImmediate - } - deliveryGeo := strings.Split(utils.Interface2String(result["deliveryGeo"]), ",") - if len(deliveryGeo) == 2 { - order.CoordinateType = model.CoordinateTypeMars - order.ConsigneeLng = jxutils.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[0])) - order.ConsigneeLat = jxutils.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1])) - } - - for _, group2 := range result["groups"].([]interface{}) { - group := group2.(map[string]interface{}) - for _, product2 := range group["items"].([]interface{}) { - product := product2.(map[string]interface{}) - sku := &model.OrderSku{ - VendorOrderID: orderID, - VendorID: model.VendorIDELM, - Count: int(utils.MustInterface2Int64(product["quantity"])), - SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)), - VendorSkuID: utils.Int64ToStr(utils.Interface2Int64WithDefault(product["vfoodId"], 0)), - SkuName: product["name"].(string), - SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])), - Weight: int(math.Round(utils.Interface2FloatWithDefault(product["weight"], 0.0))), - } - if sku.VendorSkuID == "0" { - sku.VendorSkuID = utils.Int64ToStr(utils.MustInterface2Int64(product["id"])) // 2018-09-28日,饿了么迁移到饿百后,这个字段发生了变化 - } - 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) + order = c.Map2Order(result) } return order, err } +func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) { + result := orderData + orderID := result["id"].(string) + phoneList := result["phoneList"].([]interface{}) + consigneeMobile := "" + if len(phoneList) > 0 { + consigneeMobile = utils.Interface2String(phoneList[0]) + } + + // globals.SugarLogger.Debug(result) + order = &model.GoodsOrder{ + VendorOrderID: orderID, + VendorID: model.VendorIDELM, + VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shopId"])), + StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["openId"]), 0)), + StoreName: result["shopName"].(string), + ConsigneeName: result["consignee"].(string), + ConsigneeMobile: consigneeMobile, + ConsigneeAddress: result["address"].(string), + BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["description"])), + ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["deliverTime"]), utils.DefaultTimeValue), + VendorStatus: utils.Interface2String(result["status"]), // 取订单的原始status,不合并消息类型(因为当前消息类型没有意义) + OrderSeq: int(utils.MustInterface2Int64(result["daySn"])), + StatusTime: utils.Str2Time(result["activeAt"].(string)), + OriginalData: string(utils.MustMarshal(result)), + ActualPayPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(result["totalPrice"])), + Skus: []*model.OrderSku{}, + } + order.Status = c.GetStatusFromVendorStatus(order.VendorStatus) + if result["book"].(bool) { + order.BusinessType = model.BusinessTypeDingshida + } else { + order.BusinessType = model.BusinessTypeImmediate + } + deliveryGeo := strings.Split(utils.Interface2String(result["deliveryGeo"]), ",") + if len(deliveryGeo) == 2 { + order.CoordinateType = model.CoordinateTypeMars + order.ConsigneeLng = jxutils.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[0])) + order.ConsigneeLat = jxutils.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1])) + } + + for _, group2 := range result["groups"].([]interface{}) { + group := group2.(map[string]interface{}) + for _, product2 := range group["items"].([]interface{}) { + product := product2.(map[string]interface{}) + sku := &model.OrderSku{ + VendorOrderID: orderID, + VendorID: model.VendorIDELM, + Count: int(utils.MustInterface2Int64(product["quantity"])), + SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)), + VendorSkuID: utils.Int64ToStr(utils.Interface2Int64WithDefault(product["vfoodId"], 0)), + SkuName: product["name"].(string), + SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])), + Weight: int(math.Round(utils.Interface2FloatWithDefault(product["weight"], 0.0))), + } + if sku.VendorSkuID == "0" { + sku.VendorSkuID = utils.Int64ToStr(utils.MustInterface2Int64(product["id"])) // 2018-09-28日,饿了么迁移到饿百后,这个字段发生了变化 + } + 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 +} + func setOrederDetailFee(result map[string]interface{}, order *model.GoodsOrder) { orderActivities, ok := result["orderActivities"].([]interface{}) if ok { diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index 34f83fbd2..a97ef08bf 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -79,83 +79,90 @@ func (c *PurchaseHandler) GetOrder(orderID string) (order *model.GoodsOrder, err task.Run() task.GetResult(0) if err == nil { - order = &model.GoodsOrder{ - VendorOrderID: orderID, - VendorID: model.VendorIDJD, - VendorStoreID: result["produceStationNo"].(string), - StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["produceStationNoIsv"]), 0)), - StoreName: utils.Interface2String(result["produceStationName"]), - ConsigneeName: result["buyerFullName"].(string), - ConsigneeMobile: result["buyerMobile"].(string), - ConsigneeAddress: result["buyerFullAddress"].(string), - CoordinateType: model.CoordinateTypeMars, - BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["orderBuyerRemark"])), - ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["orderPreEndDeliveryTime"]), utils.DefaultTimeValue), - VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(result["orderStatus"])), - OrderSeq: int(utils.MustInterface2Int64(result["orderNum"])), - StatusTime: utils.Str2Time(result["orderPurchaseTime"].(string)), - OriginalData: string(utils.MustMarshal(result)), - ActualPayPrice: utils.MustInterface2Int64(result["orderBuyerPayableMoney"]), - Skus: []*model.OrderSku{}, - } + order = c.Map2Order(result) if err2 == nil { order.ConsigneeMobile2 = result2 } else { // globals.SugarLogger.Warnf("jd GetOrder orderID:%s, GetRealMobile4Order failed with error:%v", orderID, err2) } - order.Status = c.GetStatusFromVendorStatus(order.VendorStatus) - businessTage := utils.Interface2String(result["businessTag"]) - if strings.Index(businessTage, "dj_aging_immediately") >= 0 { - order.BusinessType = model.BusinessTypeImmediate - } else { - order.BusinessType = model.BusinessTypeDingshida - } - 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 = 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{}) - sku := &model.OrderSku{ - VendorOrderID: orderID, - VendorID: model.VendorIDJD, - Count: int(utils.MustInterface2Int64(product["skuCount"])), - SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["skuIdIsv"]), 0)), - VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])), - SkuName: product["skuName"].(string), - Weight: jxutils.FloatWeight2Int(float32(utils.MustInterface2Float64(product["skuWeight"]))), - SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]), - PromotionType: int(utils.MustInterface2Int64(product["promotionType"])), - } - if skuCostumeProperty, ok := product["skuCostumeProperty"]; ok { - sku.SkuName += skuCostumeProperty.(string) - } - 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 (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) { + result := orderData + orderID := utils.Int64ToStr(utils.MustInterface2Int64(result["orderId"])) + order = &model.GoodsOrder{ + VendorOrderID: orderID, + VendorID: model.VendorIDJD, + VendorStoreID: result["produceStationNo"].(string), + StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["produceStationNoIsv"]), 0)), + StoreName: utils.Interface2String(result["produceStationName"]), + ConsigneeName: result["buyerFullName"].(string), + ConsigneeMobile: result["buyerMobile"].(string), + ConsigneeAddress: result["buyerFullAddress"].(string), + CoordinateType: model.CoordinateTypeMars, + BuyerComment: utils.TrimBlankChar(utils.Interface2String(result["orderBuyerRemark"])), + ExpectedDeliveredTime: utils.Str2TimeWithDefault(utils.Interface2String(result["orderPreEndDeliveryTime"]), utils.DefaultTimeValue), + VendorStatus: utils.Int64ToStr(utils.MustInterface2Int64(result["orderStatus"])), + OrderSeq: int(utils.MustInterface2Int64(result["orderNum"])), + StatusTime: utils.Str2Time(result["orderPurchaseTime"].(string)), + OriginalData: string(utils.MustMarshal(result)), + ActualPayPrice: utils.MustInterface2Int64(result["orderBuyerPayableMoney"]), + Skus: []*model.OrderSku{}, + } + order.Status = c.GetStatusFromVendorStatus(order.VendorStatus) + businessTage := utils.Interface2String(result["businessTag"]) + if strings.Index(businessTage, "dj_aging_immediately") >= 0 { + order.BusinessType = model.BusinessTypeImmediate + } else { + order.BusinessType = model.BusinessTypeDingshida + } + 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 = 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{}) + sku := &model.OrderSku{ + VendorOrderID: orderID, + VendorID: model.VendorIDJD, + Count: int(utils.MustInterface2Int64(product["skuCount"])), + SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["skuIdIsv"]), 0)), + VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])), + SkuName: product["skuName"].(string), + Weight: jxutils.FloatWeight2Int(float32(utils.MustInterface2Float64(product["skuWeight"]))), + SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]), + PromotionType: int(utils.MustInterface2Int64(product["promotionType"])), + } + if skuCostumeProperty, ok := product["skuCostumeProperty"]; ok { + sku.SkuName += skuCostumeProperty.(string) + } + 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 +} + func setOrederDetailFee(result map[string]interface{}, order *model.GoodsOrder) { order.BoxFee = utils.MustInterface2Int64(result["packagingMoney"]) order.PlatformFeeRate = model.JdPlatformFeeRate diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index 20ce34fa7..cb8e26d7d 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -1,6 +1,7 @@ package mtwm import ( + "fmt" "net/url" "time" @@ -43,77 +44,84 @@ func (p *PurchaseHandler) GetOrder(vendorOrderID string) (order *model.GoodsOrde 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.Str2Int64(result["app_poi_code"].(string))), - 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{}, - } - 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) - - var detail []map[string]interface{} - if err := utils.UnmarshalUseNumber([]byte(result["detail"].(string)), &detail); err != nil { - return nil, err - } - // detail := result["detail"].([]interface{}) - for _, product := 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) + order = p.Map2Order(result) } return order, err } +func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) { + result := orderData + vendorOrderID := utils.Int64ToStr(utils.MustInterface2Int64(result["order_id"])) + 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.Str2Int64(result["app_poi_code"].(string))), + 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{}, + } + 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) + + var detail []map[string]interface{} + if err := utils.UnmarshalUseNumber([]byte(result["detail"].(string)), &detail); err != nil { + panic(fmt.Sprintf("mtwm Map2Order vendorID:%s failed with error:%v", vendorOrderID, err)) + } + // detail := result["detail"].([]interface{}) + for _, product := 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 +} + func (c *PurchaseHandler) onOrderMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) { var err error if msg.Cmd == mtwmapi.MsgTypeNewOrder || msg.Cmd == mtwmapi.MsgTypeOrderModified { diff --git a/business/partner/purchase/weimob/wsc/order.go b/business/partner/purchase/weimob/wsc/order.go index 726443010..d52979af8 100644 --- a/business/partner/purchase/weimob/wsc/order.go +++ b/business/partner/purchase/weimob/wsc/order.go @@ -106,6 +106,13 @@ func (p *PurchaseHandler) GetOrder(vendorOrderID string) (order *model.GoodsOrde if err != nil { return nil, err } + order = p.Map2Order(result) + return order, err +} + +func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) { + result := orderData + vendorOrderID := utils.Int64ToStr(utils.MustInterface2Int64(result["orderNo"])) deliveryDetail := result["deliveryDetail"].(map[string]interface{}) logisticsDeliveryDetail := deliveryDetail["logisticsDeliveryDetail"].(map[string]interface{}) // paymentInfo := result["paymentInfo"].(map[string]interface{}) @@ -156,7 +163,7 @@ func (p *PurchaseHandler) GetOrder(vendorOrderID string) (order *model.GoodsOrde } p.arrangeSaleStore(order, utils.Interface2String(logisticsDeliveryDetail["receiverCity"]), utils.Interface2String(logisticsDeliveryDetail["receiverProvince"])) p.setStoreOrderSeq(order) - return order, err + return order } func (p *PurchaseHandler) GetStatusActionTimeout(statusType, status int) time.Duration {