From fdc91c20e445933264b5e192f75811e7026f9842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 27 Feb 2020 13:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=81=94=E5=AE=9D=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/jx/localjx/order.go | 49 +++++++++++-------- .../purchase/jx/localjx/tonglianpay.go | 11 +++++ 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index c5be696fc..dd65d6a11 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -594,29 +594,20 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) var orderPayRefund *model.OrderPayRefund if orderPay.PayType == model.PayTypeWX { orderPayRefund, err = refundOrderByWX(ctx, orderPay, refundID, orderPay.TotalFee, reason) + if err == nil { + dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName()) + errList.AddErr(dao.CreateEntity(dao.GetDB(), orderPayRefund)) + MarkArrears(db, order, orderPay) + } else { + errList.AddErr(err) + } } else if orderPay.PayType == model.PayTypeTL { orderPayRefund, err = refundOrderByTL(ctx, orderPay, refundID, orderPay.TotalFee, reason) - } - if err2 == nil { - dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName()) - errList.AddErr(dao.CreateEntity(dao.GetDB(), orderPayRefund)) - //退款后,若此订单下单用户有推广人,则需要将分给推广人的金额记录到该推广人的欠款中 - orders, _ := dao.QueryOrders(db, order.VendorOrderID, 0, []int{model.VendorIDJX}, 0, utils.DefaultTimeValue, utils.DefaultTimeValue) - if len(orders) > 0 { - user, _ := dao.GetUserByID(db, "user_id", orders[0].UserID) - if user.ParentMobile != "" { - user2, _ := dao.GetUserByID(db, "mobile", user.ParentMobile) - user2.Arrears = user2.Arrears + (orderPay.TotalFee * user2.DividePercentage / 100) - dao.UpdateEntity(db, user2, "Arrears") - if user2.ParentMobile != "" { - user3, _ := dao.GetUserByID(db, "mobile", user2.ParentMobile) - user3.Arrears = user3.Arrears + ((orderPay.TotalFee - user2.Arrears) * user3.DividePercentage / 100) - dao.UpdateEntity(db, user3, "Arrears") - } - } + if err == nil { + MarkArrears(db, order, orderPay) + } else { + errList.AddErr(err) } - } else { - errList.AddErr(err2) } } else { orderPay.Status = model.PayStatusCanceled @@ -639,6 +630,24 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) return err } +func MarkArrears(db *dao.DaoDB, order *model.GoodsOrder, orderPay *model.OrderPay) { + //退款后,若此订单下单用户有推广人,则需要将分给推广人的金额记录到该推广人的欠款中 + orders, _ := dao.QueryOrders(db, order.VendorOrderID, 0, []int{model.VendorIDJX}, 0, utils.DefaultTimeValue, utils.DefaultTimeValue) + if len(orders) > 0 { + user, _ := dao.GetUserByID(db, "user_id", orders[0].UserID) + if user.ParentMobile != "" { + user2, _ := dao.GetUserByID(db, "mobile", user.ParentMobile) + user2.Arrears = user2.Arrears + (orderPay.TotalFee * user2.DividePercentage / 100) + dao.UpdateEntity(db, user2, "Arrears") + if user2.ParentMobile != "" { + user3, _ := dao.GetUserByID(db, "mobile", user2.ParentMobile) + user3.Arrears = user3.Arrears + ((orderPay.TotalFee - user2.Arrears) * user3.DividePercentage / 100) + dao.UpdateEntity(db, user3, "Arrears") + } + } + } +} + func AgreeOrRefuseCancel(ctx *jxcontext.Context, order *model.GoodsOrder, isAgree bool, reason string) (err error) { if isAgree { err = CancelOrder(ctx, order, reason) diff --git a/business/partner/purchase/jx/localjx/tonglianpay.go b/business/partner/purchase/jx/localjx/tonglianpay.go index d74dfdcde..d2eaa79be 100644 --- a/business/partner/purchase/jx/localjx/tonglianpay.go +++ b/business/partner/purchase/jx/localjx/tonglianpay.go @@ -171,5 +171,16 @@ func refundOrderByTL(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID RefundCreatedAt: time.Now(), } } + db := dao.GetDB() + if result.TrxStatus == tonglianpayapi.TrxStatusSuccess { + orderPayRefund.Status = model.RefundStatusYes + } else { + orderPayRefund.Status = model.RefundStatusFailed + } + orderPayRefund.OriginalData = utils.Format4Output(result, true) + dao.CreateEntity(db, orderPayRefund) + + orderPay.Status = model.PayStatusRefund + dao.UpdateEntity(db, orderPay) return orderPayRefund, err }