|
@@ -16,6 +16,7 @@ import (
|
|
|
"github.com/go-pay/gopay/wechat"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"math/rand"
|
|
|
+ "net/http"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
@@ -209,6 +210,8 @@ func ActiveConfigInfo(c *gin.Context) {
|
|
|
groupBuyInfo.OriginalPrice = v.OriginalPrice
|
|
|
groupBuyInfo.RebateRate = v.RebateRate
|
|
|
|
|
|
+ groupBuyInfo.MaxRebatePrice = v.GroupBuyOnePrice.Mul(decimal.NewFromInt32(int32(v.RebateRate)).Div(decimal.NewFromInt32(100)))
|
|
|
+
|
|
|
groupBuyProject.GroupBuyID = v.ID
|
|
|
|
|
|
projectList, _, err := groupBuyProject.GetGroupBuyProjectList()
|
|
@@ -789,3 +792,81 @@ func Pay(c *gin.Context) {
|
|
|
// 获取参数
|
|
|
//
|
|
|
}
|
|
|
+
|
|
|
+func ActivePayCallBack(c *gin.Context) {
|
|
|
+ var payLog shanghu.ActivePayCallbackLog
|
|
|
+ var payTrans shanghu.ClientActivePayTrans
|
|
|
+ wxNotify, err := wechat.ParseNotifyToBodyMap(c.Request)
|
|
|
+ if err != nil {
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //通知回调log
|
|
|
+ payLog.CallBackLog = wxNotify.JsonBody()
|
|
|
+ payLog.ThirdTradeNo = wxNotify.Get("transaction_id")
|
|
|
+ payLog.OutTradeNo = wxNotify.Get("out_trade_no")
|
|
|
+ payLog.CreatedAt = time.Now()
|
|
|
+ payLog.UpdatedAt = time.Now()
|
|
|
+
|
|
|
+ _, err = payLog.Create()
|
|
|
+ if err != nil {
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if wxNotify.Get("return_code") != "SUCCESS" || wxNotify.Get("result_code") != "SUCCESS" {
|
|
|
+ payLog.ErrLog = "微信返回错误:" + wxNotify.Get("return_code") + "--" + wxNotify.Get("result_code")
|
|
|
+ payLog.UpdateMerchant()
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验金额
|
|
|
+ payTrans.OutTradeNo = wxNotify.Get("out_trade_no")
|
|
|
+ payTransInfo, err := payTrans.GetPayTransByTradeNo()
|
|
|
+ if err != nil {
|
|
|
+ payLog.ErrLog = "查询交易信息错误:" + " err=" + err.Error()
|
|
|
+ payLog.UpdateMerchant()
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 判断金额与支付流水是否一致
|
|
|
+ totalFee, err := decimal.NewFromString(wxNotify.Get("total_fee"))
|
|
|
+ if err != nil {
|
|
|
+ payLog.ErrLog = "解析总金额报错:" + "err=" + err.Error()
|
|
|
+ payLog.UpdateMerchant()
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !totalFee.Equal(payTransInfo.Amount.Mul(decimal.NewFromInt(100))) {
|
|
|
+ payLog.ErrLog = "验证金额报错:total_fee=" + wxNotify.Get("total_fee") + " amount=" + payTransInfo.Amount.String()
|
|
|
+ payLog.UpdateMerchant()
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 解析支付时间
|
|
|
+ timeEnd, err := time.ParseInLocation("20060102150405", wxNotify.Get("time_end"), tools.TimeLocation)
|
|
|
+ if err != nil {
|
|
|
+ payLog.ErrLog = "付款时间解析出错:err=" + err.Error()
|
|
|
+ payLog.UpdateMerchant()
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ payTrans.ThirdTradeNo = wxNotify.Get("transaction_id")
|
|
|
+ payTrans.Status = 2 //支付成功
|
|
|
+ payTrans.PayTime = timeEnd
|
|
|
+ payTrans.AccountStatus = 1 //未分账
|
|
|
+
|
|
|
+ err = payTrans.UpdatePayTransByTradeNo()
|
|
|
+ if err != nil {
|
|
|
+ payLog.ErrLog = "更新支付状态失败:err=" + err.Error()
|
|
|
+ payLog.UpdateMerchant()
|
|
|
+ c.XML(http.StatusOK, failResp)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ c.XML(http.StatusOK, successResp)
|
|
|
+
|
|
|
+}
|