Files
jx-callback/business/partner/purchase/mtwm/financial.go
2019-03-21 16:12:54 +08:00

124 lines
5.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package mtwm
import (
"net/url"
"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"
)
// 存储美团退款订单结账信息
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))
}
}
if msg.Cmd == mtwmapi.MsgTypeOrderRefund { // todo 全额退款处理
orderData := msg.Data
if orderData.Get("notify_type") == mtwmapi.NotifyTypeSuccess {
globals.SugarLogger.Debug(orderData.Get("order_id")) // 获得退款订单ID去本地数据库拿饿百消息推送只给了订单号也没有通过订单号查询退款信息的接口
}
}
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"))),
}
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
if err == nil {
afsOrder.JxStoreID = order.JxStoreID
} else {
globals.SugarLogger.Warnf("mtwm OnFinancialMsg, afsOrderID:%s is not found from partner.CurOrderManager.LoadOrder", afsOrder.VendorOrderID)
err = nil
}
food := orderData.Get("food")
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"])),
}
afsOrder.Skus = append(afsOrder.Skus, orderSku)
}
if len(refundDetail) <= 0 {
globals.SugarLogger.Warnf("ebai OnFinancialMsg, orderID:%s have no refund_detail", afsOrder.VendorOrderID)
}
return afsOrder
}
// 存储美团正向订单结账信息
func (p *PurchaseHandler) OnOrderDetail(result map[string]interface{}) (err error) {
err = orderman.SaveOrderFinancialInfo(p.OrderDetail2Financial(result))
return err
}
func (p *PurchaseHandler) OrderDetail2Financial(result map[string]interface{}) (orderDetail *model.OrderFinancial) {
orderDetail = &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)
if err == nil {
if order.Skus != nil {
for _, x := range order.Skus {
orderDetail.ShopPriceMoney += x.ShopPrice
}
}
} else {
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s is not found from partner.CurOrderManager.LoadOrder", orderDetail.VendorOrderID)
err = nil
}
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"])
}
} else {
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s have no detail", orderDetail.VendorOrderID)
}
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"])
for _, x := range data["actOrderChargeByMt"].([]interface{}) {
orderDetail.TotalDiscountMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
orderDetail.PmSubsidyMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
}
for _, x := range data["actOrderChargeByPoi"].([]interface{}) {
orderDetail.TotalDiscountMoney += utils.MustInterface2Int64(x.(map[string]interface{})["moneyCent"])
}
} else {
globals.SugarLogger.Warnf("mtwm OrderDetail2Financial, orderID:%s have no poi_receive_detail", orderDetail.VendorOrderID)
}
return orderDetail
}