Merge remote-tracking branch 'origin/lcw' into mark

This commit is contained in:
gazebo
2019-04-10 09:28:14 +08:00
17 changed files with 1060 additions and 235 deletions

View File

@@ -16,6 +16,11 @@ const (
StoreNameSeparator = "-"
)
const (
CreatedPeration = "create"
UpdatedPeration = "update"
)
const (
CancelWaybillReasonNotAcceptIntime = 1
CancelWaybillReasonSwitch2SelfFailed = 2
@@ -105,11 +110,17 @@ type IOrderManager interface {
LoadOrder(vendorOrderID string, vendorID int) (order *model.GoodsOrder, err error)
LoadOrder2(vendorOrderID2 string, vendorID int) (order *model.GoodsOrder, err error)
LoadOrderFinancial(vendorOrderID string, vendorID int) (order *model.OrderFinancial, err error)
LoadOrderFinancial2(vendorOrderID2 string, vendorID int) (order *model.OrderFinancial, err error)
UpdateWaybillVendorID(bill *model.Waybill, revertStatus bool) (err error)
UpdateOrderStatusAndFlag(order *model.GoodsOrder) (err error)
LoadWaybill(vendorWaybillID string, waybillVendorID int) (bill *model.Waybill, err error)
OnOrderComments(orderCommentList []*model.OrderComment) (err error)
SaveOrderFinancialInfo(order *model.OrderFinancial, operation string) (err error)
SaveAfsOrderFinancialInfo(afsOrder *model.AfsOrder) (err error)
}
// purchase handler中

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,24 +16,95 @@ 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 { // 全额退款处理
messageType := utils.Int64ToStr(utils.MustInterface2Int64(msg.Body["type"]))
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去本地数据库拿饿百消息推送只给了订单号但是没有查询全额退款的接口只有部分退款才可以查询
globals.SugarLogger.Debug(utils.Interface2String(msg.Body["order_id"])) // 获得退款订单ID去本地数据库拿饿百消息推送只给了订单号但是没有查询全额退款的接口只有部分退款才可以查询
afsOrderID := utils.Interface2String(msg.Body["order_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 utils.Int64ToStr(utils.MustInterface2Int64(msg.Body["status"])) == 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["order_id"]),
VendorOrderID: utils.Interface2String(msg.Body["order_id"]),
AfsCreateAt: utils.Timestamp2Time(msg.Timestamp),
// BoxMoney: orderFinancial.BoxMoney, // 饿百的餐盒费已经拆分到单条Sku里面退款时直接计算用户支付sku金额就好了
// SkuBoxMoney: orderFinancial.SkuBoxMoney,
FreightUserMoney: orderFinancial.FreightMoney,
SkuUserMoney: orderFinancial.ActualPayMoney - orderFinancial.FreightMoney,
PmSubsidyMoney: orderFinancial.PmSubsidyMoney,
}
// if msg.Body["timestamp"] != nil {
// afsOrder.AfsCreateAt = utils.Timestamp2Time(utils.Str2Int64(utils.Interface2String(msg.Body["timestamp"])))
// } else {
// globals.SugarLogger.Warnf("ebai OrderFinancialDetail2Refund timestamp is not found in afsOrder:%s", afsOrder.AfsOrderID)
// afsOrder.AfsCreateAt = time.Now()
// }
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 +117,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.Str2Int64WithDefault(utils.Interface2String(xMap["custom_sku_id"]), 0)),
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,46 +145,78 @@ 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"])
if int(utils.MustInterface2Int64(order1["send_immediately"])) == ebaiapi.SendImmediatelySelf {
orderDetail.SelfDeliveryDiscountMoney = orderDetail.ReceivableFreight
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(getInt64FromInterface(order1["delivery_party"])) == ebaiapi.SendImmediatelySelf {
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
}
shop := result["shop"].(map[string]interface{})
if result["products"] != nil {
products := result["products"].([]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: utils.Interface2String(shop["baidu_shop_id"]),
StoreID: storeID,
JxStoreID: jxStoreID,
VendorSkuID: utils.Interface2String(product["baidu_product_id"]),
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["custom_sku_id"]), 0)),
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 +224,31 @@ 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
}
func getInt64FromInterface(strOrNum interface{}) int64 {
var resultNum int64
if resultStr, ok := strOrNum.(string); ok {
resultNum = utils.Str2Int64WithDefault(resultStr, 0)
} else {
resultNum = utils.Interface2Int64WithDefault(strOrNum, 0)
}
return resultNum
}

View File

@@ -1,19 +1,26 @@
package ebai
import (
"encoding/json"
"fmt"
"testing"
"time"
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
"git.rosy.net.cn/baseapi/utils"
)
func TestOnFinancialMsg(t *testing.T) {
msg := &ebaiapi.CallbackMsg{
Cmd: "order.partrefund.push",
// Cmd: "order.partrefund.push",
Cmd: "order.user.cancel",
Body: make(map[string]interface{}),
}
msg.Body["refund_id"] = "15518443822344"
msg.Body["status"] = "20"
msg.Body["refund_id"] = "15531567190216"
msg.Body["timestamp"] = utils.Int64ToStr(time.Now().Unix())
// msg.Body["status"] = json.Number("20")
msg.Body["type"] = json.Number("40")
msg.Body["cancel_type"] = json.Number("2")
res := OnFinancialMsg(msg)
fmt.Println(res)
}

View File

@@ -241,7 +241,7 @@ func (c *PurchaseHandler) onOrderNew(msg *ebaiapi.CallbackMsg) (response *ebaiap
if err == nil {
if err = partner.CurOrderManager.OnOrderNew(order, order.VendorStatus); err == nil {
utils.CallFuncAsync(func() {
c.OnOrderDetail(orderMap)
c.OnOrderDetail(orderMap, partner.CreatedPeration)
})
}
}

View File

@@ -3,7 +3,6 @@ package jd
import (
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"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"
@@ -13,14 +12,18 @@ import (
// 京东正向/退款订单类型处理--存储
func OnFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
var err error
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle || msg.StatusID == jdapi.OrderStatusAdjustSettle || msg.StatusID == jdapi.OrderStatusSwitch2SelfSettle { // 如果是正向单
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle || msg.StatusID == jdapi.OrderStatusTipChanged || 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)
if err = err2; err == nil {
orderFinancial, err2 := curPurchaseHandler.OrderDetail2Financial(orderData, false, order)
if err = err2; err == nil {
err = orderman.SaveOrderFinancialInfo(orderFinancial)
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle {
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, partner.CreatedPeration)
} else {
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, partner.UpdatedPeration)
}
}
}
} else {
@@ -29,7 +32,7 @@ func OnFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse
} else if msg.StatusID == jdapi.SaleBillStatusRefundSuccess || msg.StatusID == jdapi.SaleBillStatusSaleReturnSuccess { // 如果是退款单
orderData, err2 := api.JdAPI.GetAfsService(msg.BillID)
if err = err2; err == nil {
err = orderman.SaveAfsOrderFinancialInfo(curPurchaseHandler.AfsOrderDetail2Financial(orderData))
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(curPurchaseHandler.AfsOrderDetail2Financial(orderData))
}
}
return jdapi.Err2CallbackResponse(err, "jd OnFinancialMsg")
@@ -46,25 +49,60 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
DiscountMoney: utils.MustInterface2Int64(orderData["orderDiscountMoney"]),
DistanceFreightMoney: utils.MustInterface2Int64(orderData["merchantPaymentDistanceFreightMoney"]),
FreightTipsMoney: utils.MustInterface2Int64(orderData["tips"]),
// BoxFee: utils.MustInterface2Int64(orderData["packagingMoney"]), // 京东包装(塑料袋)由京东提供,相应钱款也归京东,不记录/记录之后优化算法
PointsDeductionMoney: utils.MustInterface2Int64(orderData["platformPointsDeductionMoney"]),
// BoxMoney: utils.MustInterface2Int64(orderData["packagingMoney"]), // 京东包装(塑料袋)由京东提供,相应钱款也归京东,不记录/记录之后优化算法
}
skus := order.Skus
if skus != nil {
for _, x := range skus {
orderFinancial.ShopPriceMoney += x.ShopPrice
orderFinancial.ShopPriceMoney += x.ShopPrice * int64(x.Count)
}
}
if orderData["product"] != nil {
product := orderData["product"].([]interface{})
for _, x := range product {
xMap := x.(map[string]interface{})
orderFinancial.SalePriceMoney += utils.MustInterface2Int64(xMap["skuJdPrice"]) * utils.MustInterface2Int64(xMap["skuCount"])
orderSkuFinancial := &model.OrderSkuFinancial{
VendorID: orderFinancial.VendorID,
VendorOrderID: orderFinancial.VendorOrderID,
// OrderFinancialID: orderFinancial.VendorOrderID,
// ConfirmTime: utils.Str2Time(utils.Interface2String(orderData["orderStartTime"])),
VendorStoreID: utils.Interface2String(orderData["deliveryStationNo"]),
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(orderData["deliveryStationNoIsv"]), 0)),
JxStoreID: order.JxStoreID,
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(xMap["skuId"])),
// SkuID: int(utils.Str2Int64(utils.Interface2String(xMap["skuIdIsv"]))),
PromotionType: int(utils.MustInterface2Int64(xMap["promotionType"])),
Name: utils.Interface2String(xMap["skuName"]),
ShopPrice: utils.MustInterface2Int64(xMap["skuStorePrice"]),
SalePrice: utils.MustInterface2Int64(xMap["skuJdPrice"]),
Count: int(utils.MustInterface2Int64(xMap["skuCount"])),
IsAfsOrder: 0,
// MealBoxMoney: utils.MustInterface2Int64(xMap["canteenMoney"]), // 京东的目前不考虑结算餐盒费,因为都归京东所有
}
// PromotionType 是一个关键数据可能某商品活动限购用户超出限购数量超出部分不享受优惠那么除了要在活动表根据skuId,活动起止日期活动城市来查询还需要判断活动类型PromotionType
// 平台/京西单条sku补贴金额应该去京西后台活动库去取活动里针对单条SKU如果京东/京西有补贴,应该有记录
// orderSkuFinancial.PmSubsidyMoneyForSku =
// orderSkuFinancial.JxSubsidyMoneyForSku =
// orderFinancial.JxSubsidyMoneyToSku += orderSkuFinancial.JxSubsidyMoneyForSku
// orderFinancial.JxSubsidyMoney += orderSkuFinancial.JxSubsidyMoneyForSku
orderFinancial.SalePriceMoney += orderSkuFinancial.SalePrice * int64(orderSkuFinancial.Count)
orderSkuFinancial.SkuID = int(utils.Str2Int64WithDefault(utils.Interface2String(xMap["skuIdIsv"]), 0))
orderFinancial.Skus = append(orderFinancial.Skus, orderSkuFinancial)
}
}
orderFinancial.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 {
// 如果为自配送,自配送补贴=订单初始运费,远距离费=0
orderFinancial.SelfDeliveryDiscountMoney = utils.MustInterface2Int64(orderData["orderReceivableFreight"])
orderFinancial.DistanceFreightMoney = 0
// 通过本地数据库去取是否转美团/达达,并计算运费
// wayBill, err2 := partner.CurOrderManager.LoadWaybill(orderFinancial.VendorOrderID, orderFinancial.VendorID)
// if err = err2; err == nil {
// orderFinancial.JxFreightMoney = wayBill.DesiredFee
// }
}
if orderData["discount"] != nil {
discount := orderData["discount"].([]interface{})
@@ -74,12 +112,33 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
discountType := int(utils.MustInterface2Int64(xMap["discountType"]))
if discountType == jdapi.FreightDiscountTypeByShop {
orderFinancial.FreightDiscountMoney = discountPrice
}
if discountType == jdapi.FreightDiscountTypeByVip || discountType == jdapi.FreightDiscountTypeByActivity || discountType == jdapi.FreightDiscountTypeByCoupons {
orderFinancial.VendorFreightDiscountMoney = discountPrice
} else if discountType == jdapi.FreightDiscountTypeByVip || discountType == jdapi.FreightDiscountTypeByActivity {
orderFinancial.PmFreightDiscountMoney = discountPrice
} else if discountType == jdapi.FreightDiscountTypeByCoupons {
if xMap["platPayMoney"] == nil {
orderFinancial.PmFreightDiscountMoney = discountPrice
} else {
orderFinancial.PmFreightDiscountMoney = int64(utils.MustInterface2Float64(xMap["platPayMoney"]))
orderFinancial.FreightDiscountMoney = discountPrice - orderFinancial.PmFreightDiscountMoney
}
}
orderFinancial.TotalDiscountMoney += discountPrice
if xMap["orderShareRatioData"] != nil {
orderShareRatioData, _ := utils.HTTPBody2Values([]byte(utils.Interface2String(xMap["orderShareRatioData"])), false)
activity := &model.OrderDiscountFinancial{
VendorID: orderFinancial.VendorID,
VendorOrderID: orderFinancial.VendorOrderID,
// ActivityName: utils.Interface2String(xMap["discountName"]),
// ActivityMoney: discountPrice,
VendorActivityID: utils.Interface2String(orderShareRatioData["promotionId"][0]),
// Remark: utils.Interface2String(xMap["orderShareRatioData"]),
}
orderFinancial.Discounts = append(orderFinancial.Discounts, activity)
// 通过活动Id去取京西活动补贴
// orderFinancial.JxSubsidyMoney +=
}
}
globals.SugarLogger.Debug(utils.Format4Output(orderFinancial.Discounts, false))
}
order1, err2 := api.JdAPI.OrderShoudSettlementService(orderFinancial.VendorOrderID)
if err = err2; err == nil {
@@ -88,8 +147,8 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["freightCommission"], 0)
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["packageCommission"], 0)
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["guaranteedCommission"], 0)
orderFinancial.PmSubsidyMoney += utils.Interface2Int64WithDefault(order1["platOrderGoodsDiscountMoney"], 0)
orderFinancial.PmSubsidyMoney += utils.Interface2Int64WithDefault(order1["platSkuGoodsDiscountMoney"], 0)
orderFinancial.PmSkuSubsidyMoney = utils.Interface2Int64WithDefault(order1["platSkuGoodsDiscountMoney"], 0)
orderFinancial.PmSubsidyMoney = utils.Interface2Int64WithDefault(order1["platOrderGoodsDiscountMoney"], 0) + orderFinancial.PmSkuSubsidyMoney
} else {
if !isFromOrderDetail {
globals.SugarLogger.Warnf("jd OrderDetail2Financial, orderID:%s is not found from api.JdAPI.OrderShoudSettlementService", orderFinancial.VendorOrderID)
@@ -99,19 +158,19 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
}
// 处理京东售后订单结账信息
func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interface{}) (afsOrder *model.AfterSalesOrder) {
afsOrder = &model.AfterSalesOrder{
func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interface{}) (afsOrder *model.AfsOrder) {
afsOrder = &model.AfsOrder{
VendorID: model.VendorIDJD,
AfterSalesOrderID: utils.Interface2String(orderData["afsServiceOrder"]),
AfsOrderID: utils.Interface2String(orderData["afsServiceOrder"]),
VendorOrderID: utils.Interface2String(orderData["orderId"]),
VendorStoreID: utils.Interface2String(orderData["stationId"]),
StoreID: int(utils.Str2Int64(utils.Interface2String(orderData["stationNumOutSystem"]))),
ConfirmTime: utils.Timestamp2Time(utils.MustInterface2Int64(orderData["updateTime"].(map[string]interface{})["time"]) / 1000),
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(orderData["stationNumOutSystem"]), 0)),
AfsCreateAt: utils.Timestamp2Time(utils.MustInterface2Int64(orderData["updateTime"].(map[string]interface{})["time"]) / 1000),
FreightUserMoney: utils.MustInterface2Int64(orderData["orderFreightMoney"]),
AfsFreightMoney: utils.MustInterface2Int64(orderData["afsFreight"]),
BoxMoney: utils.MustInterface2Int64(orderData["packagingMoney"]),
TongchengFreightMoney: utils.MustInterface2Int64(orderData["tongchengFreightMoney"]),
MealBoxMoney: utils.MustInterface2Int64(orderData["mealBoxMoney"]),
SkuBoxMoney: utils.MustInterface2Int64(orderData["mealBoxMoney"]),
}
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
if err == nil {
@@ -123,24 +182,32 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
refundDetail := orderData["afsDetailList"].([]interface{})
for _, x := range refundDetail {
xMap := x.(map[string]interface{})
orderSku := &model.AfterSalesOrderSku{
VendorID: model.VendorIDJD,
AfterSalesOrderID: afsOrder.AfterSalesOrderID,
VendorOrderID: afsOrder.VendorOrderID,
VendorStoreID: afsOrder.VendorStoreID,
StoreID: afsOrder.StoreID,
ConfirmTime: afsOrder.ConfirmTime,
orderSku := &model.OrderSkuFinancial{
VendorID: model.VendorIDJD,
AfsOrderID: afsOrder.AfsOrderID,
VendorOrderID: afsOrder.VendorOrderID,
VendorStoreID: afsOrder.VendorStoreID,
StoreID: afsOrder.StoreID,
// ConfirmTime: afsOrder.AfsCreateAt,
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(xMap["wareId"])),
SkuID: int(utils.Str2Int64(utils.Interface2String(xMap["skuIdIsv"]))),
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(xMap["skuIdIsv"]), 0)),
Name: utils.Interface2String(xMap["wareName"]),
SkuUserMoney: utils.MustInterface2Int64(xMap["afsMoney"]),
UserMoney: utils.MustInterface2Int64(xMap["afsMoney"]),
PmSkuSubsidyMoney: utils.MustInterface2Int64(xMap["platPayMoney"]),
IsAfsOrder: 1,
}
afsOrder.PmSkuSubsidyMoney += orderSku.PmSkuSubsidyMoney
orderSku.PmSubsidyMoney += orderSku.PmSkuSubsidyMoney
if xMap["afsSkuDiscountList"] != nil {
afsSkuDiscountList := xMap["afsSkuDiscountList"].([]interface{})
for _, y := range afsSkuDiscountList {
orderSku.SkuVendorMoney += utils.MustInterface2Int64(y.(map[string]interface{})["platPayMoney"])
orderSku.PmSubsidyMoney += utils.MustInterface2Int64(y.(map[string]interface{})["platPayMoney"])
}
}
afsOrder.SkuUserMoney += orderSku.UserMoney
afsOrder.PmSubsidyMoney += orderSku.PmSubsidyMoney
afsOrder.Skus = append(afsOrder.Skus, orderSku)
}
if len(refundDetail) <= 0 {
@@ -157,7 +224,7 @@ func (p *PurchaseHandler) OnOrderDetail(orderDetail map[string]interface{}) (err
if err == nil {
orderFinancial, err2 := curPurchaseHandler.OrderDetail2Financial(orderDetail, true, order)
if err = err2; err == nil {
err = orderman.SaveOrderFinancialInfo(orderFinancial)
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, partner.CreatedPeration)
}
}
return err

View File

@@ -9,8 +9,8 @@ import (
func TestOnFinancialMsg(t *testing.T) {
msg := &jdapi.CallbackOrderMsg{
BillID: "817102100000041",
StatusID: "330901",
BillID: "907315020000322",
StatusID: "330902",
}
res := OnFinancialMsg(msg)
fmt.Println(res)

View File

@@ -5,39 +5,104 @@ import (
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
)
const (
PublicWelfareDonation = 1 // 美团公益捐款金额现阶段是每单一分钱
)
// 存储美团退款订单结账信息
func OnFinancialMsg(msg *mtwmapi.CallbackMsg) (err error) {
if msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund { // 部分退款处理
orderData := msg.Data
if orderData.Get("notify_type") == mtwmapi.NotifyTypeSuccess {
err = orderman.SaveAfsOrderFinancialInfo(curPurchaseHandler.AfsOrderDetail2Financial(orderData))
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(curPurchaseHandler.AfsOrderDetail2Financial(orderData))
}
}
if msg.Cmd == mtwmapi.MsgTypeOrderRefund { // todo 全额退款处理
orderData := msg.Data
if orderData.Get("notify_type") == mtwmapi.NotifyTypeSuccess {
globals.SugarLogger.Debug(orderData.Get("order_id")) // 获得退款订单ID去本地数据库拿饿百消息推送只给了订单号也没有通过订单号查询退款信息的接口
afsOrderID := orderData.Get("order_id")
orderFinancial, err := partner.CurOrderManager.LoadOrderFinancial(afsOrderID, model.VendorIDMTWM)
if err == nil {
globals.SugarLogger.Debug(utils.Format4Output(orderFinancial, false))
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(curPurchaseHandler.OrderFinancialDetail2Refund(orderFinancial, orderData))
} else {
globals.SugarLogger.Warnf("mtwm OnFinancialMsg, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrderFinancial", afsOrderID)
}
}
}
return err
}
func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData url.Values) (afsOrder *model.AfterSalesOrder) {
afsOrder = &model.AfterSalesOrder{
VendorID: model.VendorIDMTWM,
AfterSalesOrderID: orderData.Get("order_id"),
VendorOrderID: orderData.Get("order_id"),
ConfirmTime: utils.Timestamp2Time(utils.Str2Int64(orderData.Get("timestamp"))),
RefundMoney: jxutils.StandardPrice2Int(utils.Str2Float64(orderData.Get("money"))),
func (p *PurchaseHandler) OrderFinancialDetail2Refund(orderFinancial *model.OrderFinancial, orderData url.Values) (afsOrder *model.AfsOrder) {
afsOrder = &model.AfsOrder{
VendorID: model.VendorIDMTWM,
AfsOrderID: orderData.Get("order_id"),
VendorOrderID: orderData.Get("order_id"),
AfsCreateAt: utils.Timestamp2Time(utils.Str2Int64(orderData.Get("timestamp"))),
// BoxMoney: orderFinancial.BoxMoney,
// SkuBoxMoney: orderFinancial.SkuBoxMoney, // 美团的餐盒费已经拆到单条SKU里面去了,退款时直接计算用户支付sku金额就好了
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("mtwm 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,
// OrderFinancialID: 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,
UserMoney: sku.UserMoney,
PmSubsidyMoney: sku.PmSubsidyMoney,
IsAfsOrder: 1,
}
afsOrder.Skus = append(afsOrder.Skus, orderSkuFinancial)
}
return afsOrder
}
func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData url.Values) (afsOrder *model.AfsOrder) {
afsOrder = &model.AfsOrder{
VendorID: model.VendorIDMTWM,
AfsOrderID: orderData.Get("order_id"),
VendorOrderID: orderData.Get("order_id"),
AfsCreateAt: utils.Timestamp2Time(utils.Str2Int64(orderData.Get("timestamp"))),
RefundMoney: jxutils.StandardPrice2Int(utils.Str2Float64(orderData.Get("money"))),
}
// if orderData.Get("timestamp") != "" {
// afsOrder.AfsCreateAt = utils.Timestamp2Time(utils.Str2Int64(orderData.Get("timestamp")))
// } else {
// globals.SugarLogger.Warnf("ebai OrderFinancialDetail2Refund timestamp is not found in afsOrder:%s", afsOrder.AfsOrderID)
// afsOrder.AfsCreateAt = time.Now()
// }
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
if err == nil {
afsOrder.JxStoreID = order.JxStoreID
} else {
@@ -48,18 +113,22 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData url.Values) (afsOrd
var refundDetail []map[string]interface{}
utils.UnmarshalUseNumber([]byte(food), &refundDetail)
for _, xMap := range refundDetail {
orderSku := &model.AfterSalesOrderSku{
VendorID: model.VendorIDMTWM,
AfterSalesOrderID: afsOrder.AfterSalesOrderID,
VendorOrderID: afsOrder.VendorOrderID,
ConfirmTime: afsOrder.ConfirmTime,
VendorSkuID: utils.Interface2String(xMap["app_food_code"]),
SkuID: int(utils.Str2Int64(utils.Interface2String(xMap["sku_id"]))),
Name: utils.Interface2String(xMap["food_name"]),
SkuUserMoney: jxutils.StandardPrice2Int(utils.MustInterface2Float64(xMap["refund_price"]))*utils.MustInterface2Int64(xMap["count"]) + jxutils.StandardPrice2Int(utils.MustInterface2Float64(xMap["box_price"]))*int64(utils.MustInterface2Float64(xMap["box_num"])),
orderSkuFinancial := &model.OrderSkuFinancial{
VendorID: model.VendorIDMTWM,
AfsOrderID: afsOrder.AfsOrderID,
VendorOrderID: afsOrder.VendorOrderID,
// ConfirmTime: afsOrder.AfsCreateAt,
VendorSkuID: utils.Interface2String(xMap["app_food_code"]),
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(xMap["sku_id"]), 0)),
Name: utils.Interface2String(xMap["food_name"]),
UserMoney: jxutils.StandardPrice2Int(utils.MustInterface2Float64(xMap["refund_price"]))*utils.MustInterface2Int64(xMap["count"]) + jxutils.StandardPrice2Int(utils.MustInterface2Float64(xMap["box_price"]))*int64(utils.MustInterface2Float64(xMap["box_num"])),
IsAfsOrder: 1,
}
afsOrder.Skus = append(afsOrder.Skus, orderSku)
afsOrder.Skus = append(afsOrder.Skus, orderSkuFinancial)
afsOrder.SkuUserMoney += orderSkuFinancial.UserMoney
// afsOrder.PmSubsidyMoney += orderSkuFinancial.PmSubsidyMoney // 美团只给了一个扣款金额,很尴尬、、
}
afsOrder.PmSubsidyMoney += afsOrder.RefundMoney - afsOrder.SkuUserMoney
if len(refundDetail) <= 0 {
globals.SugarLogger.Warnf("mtwm AfsOrderDetail2Financial, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
}
@@ -67,57 +136,116 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData url.Values) (afsOrd
}
// 存储美团正向订单结账信息
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.VendorIDMTWM,
VendorOrderID: utils.Int64ToStr(utils.MustInterface2Int64(result["order_id"])),
}
orderDetail.DeliveryConfirmTime = utils.Str2TimeWithDefault(utils.Interface2String(result["order_completed_time"]), utils.DefaultTimeValue)
order, err := partner.CurOrderManager.LoadOrder(orderDetail.VendorOrderID, orderDetail.VendorID)
// orderFinancial.DeliveryConfirmTime = utils.Str2TimeWithDefault(utils.Interface2String(result["order_completed_time"]), utils.DefaultTimeValue)
order, err := partner.CurOrderManager.LoadOrder(orderFinancial.VendorOrderID, orderFinancial.VendorID)
jxStoreID := 0
if err == nil {
jxStoreID = order.JxStoreID
if order.Skus != nil {
for _, x := range order.Skus {
orderDetail.ShopPriceMoney += x.ShopPrice
orderFinancial.ShopPriceMoney += x.ShopPrice * int64(x.Count)
}
}
} else {
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s is not found from partner.CurOrderManager.LoadOrder", orderDetail.VendorOrderID)
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s is not found from partner.CurOrderManager.LoadOrder", orderFinancial.VendorOrderID)
err = nil
}
if result["package_bag_money"] != nil {
orderFinancial.BoxMoney = utils.MustInterface2Int64(result["package_bag_money"])
}
detail := result["detail"]
if detail != nil {
var data []map[string]interface{}
utils.UnmarshalUseNumber([]byte(utils.Interface2String(detail)), &data)
for _, x := range data {
orderDetail.SalePriceMoney += jxutils.StandardPrice2Int(utils.MustInterface2Float64(x["price"])) * utils.MustInterface2Int64(x["quantity"])
orderDetail.BoxMoney += jxutils.StandardPrice2Int(utils.MustInterface2Float64(x["box_price"])) * utils.MustInterface2Int64(x["box_num"])
orderSkuFinancial := &model.OrderSkuFinancial{
VendorID: orderFinancial.VendorID,
VendorOrderID: orderFinancial.VendorOrderID,
// OrderFinancialID: orderFinancial.VendorOrderID,
// ConfirmTime: utils.Str2TimeWithDefault(utils.Interface2String(result["ctime"]), utils.DefaultTimeValue),
VendorStoreID: result["app_poi_code"].(string),
StoreID: 0,
JxStoreID: jxStoreID,
VendorSkuID: utils.Interface2String(x["sku_id"]),
Name: utils.Interface2String(x["food_name"]),
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(x["price"])),
Count: int(utils.MustInterface2Int64(x["quantity"])),
SkuBoxMoney: jxutils.StandardPrice2Int(utils.MustInterface2Float64(x["box_price"])) * utils.MustInterface2Int64(x["box_num"]),
IsAfsOrder: 0,
}
orderFinancial.Skus = append(orderFinancial.Skus, orderSkuFinancial)
orderFinancial.SalePriceMoney += orderSkuFinancial.SalePrice * int64(orderSkuFinancial.Count)
orderFinancial.SkuBoxMoney += orderSkuFinancial.SkuBoxMoney
}
} else {
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s have no detail", orderDetail.VendorOrderID)
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s have no detail", orderFinancial.VendorOrderID)
}
extras := result["extras"]
if extras != nil {
var data []map[string]interface{}
utils.UnmarshalUseNumber([]byte(utils.Interface2String(extras)), &data)
for _, x := range data {
if x["rider_fee"] == nil {
activity := &model.OrderDiscountFinancial{
VendorID: orderFinancial.VendorID,
VendorOrderID: orderFinancial.VendorOrderID,
// ActivityName: utils.Interface2String(x["remark"]),
// ActivityMoney: jxutils.StandardPrice2Int(utils.MustInterface2Float64(x["reduce_fee"])),
// VendorActivityID: utils.Int64ToStr(utils.MustInterface2Int64(x["act_detail_id"])),
}
if x["act_detail_id"] != nil { // 容错处理
activity.VendorActivityID = utils.Int64ToStr(utils.MustInterface2Int64(x["act_detail_id"]))
orderFinancial.Discounts = append(orderFinancial.Discounts, activity)
}
// 通过活动Id去取京西活动补贴
// orderFinancial.JxSubsidyMoney +=
}
}
}
poiReceiveDetail := result["poi_receive_detail"]
if poiReceiveDetail != nil {
var data map[string]interface{}
utils.UnmarshalUseNumber([]byte(utils.Interface2String(poiReceiveDetail)), &data)
orderDetail.ReceivableFreight = utils.MustInterface2Int64(data["logisticsFee"])
orderDetail.FreightMoney = utils.MustInterface2Int64(data["logisticsFee"])
orderDetail.ActualPayMoney = utils.MustInterface2Int64(data["onlinePayment"])
orderDetail.PmMoney = utils.MustInterface2Int64(data["foodShareFeeChargeByPoi"])
orderDetail.ShopMoney = utils.MustInterface2Int64(data["wmPoiReceiveCent"])
orderFinancial.ReceivableFreight = utils.MustInterface2Int64(data["logisticsFee"])
orderFinancial.FreightMoney = utils.MustInterface2Int64(data["logisticsFee"])
orderFinancial.ActualPayMoney = utils.MustInterface2Int64(data["onlinePayment"])
orderFinancial.PmMoney = utils.MustInterface2Int64(data["foodShareFeeChargeByPoi"])
orderFinancial.ShopMoney = utils.MustInterface2Int64(data["wmPoiReceiveCent"])
for _, x := range data["actOrderChargeByMt"].([]interface{}) {
orderDetail.TotalDiscountMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
orderDetail.PmSubsidyMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
orderFinancial.TotalDiscountMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
orderFinancial.PmSubsidyMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
}
for _, x := range data["actOrderChargeByPoi"].([]interface{}) {
orderDetail.TotalDiscountMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
orderFinancial.TotalDiscountMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
}
} else {
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s have no poi_receive_detail", orderDetail.VendorOrderID)
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s have no poi_receive_detail", orderFinancial.VendorOrderID)
}
return orderDetail
if utils.MustInterface2Int64(result["is_third_shipping"]) == SelfDeliveryCarrierNo { // is_third_shipping int 是否是第三方配送平台配送,0表否1表是
orderFinancial.SelfDeliveryDiscountMoney = orderFinancial.ReceivableFreight
orderFinancial.DistanceFreightMoney = 0
// 通过本地数据库去取是否转美团/达达,并计算运费
// wayBill, err := partner.CurOrderManager.LoadWaybill(orderFinancial.VendorOrderID, orderFinancial.VendorID)
// if err == nil {
// orderFinancial.JxFreightMoney = wayBill.DesiredFee
// }
}
// // 美团订单单独处理部分,美团正向订单接口推送时总结算金额没有计算公益捐款一分钱,是否在这里直接提前扣除?
// // 3/18之后的订单一直都不显示公益捐款金额而且结算现在结算到了3/18之后的订单没有的已经不计算了先注释
// // 2019-04-03 10.52 询问赵mf, 此计划是必须参加的,而且是长期的,每单固定扣除一分钱
orderFinancial.DonationMoney = PublicWelfareDonation
// 不应该对第三方结账金额做更改,就算有异常,也要保留异常,知道问题出在哪里
// orderFinancial.ShopMoney -= PublicWelfareDonation
return orderFinancial
}

View File

@@ -12,11 +12,11 @@ import (
func TestOnFinancialMsg(t *testing.T) {
msg := &mtwmapi.CallbackMsg{
Cmd: "orderPartialRefund",
Cmd: "orderRefund",
Data: url.Values{},
}
msg.Data.Set("timestamp", utils.Int64ToStr(time.Now().Unix()))
msg.Data.Set("order_id", "123458")
msg.Data.Set("order_id", "33762863167364867")
msg.Data.Set("notify_type", "agree")
msg.Data.Set("money", "23.56")
food := []map[string]interface{}{

View File

@@ -21,7 +21,9 @@ const (
FakeMsgTypeOrderReceived = "orderReceived"
FakeMsgTypeOrderDelivering = "orderDelivering"
)
const (
SelfDeliveryCarrierNo = 1 // 美团配送方式0-美团专送1-商家自送
)
const (
pickupOrderDelay = 260 * time.Second
@@ -156,13 +158,25 @@ func (c *PurchaseHandler) onOrderMsg(msg *mtwmapi.CallbackMsg) (response *mtwmap
}
if err == nil {
utils.CallFuncAsync(func() {
c.OnOrderDetail(orderMap)
if msg.Cmd == mtwmapi.MsgTypeNewOrder {
c.OnOrderDetail(orderMap, partner.CreatedPeration)
} else {
c.OnOrderDetail(orderMap, partner.UpdatedPeration)
}
})
}
}
} else {
status := c.callbackMsg2Status(msg)
err = partner.CurOrderManager.OnOrderStatusChanged(status)
if err == nil && msg.Cmd == mtwmapi.MsgTypeOrderFinished {
utils.CallFuncAsync(func() {
orderMap, err := api.MtwmAPI.OrderGetOrderDetail(utils.Str2Int64(GetOrderIDFromMsg(msg)), true)
if err == nil && utils.MustInterface2Int64(orderMap["is_third_shipping"]) == SelfDeliveryCarrierNo {
c.OnOrderDetail(orderMap, partner.UpdatedPeration)
}
})
}
}
return mtwmapi.Err2CallbackResponse(err, "")
}