From 48f6ec00632edf2270296e4d884ee4c6e2df7c49 Mon Sep 17 00:00:00 2001 From: mofangmin Date: Mon, 19 Aug 2024 12:16:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86mlpay=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- call/pay.go | 43 +++++++++++++++++++++------------- modules/pay/base/callback.go | 2 +- modules/pay/mlpay/base.go | 22 ++++++++++------- modules/pay/routers/routers.go | 1 + modules/pay/values/values.go | 10 ++++++-- modules/web/handler/share.go | 2 +- 6 files changed, 52 insertions(+), 28 deletions(-) diff --git a/call/pay.go b/call/pay.go index 81b83c0..ccc39c7 100644 --- a/call/pay.go +++ b/call/pay.go @@ -396,11 +396,17 @@ func ReturnBackWithdraw(or *common.WithdrawOrder, originStatus, status uint8, pa order := &common.WithdrawOrder{} order.ID = or.ID tx := db.Mysql().Begin() + // 打款失败的单,重新挂起到后台进入人工审核,不再返还金币给玩家 u := map[string]interface{}{ "status": status, "fail_reason": or.FailReason, "callback_time": time.Now().Unix(), } + if len(or.Operator) == 0 { + status = common.StatusROrderCreate + delete(u, "callback_time") + } + if len(payChannel) > 0 { u["pay_channel"] = payChannel[0] } @@ -423,10 +429,13 @@ func ReturnBackWithdraw(or *common.WithdrawOrder, originStatus, status uint8, pa uid := or.UID re := new(common.RechargeInfo) re.UID = uid - updateRe := map[string]interface{}{ - "withdrawing_cash": gorm.Expr("withdrawing_cash - ?", or.WithdrawCash), - "total_withdrawing": gorm.Expr("total_withdrawing - ?", or.Amount), - "day_withdraw": gorm.Expr("day_withdraw - ?", or.Amount), + updateRe := map[string]interface{}{} + if status != common.StatusROrderCreate { + updateRe = map[string]interface{}{ + "withdrawing_cash": gorm.Expr("withdrawing_cash - ?", or.WithdrawCash), + "total_withdrawing": gorm.Expr("total_withdrawing - ?", or.Amount), + "day_withdraw": gorm.Expr("day_withdraw - ?", or.Amount), + } } if status == common.StatusROrderFail || status == common.StatusROrderRefuse { updateRe["withdraw_count"] = gorm.Expr("withdraw_count + ?", -1) @@ -438,18 +447,20 @@ func ReturnBackWithdraw(or *common.WithdrawOrder, originStatus, status uint8, pa tx.Rollback() return err } - if err := UpdateCurrency(&common.UpdateCurrency{ - CurrencyBalance: &common.CurrencyBalance{ - UID: or.UID, - Type: or.CurrencyType, - Value: or.WithdrawCash, - Event: common.CurrencyEventWithDrawBack, - Exs1: or.OrderID, - }, - }, tx); err != nil { - log.Error("Withdraw callback err:%v", err) - tx.Rollback() - return err + if status != common.StatusROrderCreate { + if err := UpdateCurrency(&common.UpdateCurrency{ + CurrencyBalance: &common.CurrencyBalance{ + UID: or.UID, + Type: or.CurrencyType, + Value: or.WithdrawCash, + Event: common.CurrencyEventWithDrawBack, + Exs1: or.OrderID, + }, + }, tx); err != nil { + log.Error("Withdraw callback err:%v", err) + tx.Rollback() + return err + } } // 退还代付券 // if or.Extra == "useFreeWithdraw" { diff --git a/modules/pay/base/callback.go b/modules/pay/base/callback.go index 6bb49d8..0b6877c 100644 --- a/modules/pay/base/callback.go +++ b/modules/pay/base/callback.go @@ -16,10 +16,10 @@ import ( ) func (b *Base) PayCallback(c *gin.Context) { - str, err := b.Callback(c) defer func() { c.String(http.StatusOK, b.CallbackResp.Msg) }() + str, err := b.Callback(c) if err != nil { log.Error("err:%v", err) b.CallbackResp.Msg = "callback fail" diff --git a/modules/pay/mlpay/base.go b/modules/pay/mlpay/base.go index 11ddd34..4a8f9ea 100644 --- a/modules/pay/mlpay/base.go +++ b/modules/pay/mlpay/base.go @@ -32,12 +32,12 @@ func NewSub(b *base.Base) { b.Resp = new(WithdrawResp) b.ReqURL = baseUrl + withdrawURL } else if b.Opt == base.OPTPayCB { - b.HttpType = base.HttpTypeForm + b.HttpType = base.HttpTypeGet b.CallbackReq = new(PayCallbackReq) b.CallbackResp.Msg = "0" } else if b.Opt == base.OPTWithdrawCB { b.SignKey = withdrawKey - b.HttpType = base.HttpTypeForm + b.HttpType = base.HttpTypeGet b.CallbackReq = new(WithdrawCallbackReq) b.CallbackResp.Msg = "0" // } else if b.Opt == base.OPTQueryWithdraw { // 查询 @@ -147,20 +147,26 @@ func (s *Sub) PackWithdrawReq() interface{} { func (s *Sub) CheckSign(str string) bool { log.Debug("callback:%v", s.Base.CallbackReq) - sign := "" + checkSign := "" + sign := str if s.Base.Opt == base.OPTPayCB { req := s.Base.CallbackReq.(*PayCallbackReq) s.Base.CallbackResp.OrderID = req.PartnerOrderNo s.Base.CallbackResp.APIOrderID = req.OrderNo s.Base.CallbackResp.Success = req.Status == 1 - sign = req.Sign + checkSign = req.Sign } else if s.Base.Opt == base.OPTWithdrawCB { req := s.Base.CallbackReq.(*WithdrawCallbackReq) s.Base.CallbackResp.OrderID = req.PartnerWithdrawNo s.Base.CallbackResp.Success = req.Status == 1 - sign = req.Sign } - signStr := base.GetSignStrFormURLEncode(s.Base.C, s.Base.CallbackReq, "sign") - signStr2 := base.GetSignStrURLEncode(signStr, "sign") + "&key=" + s.Base.SignKey - return strings.ToUpper(util.CalculateMD5(signStr2)) == sign + if s.Base.KeyName == "" { + sign += "&key=" + s.Base.SignKey + } else { + sign += "&" + s.Base.KeyName + "=" + s.Base.SignKey + } + ret := util.CalculateMD5(sign) + ret = strings.ToUpper(ret) + log.Info("SignStr:%v,SignMD5:%v", sign, ret) + return checkSign == ret } diff --git a/modules/pay/routers/routers.go b/modules/pay/routers/routers.go index ad777ac..6580523 100644 --- a/modules/pay/routers/routers.go +++ b/modules/pay/routers/routers.go @@ -58,6 +58,7 @@ func PayCallback(c *gin.Context) { b := base.NewCallbackBase(3) allpay.NewSub(b, index) if b.Sub == nil { + log.Error("err:%v", err) return } b.PayCallback(c) diff --git a/modules/pay/values/values.go b/modules/pay/values/values.go index efae297..ec2c4f6 100644 --- a/modules/pay/values/values.go +++ b/modules/pay/values/values.go @@ -443,8 +443,14 @@ func Post(req *http.Request, ret interface{}) int { } func AddWithdrawChannel(p int, amount int) { - if err := db.Mysql().C().Model(&common.ConfigWithdrawChannels{}).Where("channel_id = ?", p).Updates(map[string]interface{}{"withdraw_per": gorm.Expr("withdraw_per + ?", amount)}).Error; err != nil { - log.Error("err:%v", err) + channel := &common.ConfigWithdrawChannels{ + ChannelID: p, + } + db.Mysql().Get(&channel) + if channel.WithdrawPer+amount > 100 { + if err := db.Mysql().C().Model(&common.ConfigWithdrawChannels{}).Where("channel_id = ?", p).Updates(map[string]interface{}{"withdraw_per": gorm.Expr("withdraw_per + ?", amount)}).Error; err != nil { + log.Error("err:%v", err) + } } } diff --git a/modules/web/handler/share.go b/modules/web/handler/share.go index 7b5ec82..da2c5e5 100644 --- a/modules/web/handler/share.go +++ b/modules/web/handler/share.go @@ -267,7 +267,7 @@ func ShareWithdraw(c *gin.Context) { } } - orderID := util.NewOrderID(int(a.UID)) + orderID := util.NewOrderID(a.UID) vipCon := call.GetVipCon(a.UID) realAmount := req.Amount // 实际打款