结账第二期

This commit is contained in:
renyutian
2019-04-03 17:49:30 +08:00
parent 7b43e7d6e9
commit 632aa6aa3d
17 changed files with 1028 additions and 231 deletions

View File

@@ -3,7 +3,6 @@ package ebai
import (
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
@@ -17,7 +16,7 @@ func OnFinancialMsg(msg *ebaiapi.CallbackMsg) (err error) {
orderData, err2 := api.EbaiAPI.OrderPartrefundGet(utils.Interface2String(msg.Body["refund_id"]))
if err = err2; err == nil {
afsOrder := CurPurchaseHandler.AfsOrderDetail2Financial(orderData)
err = orderman.SaveAfsOrderFinancialInfo(afsOrder)
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(afsOrder)
}
}
} else if msg.Cmd == ebaiapi.CmdOrderUserCancel { // 全额退款处理
@@ -25,16 +24,81 @@ func OnFinancialMsg(msg *ebaiapi.CallbackMsg) (err error) {
if utils.Int64ToStr(utils.MustInterface2Int64(msg.Body["cancel_type"])) == ebaiapi.AfterOrderFinishedCancelType &&
(messageType == ebaiapi.OrderUserCancelSuccessA || messageType == ebaiapi.OrderUserCancelSuccessB) {
globals.SugarLogger.Debug(utils.Interface2String(msg.Body["refund_id"])) // 获得退款订单ID去本地数据库拿饿百消息推送只给了订单号但是没有查询全额退款的接口只有部分退款才可以查询
afsOrderID := utils.Interface2String(msg.Body["refund_id"])
orderFinancial, err := partner.CurOrderManager.LoadOrderFinancial(afsOrderID, model.VendorIDEBAI)
if err == nil {
globals.SugarLogger.Debug(utils.Format4Output(orderFinancial, false))
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(CurPurchaseHandler.OrderFinancialDetail2Refund(orderFinancial, msg))
} else {
globals.SugarLogger.Warnf("ebai OnFinancialMsg, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrderFinancial", afsOrderID)
}
}
} else if msg.Cmd == ebaiapi.CmdOrderDeliveryStatus { // 转自送调整
if msg.Body["status"].(string) == ebaiapi.WaybillStatusSelfDelivery {
vendorOrderID := GetOrderIDFromMsg(msg)
orderMap, err := api.EbaiAPI.OrderGet(vendorOrderID)
if err == nil {
err = CurPurchaseHandler.OnOrderDetail(orderMap, partner.UpdatedPeration)
}
}
}
return err
}
func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interface{}) (afsOrder *model.AfterSalesOrder) {
afsOrder = &model.AfterSalesOrder{
VendorID: model.VendorIDEBAI,
AfterSalesOrderID: utils.Interface2String(orderData["order_id"]),
VendorOrderID: utils.Interface2String(orderData["order_id"]),
func (p *PurchaseHandler) OrderFinancialDetail2Refund(orderFinancial *model.OrderFinancial, msg *ebaiapi.CallbackMsg) (afsOrder *model.AfsOrder) {
afsOrder = &model.AfsOrder{
VendorID: model.VendorIDEBAI,
AfsOrderID: utils.Interface2String(msg.Body["refund_id"]),
VendorOrderID: utils.Interface2String(msg.Body["refund_id"]),
AfsCreateAt: utils.Timestamp2Time(utils.Str2Int64(utils.Interface2String(msg.Body["timestamp"]))),
// BoxMoney: orderFinancial.BoxMoney, // 饿百的餐盒费已经拆分到单条Sku里面退款时直接计算用户支付sku金额就好了
// SkuBoxMoney: orderFinancial.SkuBoxMoney,
FreightUserMoney: orderFinancial.FreightMoney,
SkuUserMoney: orderFinancial.ActualPayMoney - orderFinancial.FreightMoney,
PmSubsidyMoney: orderFinancial.PmSubsidyMoney,
}
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
globals.SugarLogger.Debug(utils.Format4Output(order, false))
if err == nil {
afsOrder.JxStoreID = order.JxStoreID
afsOrder.VendorStoreID = order.VendorStoreID
afsOrder.StoreID = order.StoreID
} else {
globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
err = nil
}
for _, sku := range orderFinancial.Skus {
orderSkuFinancial := &model.OrderSkuFinancial{
VendorID: sku.VendorID,
VendorOrderID: sku.VendorOrderID,
VendorOrderID2: sku.VendorOrderID2,
AfsOrderID: sku.VendorOrderID,
// ConfirmTime: afsOrder.AfsCreateAt,
VendorStoreID: afsOrder.VendorStoreID,
StoreID: afsOrder.StoreID,
JxStoreID: afsOrder.JxStoreID,
VendorSkuID: sku.VendorSkuID,
SkuID: sku.SkuID,
PromotionType: sku.PromotionType,
Name: sku.Name,
ShopPrice: sku.ShopPrice,
SalePrice: sku.SalePrice,
Count: sku.Count,
SkuBoxMoney: sku.SkuBoxMoney,
UserMoney: sku.UserMoney,
PmSubsidyMoney: sku.PmSubsidyMoney,
IsAfsOrder: 1,
}
afsOrder.Skus = append(afsOrder.Skus, orderSkuFinancial)
}
return afsOrder
}
func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interface{}) (afsOrder *model.AfsOrder) {
afsOrder = &model.AfsOrder{
VendorID: model.VendorIDEBAI,
AfsOrderID: utils.Interface2String(orderData["order_id"]),
VendorOrderID: utils.Interface2String(orderData["order_id"]),
}
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
if err == nil {
@@ -47,21 +111,24 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
refundDetail := orderData["refund_detail"].([]interface{})
for _, refundInfo := range refundDetail {
xMap := refundInfo.(map[string]interface{})
orderSku := &model.AfterSalesOrderSku{
VendorID: model.VendorIDEBAI,
AfterSalesOrderID: afsOrder.AfterSalesOrderID,
VendorOrderID: afsOrder.VendorOrderID,
ConfirmTime: getTimeFromInterface(xMap["apply_time"]),
VendorSkuID: utils.Interface2String(xMap["sku_id"]),
SkuID: int(utils.Str2Int64(utils.Interface2String(xMap["custom_sku_id"]))),
Name: utils.Interface2String(xMap["name"]),
SkuUserMoney: utils.MustInterface2Int64(xMap["total_refund"]),
SkuVendorMoney: utils.MustInterface2Int64(xMap["shop_ele_refund"]),
orderSkuFinancial := &model.OrderSkuFinancial{
VendorID: model.VendorIDEBAI,
AfsOrderID: afsOrder.AfsOrderID,
VendorOrderID: afsOrder.VendorOrderID,
// ConfirmTime: getTimeFromInterface(xMap["apply_time"]),
VendorSkuID: utils.Interface2String(xMap["sku_id"]),
SkuID: int(utils.Str2Int64(utils.Interface2String(xMap["custom_sku_id"]))),
Name: utils.Interface2String(xMap["name"]),
UserMoney: utils.MustInterface2Int64(xMap["total_refund"]),
PmSubsidyMoney: utils.MustInterface2Int64(xMap["shop_ele_refund"]),
IsAfsOrder: 1,
}
afsOrder.Skus = append(afsOrder.Skus, orderSku)
afsOrder.Skus = append(afsOrder.Skus, orderSkuFinancial)
afsOrder.SkuUserMoney += orderSkuFinancial.UserMoney
afsOrder.PmSubsidyMoney += orderSkuFinancial.PmSubsidyMoney
}
if len(refundDetail) > 0 {
afsOrder.ConfirmTime = afsOrder.Skus[0].ConfirmTime
afsOrder.AfsCreateAt = getTimeFromInterface(refundDetail[0].(map[string]interface{})["apply_time"])
} else {
globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
}
@@ -72,38 +139,48 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
}
// 存储饿百正向订单结账信息
func (p *PurchaseHandler) OnOrderDetail(result map[string]interface{}) (err error) {
err = orderman.SaveOrderFinancialInfo(p.OrderDetail2Financial(result))
func (p *PurchaseHandler) OnOrderDetail(result map[string]interface{}, operation string) (err error) {
err = partner.CurOrderManager.SaveOrderFinancialInfo(p.OrderDetail2Financial(result), operation)
return err
}
func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (orderDetail *model.OrderFinancial) {
orderDetail = &model.OrderFinancial{
func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (orderFinancial *model.OrderFinancial) {
orderFinancial = &model.OrderFinancial{
VendorID: model.VendorIDEBAI,
}
order1 := result["order"].(map[string]interface{})
orderDetail.VendorOrderID = utils.Interface2String(order1["order_id"])
orderDetail.VendorOrderID2 = utils.Interface2String(order1["eleme_order_id"])
orderDetail.DeliveryConfirmTime = getTimeFromInterface(order1["finished_time"])
orderDetail.TotalDiscountMoney = utils.MustInterface2Int64(order1["discount_fee"])
orderDetail.ReceivableFreight = utils.MustInterface2Int64(order1["send_fee"])
orderFinancial.VendorOrderID = utils.Interface2String(order1["order_id"])
orderFinancial.VendorOrderID2 = utils.Interface2String(order1["eleme_order_id"])
// orderFinancial.DeliveryConfirmTime = getTimeFromInterface(order1["finished_time"])
orderFinancial.TotalDiscountMoney = utils.MustInterface2Int64(order1["discount_fee"])
orderFinancial.ReceivableFreight = utils.MustInterface2Int64(order1["send_fee"])
if int(utils.MustInterface2Int64(order1["send_immediately"])) == ebaiapi.SendImmediatelySelf {
orderDetail.SelfDeliveryDiscountMoney = orderDetail.ReceivableFreight
orderFinancial.SelfDeliveryDiscountMoney = orderFinancial.ReceivableFreight
orderFinancial.DistanceFreightMoney = 0
// 通过本地数据库去取是否转美团/达达,并计算运费
// wayBill, err := partner.CurOrderManager.LoadWaybill(orderFinancial.VendorOrderID, orderFinancial.VendorID)
// if err == nil {
// orderFinancial.JxFreightMoney = wayBill.DesiredFee
// }
}
orderDetail.BoxMoney = utils.MustInterface2Int64(order1["package_fee"])
orderDetail.ActualPayMoney = utils.MustInterface2Int64(order1["user_fee"])
orderDetail.PmMoney = utils.MustInterface2Int64(order1["commission"])
orderDetail.ShopMoney = utils.MustInterface2Int64(order1["shop_fee"])
order, err := partner.CurOrderManager.LoadOrder(orderDetail.VendorOrderID, orderDetail.VendorID)
orderFinancial.BoxMoney = utils.MustInterface2Int64(order1["package_fee"])
orderFinancial.ActualPayMoney = utils.MustInterface2Int64(order1["user_fee"])
orderFinancial.PmMoney = utils.MustInterface2Int64(order1["commission"])
orderFinancial.ShopMoney = utils.MustInterface2Int64(order1["shop_fee"])
order, err := partner.CurOrderManager.LoadOrder(orderFinancial.VendorOrderID, orderFinancial.VendorID)
storeID := 0
jxStoreID := 0
if err == nil {
storeID = order.StoreID
jxStoreID = order.JxStoreID
skus := order.Skus
if skus != nil {
for _, x := range skus {
orderDetail.ShopPriceMoney += x.ShopPrice
orderFinancial.ShopPriceMoney += x.ShopPrice * int64(x.Count)
}
}
} else {
globals.SugarLogger.Warnf("ebai OrderDetail2Financial, 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", orderFinancial.VendorOrderID)
err = nil
}
if result["products"] != nil {
@@ -111,7 +188,27 @@ func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (
for _, x := range products {
for _, y := range x.([]interface{}) {
product := y.(map[string]interface{})
orderDetail.SalePriceMoney += utils.MustInterface2Int64(product["product_price"]) * utils.MustInterface2Int64(product["product_amount"])
orderSkuFinancial := &model.OrderSkuFinancial{
VendorID: orderFinancial.VendorID,
VendorOrderID: orderFinancial.VendorOrderID,
VendorOrderID2: orderFinancial.VendorOrderID2,
// OrderFinancialID: orderFinancial.VendorOrderID,
// ConfirmTime: getTimeFromInterface(order1["create_time"]),
VendorStoreID: result["app_poi_code"].(string),
StoreID: storeID,
JxStoreID: jxStoreID,
VendorSkuID: utils.Interface2String(product["baidu_product_id"]),
SkuID: int(utils.Str2Int64(utils.Interface2String(product["custom_sku_id"]))),
Name: utils.Interface2String(product["product_name"]),
SalePrice: utils.MustInterface2Int64(product["product_price"]),
Count: int(utils.MustInterface2Int64(product["product_amount"])),
SkuBoxMoney: utils.MustInterface2Int64(product["package_fee"]),
IsAfsOrder: 0,
}
orderFinancial.Skus = append(orderFinancial.Skus, orderSkuFinancial)
orderFinancial.SalePriceMoney += orderSkuFinancial.SalePrice * int64(orderSkuFinancial.Count)
orderFinancial.SkuBoxMoney += orderSkuFinancial.SkuBoxMoney
orderFinancial.BoxMoney -= orderSkuFinancial.SkuBoxMoney
}
}
}
@@ -119,9 +216,21 @@ func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (
discount := result["discount"].([]interface{})
for _, x := range discount {
xMap := x.(map[string]interface{})
orderDetail.DiscountMoney += utils.MustInterface2Int64(xMap["fee"])
orderDetail.PmSubsidyMoney += utils.MustInterface2Int64(xMap["baidu_rate"]) // 平台承担补贴
discountPrice := utils.MustInterface2Int64(xMap["fee"])
orderFinancial.DiscountMoney += discountPrice
orderFinancial.PmSubsidyMoney += utils.MustInterface2Int64(xMap["baidu_rate"]) // 平台承担补贴
activity := &model.OrderDiscountFinancial{
VendorID: orderFinancial.VendorID,
VendorOrderID: orderFinancial.VendorOrderID,
// ActivityName: utils.Interface2String(xMap["desc"]),
// ActivityMoney: discountPrice,
VendorActivityID: utils.Interface2String(xMap["activity_id"]),
}
orderFinancial.Discounts = append(orderFinancial.Discounts, activity)
// 通过活动Id去取京西活动补贴
// orderFinancial.JxSubsidyMoney +=
}
}
return orderDetail
orderFinancial.FreightDiscountMoney = orderFinancial.TotalDiscountMoney - orderFinancial.DiscountMoney
return orderFinancial
}