京东正向订单结账信息记录优化
This commit is contained in:
@@ -38,7 +38,7 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
afsOrder.JxStoreID = order.JxStoreID
|
afsOrder.JxStoreID = order.JxStoreID
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("ebai OnFinancialMsg, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
if orderData["refund_detail"] != nil {
|
if orderData["refund_detail"] != nil {
|
||||||
@@ -61,10 +61,10 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
|||||||
if len(refundDetail) > 0 {
|
if len(refundDetail) > 0 {
|
||||||
afsOrder.ConfirmTime = afsOrder.Skus[0].ConfirmTime
|
afsOrder.ConfirmTime = afsOrder.Skus[0].ConfirmTime
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("ebai OnFinancialMsg, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("ebai OnFinancialMsg, orderID:% refund_detail is nil", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, orderID:% refund_detail is nil", afsOrder.VendorOrderID)
|
||||||
}
|
}
|
||||||
return afsOrder
|
return afsOrder
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("ebai OnOrderDetail, orderID:%s is not found from partner.CurOrderManager.LoadOrder", orderDetail.VendorOrderID)
|
globals.SugarLogger.Warnf("ebai OrderDetail2Financial, orderID:%s is not found from partner.CurOrderManager.LoadOrder", orderDetail.VendorOrderID)
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
if result["products"] != nil {
|
if result["products"] != nil {
|
||||||
|
|||||||
@@ -14,9 +14,17 @@ import (
|
|||||||
func OnFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
func OnFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
var err error
|
var err error
|
||||||
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle || msg.StatusID == jdapi.OrderStatusAdjustSettle || msg.StatusID == jdapi.OrderStatusSwitch2SelfSettle { // 如果是正向单
|
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle || msg.StatusID == jdapi.OrderStatusAdjustSettle || msg.StatusID == jdapi.OrderStatusSwitch2SelfSettle { // 如果是正向单
|
||||||
|
order, err2 := partner.CurOrderManager.LoadOrder(msg.BillID, model.VendorIDJD)
|
||||||
|
if err = err2; err == nil {
|
||||||
orderData, err2 := api.JdAPI.QuerySingleOrder(msg.BillID)
|
orderData, err2 := api.JdAPI.QuerySingleOrder(msg.BillID)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
err = orderman.SaveOrderFinancialInfo(curPurchaseHandler.OrderDetail2Financial(orderData))
|
orderFinancial, err2 := curPurchaseHandler.OrderDetail2Financial(orderData, false, order)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
err = orderman.SaveOrderFinancialInfo(orderFinancial)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = nil
|
||||||
}
|
}
|
||||||
} else if msg.StatusID == jdapi.SaleBillStatusRefundSuccess || msg.StatusID == jdapi.SaleBillStatusSaleReturnSuccess { // 如果是退款单
|
} else if msg.StatusID == jdapi.SaleBillStatusRefundSuccess || msg.StatusID == jdapi.SaleBillStatusSaleReturnSuccess { // 如果是退款单
|
||||||
orderData, err2 := api.JdAPI.GetAfsService(msg.BillID)
|
orderData, err2 := api.JdAPI.GetAfsService(msg.BillID)
|
||||||
@@ -28,8 +36,8 @@ func OnFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理京东正向订单信息
|
// 处理京东正向订单信息
|
||||||
func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}) (orderDetail *model.OrderFinancial) {
|
func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}, isFromOrderDetail bool, order *model.GoodsOrder) (orderFinancial *model.OrderFinancial, err error) {
|
||||||
orderDetail = &model.OrderFinancial{
|
orderFinancial = &model.OrderFinancial{
|
||||||
VendorID: model.VendorIDJD,
|
VendorID: model.VendorIDJD,
|
||||||
VendorOrderID: utils.Int64ToStr(utils.MustInterface2Int64(orderData["orderId"])),
|
VendorOrderID: utils.Int64ToStr(utils.MustInterface2Int64(orderData["orderId"])),
|
||||||
ReceivableFreight: utils.MustInterface2Int64(orderData["orderReceivableFreight"]),
|
ReceivableFreight: utils.MustInterface2Int64(orderData["orderReceivableFreight"]),
|
||||||
@@ -40,28 +48,23 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
|
|||||||
FreightTipsMoney: utils.MustInterface2Int64(orderData["tips"]),
|
FreightTipsMoney: utils.MustInterface2Int64(orderData["tips"]),
|
||||||
// BoxFee: utils.MustInterface2Int64(orderData["packagingMoney"]), // 京东包装(塑料袋)由京东提供,相应钱款也归京东,不记录/记录之后优化算法
|
// BoxFee: utils.MustInterface2Int64(orderData["packagingMoney"]), // 京东包装(塑料袋)由京东提供,相应钱款也归京东,不记录/记录之后优化算法
|
||||||
}
|
}
|
||||||
order, err := partner.CurOrderManager.LoadOrder(orderDetail.VendorOrderID, orderDetail.VendorID)
|
|
||||||
if err == nil {
|
|
||||||
skus := order.Skus
|
skus := order.Skus
|
||||||
if skus != nil {
|
if skus != nil {
|
||||||
for _, x := range skus {
|
for _, x := range skus {
|
||||||
orderDetail.ShopPriceMoney += x.ShopPrice
|
orderFinancial.ShopPriceMoney += x.ShopPrice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Warnf("jd OnJdOrderinfo, orderID:%s is not found from partner.CurOrderManager.LoadOrder", orderDetail.VendorOrderID)
|
|
||||||
}
|
|
||||||
if orderData["product"] != nil {
|
if orderData["product"] != nil {
|
||||||
product := orderData["product"].([]interface{})
|
product := orderData["product"].([]interface{})
|
||||||
for _, x := range product {
|
for _, x := range product {
|
||||||
xMap := x.(map[string]interface{})
|
xMap := x.(map[string]interface{})
|
||||||
orderDetail.SalePriceMoney += utils.MustInterface2Int64(xMap["skuJdPrice"]) * utils.MustInterface2Int64(xMap["skuCount"])
|
orderFinancial.SalePriceMoney += utils.MustInterface2Int64(xMap["skuJdPrice"]) * utils.MustInterface2Int64(xMap["skuCount"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
orderDetail.DeliveryConfirmTime = utils.Str2TimeWithDefault(utils.Interface2String(orderData["deliveryConfirmTime"]), utils.DefaultTimeValue)
|
orderFinancial.DeliveryConfirmTime = utils.Str2TimeWithDefault(utils.Interface2String(orderData["deliveryConfirmTime"]), utils.DefaultTimeValue)
|
||||||
if utils.Interface2String(orderData["deliveryCarrierNo"]) == jdapi.SelfDeliveryCarrierNo {
|
if utils.Interface2String(orderData["deliveryCarrierNo"]) == jdapi.SelfDeliveryCarrierNo {
|
||||||
orderDetail.SelfDeliveryDiscountMoney = utils.MustInterface2Int64(orderData["orderReceivableFreight"])
|
orderFinancial.SelfDeliveryDiscountMoney = utils.MustInterface2Int64(orderData["orderReceivableFreight"])
|
||||||
orderDetail.DistanceFreightMoney = 0
|
orderFinancial.DistanceFreightMoney = 0
|
||||||
}
|
}
|
||||||
if orderData["discount"] != nil {
|
if orderData["discount"] != nil {
|
||||||
discount := orderData["discount"].([]interface{})
|
discount := orderData["discount"].([]interface{})
|
||||||
@@ -70,25 +73,29 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
|
|||||||
discountPrice := utils.MustInterface2Int64(xMap["discountPrice"])
|
discountPrice := utils.MustInterface2Int64(xMap["discountPrice"])
|
||||||
discountType := int(utils.MustInterface2Int64(xMap["discountType"]))
|
discountType := int(utils.MustInterface2Int64(xMap["discountType"]))
|
||||||
if discountType == jdapi.FreightDiscountTypeByShop {
|
if discountType == jdapi.FreightDiscountTypeByShop {
|
||||||
orderDetail.FreightDiscountMoney = discountPrice
|
orderFinancial.FreightDiscountMoney = discountPrice
|
||||||
}
|
}
|
||||||
if discountType == jdapi.FreightDiscountTypeByVip || discountType == jdapi.FreightDiscountTypeByActivity || discountType == jdapi.FreightDiscountTypeByCoupons {
|
if discountType == jdapi.FreightDiscountTypeByVip || discountType == jdapi.FreightDiscountTypeByActivity || discountType == jdapi.FreightDiscountTypeByCoupons {
|
||||||
orderDetail.VendorFreightDiscountMoney = discountPrice
|
orderFinancial.VendorFreightDiscountMoney = discountPrice
|
||||||
}
|
}
|
||||||
orderDetail.TotalDiscountMoney += discountPrice
|
orderFinancial.TotalDiscountMoney += discountPrice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
order1, err2 := api.JdAPI.OrderShoudSettlementService(orderDetail.VendorOrderID)
|
order1, err2 := api.JdAPI.OrderShoudSettlementService(orderFinancial.VendorOrderID)
|
||||||
if err2 == nil {
|
if err = err2; err == nil {
|
||||||
orderDetail.ShopMoney = utils.Interface2Int64WithDefault(order1["settlementAmount"], 0)
|
orderFinancial.ShopMoney = utils.Interface2Int64WithDefault(order1["settlementAmount"], 0)
|
||||||
orderDetail.PmMoney += utils.Interface2Int64WithDefault(order1["goodsCommission"], 0)
|
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["goodsCommission"], 0)
|
||||||
orderDetail.PmMoney += utils.Interface2Int64WithDefault(order1["freightCommission"], 0)
|
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["freightCommission"], 0)
|
||||||
orderDetail.PmMoney += utils.Interface2Int64WithDefault(order1["packageCommission"], 0)
|
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["packageCommission"], 0)
|
||||||
orderDetail.PmMoney += utils.Interface2Int64WithDefault(order1["guaranteedCommission"], 0)
|
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["guaranteedCommission"], 0)
|
||||||
orderDetail.PmSubsidyMoney += utils.Interface2Int64WithDefault(order1["platOrderGoodsDiscountMoney"], 0)
|
orderFinancial.PmSubsidyMoney += utils.Interface2Int64WithDefault(order1["platOrderGoodsDiscountMoney"], 0)
|
||||||
orderDetail.PmSubsidyMoney += utils.Interface2Int64WithDefault(order1["platSkuGoodsDiscountMoney"], 0)
|
orderFinancial.PmSubsidyMoney += utils.Interface2Int64WithDefault(order1["platSkuGoodsDiscountMoney"], 0)
|
||||||
|
} else {
|
||||||
|
if !isFromOrderDetail {
|
||||||
|
globals.SugarLogger.Warnf("jd OrderDetail2Financial, orderID:%s is not found from api.JdAPI.OrderShoudSettlementService", orderFinancial.VendorOrderID)
|
||||||
}
|
}
|
||||||
return orderDetail
|
}
|
||||||
|
return orderFinancial, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理京东售后订单结账信息
|
// 处理京东售后订单结账信息
|
||||||
@@ -110,7 +117,7 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
afsOrder.JxStoreID = order.JxStoreID
|
afsOrder.JxStoreID = order.JxStoreID
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("jd OnFinancialMsg, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("jd AfsOrderDetail2Financial, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
|
||||||
}
|
}
|
||||||
if orderData["afsDetailList"] != nil {
|
if orderData["afsDetailList"] != nil {
|
||||||
refundDetail := orderData["afsDetailList"].([]interface{})
|
refundDetail := orderData["afsDetailList"].([]interface{})
|
||||||
@@ -137,14 +144,21 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
|||||||
afsOrder.Skus = append(afsOrder.Skus, orderSku)
|
afsOrder.Skus = append(afsOrder.Skus, orderSku)
|
||||||
}
|
}
|
||||||
if len(refundDetail) <= 0 {
|
if len(refundDetail) <= 0 {
|
||||||
globals.SugarLogger.Warnf("ebai OnFinancialMsg, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("jd AfsOrderDetail2Financial, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("ebai OnFinancialMsg, orderID:% refund_detail is nil", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("jd AfsOrderDetail2Financial, orderID:% refund_detail is nil", afsOrder.VendorOrderID)
|
||||||
}
|
}
|
||||||
return afsOrder
|
return afsOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) OnOrderDetail(orderDetail map[string]interface{}) (err error) {
|
func (p *PurchaseHandler) OnOrderDetail(orderDetail map[string]interface{}) (err error) {
|
||||||
|
order, err := partner.CurOrderManager.LoadOrder(utils.Int64ToStr(utils.MustInterface2Int64(orderDetail["orderId"])), model.VendorIDJD)
|
||||||
|
if err == nil {
|
||||||
|
orderFinancial, err2 := curPurchaseHandler.OrderDetail2Financial(orderDetail, true, order)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
err = orderman.SaveOrderFinancialInfo(orderFinancial)
|
||||||
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData url.Values) (afsOrd
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
afsOrder.JxStoreID = order.JxStoreID
|
afsOrder.JxStoreID = order.JxStoreID
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("mtwm OnFinancialMsg, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("mtwm AfsOrderDetail2Financial, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
food := orderData.Get("food")
|
food := orderData.Get("food")
|
||||||
@@ -61,7 +61,7 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData url.Values) (afsOrd
|
|||||||
afsOrder.Skus = append(afsOrder.Skus, orderSku)
|
afsOrder.Skus = append(afsOrder.Skus, orderSku)
|
||||||
}
|
}
|
||||||
if len(refundDetail) <= 0 {
|
if len(refundDetail) <= 0 {
|
||||||
globals.SugarLogger.Warnf("ebai OnFinancialMsg, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
|
globals.SugarLogger.Warnf("mtwm AfsOrderDetail2Financial, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
|
||||||
}
|
}
|
||||||
return afsOrder
|
return afsOrder
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user