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 }