diff --git a/business/jxcallback/orderman/financial.go b/business/jxcallback/orderman/financial.go index 4e0e76898..1647af77a 100644 --- a/business/jxcallback/orderman/financial.go +++ b/business/jxcallback/orderman/financial.go @@ -62,8 +62,8 @@ func (c *OrderManager) SaveOrderFinancialInfo(order *model.OrderFinancial, opera } } order.ShopMoneyByCal = order.SalePriceMoney - order.TotalDiscountMoney - order.PointsDeductionMoney + order.PmFreightDiscountMoney - order.DistanceFreightMoney - order.FreightTipsMoney - order.DonationMoney + order.SelfDeliveryDiscountMoney + order.PmSubsidyMoney + order.SkuBoxMoney + order.BoxMoney - order.PmMoney - order.JxPmMoney = (order.ShopMoney+order.PmMoney)*TotalRate/1000 - order.PmMoney // 京西平台费 = 总金额*20%-第三方平台费 - if order.JxPmMoney < 0 { // 如果算出京西平台费为负数,则置0 + order.JxPmMoney = utils.Float64TwoInt64(float64(order.ShopMoney+order.PmMoney)*TotalRate/1000) - order.PmMoney // 京西平台费 = 总金额*20%-第三方平台费 + if order.JxPmMoney < 0 { // 如果算出京西平台费为负数,则置0 order.JxPmMoney = 0 } @@ -158,7 +158,7 @@ func (c *OrderManager) SaveAfsOrderFinancialInfo(afsOrder *model.AfsOrder) (err }() // 平台结算扣除汇总--平台补贴,售后产生运费,平台收包装费,同城运费、、、 deductionsByPm := afsOrder.PmSubsidyMoney + afsOrder.AfsFreightMoney + afsOrder.BoxMoney + afsOrder.TongchengFreightMoney - afsOrder.RefundMoneyByCal = afsOrder.SkuUserMoney + afsOrder.FreightUserMoney + deductionsByPm + afsOrder.RefundMoneyByCal = afsOrder.SkuUserMoney + afsOrder.FreightUserMoney + deductionsByPm - afsOrder.PmRefundMoney // order.TotalMoney += order.SkuJxMoney // 退款单京西补贴部分先不作计算 if err = dao.CreateEntity(db, afsOrder); err != nil { if !dao.IsDuplicateError(err) { diff --git a/business/model/order_financial.go b/business/model/order_financial.go index a667749ed..28ab408c9 100644 --- a/business/model/order_financial.go +++ b/business/model/order_financial.go @@ -36,6 +36,7 @@ type OrderFinancial struct { JxSubsidyMoney int64 `json:"jxSubsidyMoney"` // 京西总补贴 JxSkuSubsidyMoney int64 `json:"jxSkuSubsidyMoney"` // 京西补贴给单条sku的金额 JxShopMoney int64 `json:"jxShopMoney"` // 店铺应结金额-京西结算给店铺的金额M + DownFlag int8 `json:"downFlag"` // 0--正常单, 1--降级单 Skus []*OrderSkuFinancial `orm:"-" json:"skus"` // 正向订单购买商品列表 Discounts []*OrderDiscountFinancial `orm:"-" json:"discounts"` // 正向订单享受优惠列表 } @@ -53,6 +54,7 @@ type OrderDiscountFinancial struct { VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 订单ID VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);index" json:"vendorOrderID2"` // 订单ID2,饿百独有 VendorActivityID string `orm:"column(vendor_activity_id);size(48)" json:"vendorActivityID"` // 活动ID 活动ID的存在,使原本的通过城市/下单时间-活动时间/金额……一系列匹配来确认活动归属的费时且准确度低的行为有了改变的可能--通过编码精确定位 + Type string `orm:"size(48)" json:"type"` // 活动type 美团订单存在不同的活动,活动ID是一样的,type不一样 如订单34399553040365354 // ActivityName string `orm:"size(255)" json:"activityName"` // 活动名 // ActivityMoney int64 `json:"activityMoney"` // 优惠金额 // Remark string `orm:"size(255)" json:"remark"` // 备注 @@ -61,7 +63,7 @@ type OrderDiscountFinancial struct { // 设置主键 "VendorOrderID", "DiscountCode", "VendorID" 一个订单不可能享受同一优惠2次 func (o *OrderDiscountFinancial) TableUnique() [][]string { return [][]string{ - []string{"VendorOrderID", "VendorActivityID", "VendorID"}, + []string{"VendorOrderID", "VendorActivityID", "Type", "VendorID"}, } } @@ -84,6 +86,7 @@ type AfsOrder struct { SkuBoxMoney int64 `json:"skuBoxMoney"` // 应退订单餐盒费 PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台总补贴金额 PmSkuSubsidyMoney int64 `json:"pmSkuSubsidyMoney"` // 平台sku补贴金额 + PmRefundMoney int64 `json:"pmRefundMoney"` // 订单取消后可能存在佣金减少,平台退回部分金额的情况 RefundMoney int64 `json:"refundMoney"` // 平台扣款总额 1 RefundMoneyByCal int64 `json:"refundMoneyByCal"` // 平台扣款总额-通过公式计算平台扣除京西的金额M // JxSkuMoney int64 `json:"jxSkuMoney"` // 京西补贴金额,现阶段是平台扣京西多少钱,京西扣商家多少钱,暂不考虑撤回京西补贴 diff --git a/business/partner/purchase/ebai/ebai_test.go b/business/partner/purchase/ebai/ebai_test.go index 37f0870e7..b82d6bdb4 100644 --- a/business/partner/purchase/ebai/ebai_test.go +++ b/business/partner/purchase/ebai/ebai_test.go @@ -6,6 +6,7 @@ import ( "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" _ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" "git.rosy.net.cn/jx-callback/globals/testinit" ) diff --git a/business/partner/purchase/ebai/financial.go b/business/partner/purchase/ebai/financial.go index 65b6870bd..12a986ddc 100644 --- a/business/partner/purchase/ebai/financial.go +++ b/business/partner/purchase/ebai/financial.go @@ -13,7 +13,10 @@ import ( func OnFinancialMsg(msg *ebaiapi.CallbackMsg) (err error) { if msg.Cmd == ebaiapi.CmdOrderPartRefund { // 部分退款处理 if utils.Int64ToStr(utils.MustInterface2Int64(msg.Body["status"])) == ebaiapi.OrderPartRefundSuccess { - orderData, err2 := api.EbaiAPI.OrderPartrefundGet(utils.Interface2String(msg.Body["refund_id"])) + // 获取到部分退款订单id + afsOrderID := utils.Interface2String(msg.Body["order_id"]) + // 处理部分退款信息 + orderData, err2 := api.EbaiAPI.OrderPartrefundGet(afsOrderID) if err = err2; err == nil { afsOrder := CurPurchaseHandler.AfsOrderDetail2Financial(orderData) err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(afsOrder) @@ -113,6 +116,18 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID) err = nil } + // 部分退款订单,第三方平台佣金会变化,金额为 orderData["commission"],是否将该字段更新到正向订单结算表中 + // 不作更新的话,商户可以得到的钱会少几毛钱,最终京西受益 + // 如果要更新,总佣金,京西佣金是否都要更新,而其它一系列连锁反应,是否需要考虑更新 + // 或者换个思路,不考虑变更之前的正向订单,在佣金上入手,退款金额减去佣金减少的部分 + orderFinancial, err := partner.CurOrderManager.LoadOrderFinancial(afsOrder.VendorOrderID, model.VendorIDEBAI) + if err == nil { + afsOrder.PmRefundMoney = orderFinancial.PmMoney - utils.MustInterface2Int64(orderData["commission"]) + } else { + // 此处应该报错 + globals.SugarLogger.Warnf("ebai AfsOrderDetail2Financial, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrderFinancial", afsOrder.VendorOrderID) + err = nil + } if orderData["refund_detail"] != nil { refundDetail := orderData["refund_detail"].([]interface{}) for _, refundInfo := range refundDetail { @@ -150,6 +165,17 @@ func (p *PurchaseHandler) OnOrderDetail(result map[string]interface{}, operation return err } +// func (p *PurchaseHandler) GetTrueEbaiOrder(result1 map[string]interface{}) (result2 map[string]interface{}) { +// order := result1["order"].(map[string]interface{}) +// if utils.MustInterface2Int64(order["down_flag"]) == 1 { +// result, err := api.EbaiAPI.OrderGet(utils.Interface2String(order["order_id"])) +// if err == nil { +// return p.GetTrueEbaiOrder(result) +// } +// } +// return result1 +// } + func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (orderFinancial *model.OrderFinancial) { orderFinancial = &model.OrderFinancial{ VendorID: model.VendorIDEBAI, @@ -160,6 +186,7 @@ func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) ( // orderFinancial.DeliveryConfirmTime = getTimeFromInterface(order1["finished_time"]) orderFinancial.TotalDiscountMoney = utils.MustInterface2Int64(order1["discount_fee"]) orderFinancial.ReceivableFreight = utils.MustInterface2Int64(order1["send_fee"]) + orderFinancial.DownFlag = int8(utils.MustInterface2Int64(order1["down_flag"])) if int(getInt64FromInterface(order1["delivery_party"])) == ebaiapi.SendImmediatelySelf { orderFinancial.SelfDeliveryDiscountMoney = orderFinancial.ReceivableFreight @@ -233,6 +260,7 @@ func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) ( // ActivityName: utils.Interface2String(xMap["desc"]), // ActivityMoney: discountPrice, VendorActivityID: utils.Interface2String(xMap["activity_id"]), + Type: utils.Interface2String(xMap["type"]), } orderFinancial.Discounts = append(orderFinancial.Discounts, activity) // 通过活动Id去取,京西活动补贴 diff --git a/business/partner/purchase/ebai/financial_test.go b/business/partner/purchase/ebai/financial_test.go index 9e601de51..723ec6e75 100644 --- a/business/partner/purchase/ebai/financial_test.go +++ b/business/partner/purchase/ebai/financial_test.go @@ -7,20 +7,34 @@ import ( "time" "git.rosy.net.cn/baseapi/platformapi/ebaiapi" - "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/partner" + "git.rosy.net.cn/jx-callback/globals/api" ) func TestOnFinancialMsg(t *testing.T) { msg := &ebaiapi.CallbackMsg{ - // Cmd: "order.partrefund.push", - Cmd: "order.user.cancel", - Body: make(map[string]interface{}), + Timestamp: time.Now().Unix(), + Body: make(map[string]interface{}), } - 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") + msg.Body["order_id"] = "1554939646172038357" + + // 部分退款 + msg.Cmd = "order.partrefund.push" + msg.Body["status"] = json.Number("20") + + // 全单退款 + // msg.Cmd = "order.user.cancel" + // msg.Body["type"] = json.Number("40") + // msg.Body["cancel_type"] = json.Number("2") + res := OnFinancialMsg(msg) fmt.Println(res) } + +func TestOnOrderDetail(t *testing.T) { + orderID := "1554939646172038357" + result, err := api.EbaiAPI.OrderGet(orderID) + if err == nil { + new(PurchaseHandler).OnOrderDetail(result, partner.CreatedPeration) + } +} diff --git a/business/partner/purchase/jd/financial.go b/business/partner/purchase/jd/financial.go index be0d3c756..1c4fef6ba 100644 --- a/business/partner/purchase/jd/financial.go +++ b/business/partner/purchase/jd/financial.go @@ -99,6 +99,7 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{} // 如果为自配送,自配送补贴=订单初始运费,远距离费=0 orderFinancial.SelfDeliveryDiscountMoney = utils.MustInterface2Int64(orderData["orderReceivableFreight"]) orderFinancial.DistanceFreightMoney = 0 + orderFinancial.FreightTipsMoney = 0 // 通过本地数据库去取是否转美团/达达,并计算运费 // wayBill, err2 := partner.CurOrderManager.LoadWaybill(orderFinancial.VendorOrderID, orderFinancial.VendorID) // if err = err2; err == nil { @@ -127,11 +128,12 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{} if xMap["orderShareRatioData"] != nil { orderShareRatioData, _ := utils.HTTPBody2Values([]byte(utils.Interface2String(xMap["orderShareRatioData"])), false) activity := &model.OrderDiscountFinancial{ - VendorID: orderFinancial.VendorID, - VendorOrderID: orderFinancial.VendorOrderID, + VendorID: orderFinancial.VendorID, + VendorOrderID: orderFinancial.VendorOrderID, + VendorActivityID: utils.Interface2String(orderShareRatioData["promotionId"][0]), + Type: utils.Int64ToStr(int64(discountType)), // ActivityName: utils.Interface2String(xMap["discountName"]), // ActivityMoney: discountPrice, - VendorActivityID: utils.Interface2String(orderShareRatioData["promotionId"][0]), // Remark: utils.Interface2String(xMap["orderShareRatioData"]), } orderFinancial.Discounts = append(orderFinancial.Discounts, activity)