- add SaveOrder to IOrderManager
- add Map2Order to IPurchasePlatformHandler
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user