diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index e9646af90..fdf5c12cc 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -245,18 +245,7 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m } dao.UpdateEntity(db, order, "NewEarningPrice") } - //美团订单如果有售后的话,订单完成后才能查到售后结算 - //if order.VendorID == model.VendorIDMTWM { - // if afsOrders, _ := dao.GetAfsOrders(db, order.VendorID, order.VendorOrderID, ""); len(afsOrders) > 0 { - // if handler := partner.GetPurchaseOrderHandlerFromVendorID(afsOrders[0].VendorID); handler != nil { - // if orderAfsInfo, err := handler.GetOrderAfsInfo(nil, afsOrders[0].VendorOrderID, afsOrders[0].AfsOrderID); err == nil && orderAfsInfo.AfsTotalShopMoney != 0 { - // afsOrders[0].AfsTotalShopMoney = order.TotalShopMoney + orderAfsInfo.AfsTotalShopMoney - // dao.UpdateEntity(db, afsOrders[0], "AfsTotalShopMoney") - // order.TotalShopMoney = order.TotalShopMoney + orderAfsInfo.AfsTotalShopMoney - // } - // } - // } - //} + if order.VendorID == model.VendorIDMTWM { if afsOrders, _ := dao.GetAfsOrders(db, order.VendorID, order.VendorOrderID, ""); len(afsOrders) > 0 { for _, v := range afsOrders { @@ -266,6 +255,7 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m } dao.UpdateEntity(db, v, "AfsTotalShopMoney") } + break } } } diff --git a/business/jxcallback/orderman/order_afs.go b/business/jxcallback/orderman/order_afs.go index 289e85e78..04d44140c 100644 --- a/business/jxcallback/orderman/order_afs.go +++ b/business/jxcallback/orderman/order_afs.go @@ -222,7 +222,7 @@ func (c *OrderManager) addAfsOrderStatus(db *dao.DaoDB, orderStatus *model.Order } updateFields = append(updateFields, "Flag") } - if model.IsAfsOrderFinalStatus(orderStatus.Status) { + if model.IsAfsOrderFinalStatus(orderStatus.Status) || orderStatus.Status == model.AfsOrderStatusNew { order.AfsFinishedAt = orderStatus.StatusTime if utils.IsTimeZero(order.AfsFinishedAt) { order.AfsFinishedAt = time.Now() diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index 45d0acf34..1ee139c28 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -170,7 +170,7 @@ func GetServiceInfo(ctx *jxcontext.Context) map[string]interface{} { } func GetPlaces(ctx *jxcontext.Context, keyword string, includeDisabled bool, params map[string]interface{}) ([]*model.Place, error) { - sql := ` + sql := ` SELECT * FROM place t1 WHERE 1 = 1 diff --git a/business/partner/purchase/mtwm/order_afs.go b/business/partner/purchase/mtwm/order_afs.go index ba2f96139..2f3d20fad 100644 --- a/business/partner/purchase/mtwm/order_afs.go +++ b/business/partner/purchase/mtwm/order_afs.go @@ -3,6 +3,8 @@ package mtwm import ( "errors" "fmt" + "git.rosy.net.cn/baseapi/platformapi/dingdingapi" + "git.rosy.net.cn/jx-callback/business/jxutils/ddmsg" "net/url" "strconv" "strings" @@ -65,7 +67,10 @@ func (c *PurchaseHandler) OnAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma // todo 对于退款与部分退款,order.go与这个文件中对于状态的处理不一致 func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwmapi.CallbackResponse) { - var err error + var ( + err error + db = dao.GetDB() + ) orderStatus := c.callbackAfsMsg2Status(msg) needCallNew := orderStatus.Status == model.AfsOrderStatusWait4Approve || orderStatus.Status == model.AfsOrderStatusNew if !needCallNew { @@ -98,13 +103,19 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma ReasonImgList: utils.LimitUTF8StringLen(strings.Join(refundData.PictureList, ","), 1024), RefundType: model.AfsTypePartRefund, VendorOrgCode: msg.AppID, + //RefundMoney: , // FreightUserMoney: afsInfo.OrderFreightMoney, // AfsFreightMoney: afsInfo.AfsFreight, // BoxMoney: afsInfo.PackagingMoney, // TongchengFreightMoney: afsInfo.TongchengFreightMoney, // SkuBoxMoney: afsInfo.MealBoxMoney, } + var refundMoney float64 = 0 for _, sku := range refundData.FoodList { + skuCount := sku.Count + if skuCount == 0 { + skuCount = 1 + } orderSku := &model.OrderSkuFinancial{ // VendorID: model.VendorIDMTWM, AfsOrderID: afsOrder.AfsOrderID, @@ -118,7 +129,7 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma VendorSkuID: sku.SkuID, SkuID: int(utils.Str2Int64WithDefault(sku.SkuID, 0)), Name: sku.FoodName, - UserMoney: jxutils.StandardPrice2Int(sku.RefundPrice)*int64(sku.Count) + jxutils.StandardPrice2Int(sku.BoxPrice)*int64(sku.BoxNum), + UserMoney: jxutils.StandardPrice2Int(sku.RefundPrice)*int64(skuCount) + jxutils.StandardPrice2Int(sku.BoxPrice)*int64(sku.BoxNum), } if orderSku.VendorSkuID == "" || orderSku.VendorSkuID == "0" { orderSku.VendorSkuID = sku.AppFoodCode @@ -126,7 +137,9 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma afsOrder.SkuUserMoney += orderSku.UserMoney afsOrder.Skus = append(afsOrder.Skus, orderSku) + refundMoney += sku.RefundPrice } + afsOrder.RefundMoney = utils.Float64TwoInt64(refundMoney * 100) //afsOrder.PmSubsidyMoney += afsOrder.RefundMoney - afsOrder.SkuUserMoney } else { if afsOrder = c.createAfsOrder(msg.FormData); afsOrder != nil { @@ -158,42 +171,104 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma // msg-status 1-已申请 10-初审已同意 11-初审已驳回 16-初审已申诉 17-初审申诉已同意 18-初审申诉已驳回 20-终审已发起(用户已发货) 21-终审已同意 22-终审已驳回 26-终审已申诉 27-终审申诉已同意 28-终审申诉已驳回 30-已取消 if err := partner.CurOrderManager.OnAfsOrderStatusChanged(orderStatus); err == nil { order, _ := partner.CurOrderManager.LoadOrder(orderStatus.RefVendorOrderID, model.VendorIDMTWM) + mtmApi := getAPI(order.VendorOrgCode, order.StoreID, order.VendorStoreID) + // 订单回调全额退款接口时,将订单状态修改为取消 refundData := msg.Data.(*mtwmapi.CallbackRefundInfo) if refundData.NotifyType == mtwmapi.MsgTypeOrderAgree && msg.Cmd == mtwmapi.MsgTypeOrderRefund { order.Status = model.OrderStatusCanceled - dao.UpdateEntity(dao.GetDB(), order, "Status") + dao.UpdateEntity(db, order, "Status") } else if refundData.Status == "21" { - skuList, _ := dao.GetSimpleOrderSkus(dao.GetDB(), orderStatus.RefVendorOrderID, nil) + skuList, _ := dao.GetSimpleOrderSkus(db, orderStatus.RefVendorOrderID, nil) totalSkuCount := 0 for _, v := range skuList { totalSkuCount += v.Count } - financialSku, _ := dao.GetOrderRefundSkuList(dao.GetDB(), []string{orderStatus.RefVendorOrderID}) + financialSku, _ := dao.GetOrderRefundSkuList(db, []string{orderStatus.RefVendorOrderID}) refundSkuCount := 0 for _, v := range financialSku { refundSkuCount += v.Count } if totalSkuCount == refundSkuCount { order.Status = model.OrderStatusCanceled - dao.UpdateEntity(dao.GetDB(), order, "Status") + dao.UpdateEntity(db, order, "Status") } + } + // 已经审核过的售后单子 + if orderStatus.Status == model.AfsOrderStatusNew || orderStatus.Status == model.AfsOrderStatusFinished { + // 平台结算金额 + /*vendorSettle, err := mtmApi.OrderGetOrderDetail(utils.Str2Int64(order.VendorOrderID), true) // 退款列表 + if err == nil { + if poiReceiveDetailStr := utils.Interface2String(vendorSettle["poi_receive_detail"]); poiReceiveDetailStr != "" { + var poiReceiveDetail *mtwmapi.PoiReceiveDetailInfo + utils.UnmarshalUseNumber([]byte(poiReceiveDetailStr), &poiReceiveDetail) + if poiReceiveDetail != nil { + } + } + } else { + globals.SugarLogger.Debugf("美团平台售后获取结算信息错误: = %v", err) + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "美团平台售后获取结算信息错误", fmt.Sprintf("orderid := %d,%s", model.VendorIDMTWM, order.VendorOrderID)) + }*/ - //// 可能存在退差价的情况 - //if strings.Contains(orderStatus.Remark, "退差价") { - // afsOrder, _ := partner.CurOrderManager.LoadAfsOrder(orderStatus.VendorOrderID, orderStatus.VendorID) - // afsOrder.AfsTotalShopMoney = utils.Float64TwoInt64(utils.Str2Float64(msg.FormData.Get("key")) * 100) - // dao.UpdateEntity(dao.GetDB(), afsOrder, "AfsTotalShopMoney") - // - // ?? - // order.TotalShopMoney = order.TotalShopMoney - afsOrder.AfsTotalShopMoney - //} + // 售后金额 + refundDetail, err := mtmApi.GetOrderRefundDetail(utils.Str2Int64(order.VendorOrderID), 0) + if err == nil && len(refundDetail) > 0 { + for _, rd := range refundDetail { + order.TotalShopMoney = order.TotalShopMoney + jxutils.StandardPrice2Int(utils.Str2Float64(rd.RefundPartialEstimateCharge.SettleAmount)) + } + switch order.EarningType { + case model.EarningTypePoints: // 扣点 + //更新订单new_earning_price + waybill, _ := partner.CurOrderManager.LoadWaybill(order.VendorWaybillID, order.WaybillVendorID) + if waybill == nil { + if (order.NewEarningPrice == 0 || order.NewEarningPrice != order.TotalShopMoney*int64(100-order.OrderPayPercentage/2)/int64(100)) && order.OrderPayPercentage <= 50 { + order.NewEarningPrice = order.TotalShopMoney * int64(100-order.OrderPayPercentage/2) / int64(100) + } + } else { + if (order.NewEarningPrice == 0 || order.NewEarningPrice != (order.TotalShopMoney-waybill.DesiredFee)*int64(100-order.OrderPayPercentage/2)/int64(100)) && order.OrderPayPercentage <= 50 { + order.NewEarningPrice = order.TotalShopMoney*int64(100-order.OrderPayPercentage/2)/int64(100) - waybill.DesiredFee + } + } + dao.UpdateEntity(db, order, "TotalShopMoney", "NewEarningPrice") + case model.EarningTypeQuote: // 报价 + orderSkuShopPriceList := make(map[int]int64, 0) + orderSkuEarningPriceList := make(map[int]int64, 0) + for _, os := range order.Skus { + orderSkuShopPriceList[os.SkuID] = os.ShopPrice + orderSkuEarningPriceList[os.SkuID] = os.EarningPrice + } + + for _, rd := range refundDetail { + for _, rdw := range rd.WmAppRetailForOrderPartRefundList { + switch rd.RefundType { + // 退款类型:1-全额退款;2-部分退款;3-退差价;5-按金额灵活退。 + case 3: // 缺重退部分 + if _, ok := orderSkuShopPriceList[utils.Str2Int(rdw.SkuID)]; ok { + order.ShopPrice = order.ShopPrice - jxutils.StandardPrice2Int((rdw.RefundPrice/rdw.FoodPrice)*float64(orderSkuShopPriceList[utils.Str2Int(rdw.SkuID)])) + order.EarningPrice = order.EarningPrice - jxutils.StandardPrice2Int((rdw.RefundPrice/rdw.FoodPrice)*float64(orderSkuEarningPriceList[utils.Str2Int(rdw.SkuID)])) + } + default: // 全退 + if _, ok := orderSkuShopPriceList[utils.Str2Int(rdw.SkuID)]; ok { + order.ShopPrice = order.ShopPrice - (orderSkuShopPriceList[utils.Str2Int(rdw.SkuID)] * int64(rdw.Count)) + order.EarningPrice = order.EarningPrice - (orderSkuEarningPriceList[utils.Str2Int(rdw.SkuID)] * int64(rdw.Count)) + } + } + + } + order.NewEarningPrice = order.EarningPrice + } + } + dao.UpdateEntity(db, order, "TotalShopMoney", "ShopPrice", "EarningPrice") + } else { + globals.SugarLogger.Debugf("美团平台售后获取退款金额信息错误: = %v", err) + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "美团平台售后获取退款金额信息错误", fmt.Sprintf("orderid := %d,%s", model.VendorIDMTWM, order.VendorOrderID)) + } } // 新订单平台自动同意退单,某一些情况下产生的运单没退!这个处理一下! if refundData.NotifyType == mtwmapi.MsgTypeOrderAgree && (msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderAgree) { - wayBill, _ := dao.GetWaybills(dao.GetDB(), orderStatus.RefVendorOrderID, nil) + wayBill, _ := dao.GetWaybills(db, orderStatus.RefVendorOrderID, nil) for _, v := range wayBill { handlerInfo := partner.GetDeliveryPlatformFromVendorID(v.WaybillVendorID) if handlerInfo != nil { @@ -203,7 +278,7 @@ func (c *PurchaseHandler) onAfsOrderMsg(msg *mtwmapi.CallbackMsg) (retVal *mtwma } if order.Status == model.OrderStatusCanceled { num, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", utils.Int64ToFloat64(order.TotalShopMoney)/float64(100)), 64) - applyErr := getAPI(order.VendorOrgCode, order.StoreID, order.VendorStoreID).ApplyCompensation(&mtwmapi.ApplyCompensationRes{ + applyErr := mtmApi.ApplyCompensation(&mtwmapi.ApplyCompensationRes{ OrderId: utils.Str2Int64(order.VendorOrderID), Reason: "商户申请", ApplyStatus: mtwmapi.ApplyCompensationStatusOne, @@ -317,9 +392,8 @@ func (c *PurchaseHandler) GetOrderAfsInfo(ctx *jxcontext.Context, vendorOrderID, } } } - if order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, model.VendorIDMTWM); err == nil { - orderAfsInfo.AfsTotalShopMoney = order.TotalShopMoney + afsTotalShopMoney - } + + orderAfsInfo.AfsTotalShopMoney = order.TotalShopMoney + afsTotalShopMoney return orderAfsInfo, err }