Compare commits
2 Commits
93044a47c7
...
79cc31ee71
Author | SHA1 | Date |
---|---|---|
|
79cc31ee71 | |
|
b20417cb60 |
|
@ -7,6 +7,7 @@ import (
|
||||||
"PaymentCenter/app/http/entities"
|
"PaymentCenter/app/http/entities"
|
||||||
"PaymentCenter/app/http/entities/backend"
|
"PaymentCenter/app/http/entities/backend"
|
||||||
"PaymentCenter/app/models/ordersmodel"
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
|
"PaymentCenter/app/services/thirdpay"
|
||||||
"PaymentCenter/app/services/thirdpay/thirdpay_notify"
|
"PaymentCenter/app/services/thirdpay/thirdpay_notify"
|
||||||
"PaymentCenter/app/third/paymentService"
|
"PaymentCenter/app/third/paymentService"
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
@ -130,75 +131,84 @@ func queryOrder() {
|
||||||
orderInfo := order[index]
|
orderInfo := order[index]
|
||||||
|
|
||||||
// 发起查询上游支付
|
// 发起查询上游支付
|
||||||
go func(orderInfo ordersmodel.OrdersLeftPayChannelList) {
|
go func(order ordersmodel.OrdersLeftPayChannelList) {
|
||||||
defer func() {
|
defer func() {
|
||||||
<-ch
|
<-ch
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
thirdpay.OrderQueryAndNotify(ctx, &order)
|
||||||
query := paymentService.PayOrderQueryRequest{
|
|
||||||
OrderId: orderInfo.Id,
|
|
||||||
}
|
|
||||||
switch utils.PayType(orderInfo.ChannelType) {
|
|
||||||
case common.PAY_CHANNLE_TYPE_WECHAT:
|
|
||||||
wx := backend.WechatPayChannel{}
|
|
||||||
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
|
||||||
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
|
||||||
query.Wx = paymentService.WxPay{
|
|
||||||
AppId: orderInfo.AppId,
|
|
||||||
MchId: wx.MchId,
|
|
||||||
SerialNo: wx.SerialNo,
|
|
||||||
ApiV3Key: wx.ApiV3Key,
|
|
||||||
PrivateKey: wx.PrivateKey,
|
|
||||||
}
|
|
||||||
case common.PAY_CHANNLE_TYPE_ZFB:
|
|
||||||
ali := backend.AliPayChannel{}
|
|
||||||
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
|
||||||
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &ali)
|
|
||||||
query.Ali = paymentService.AliPay{
|
|
||||||
AppId: orderInfo.AppId,
|
|
||||||
PrivateKey: ali.PrivateKey,
|
|
||||||
AppPublicCert: ali.AppPublicCert,
|
|
||||||
AlipayRootCert: ali.AlipayRootCert,
|
|
||||||
AlipayPublicCert: ali.AlipayPublicCert,
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
utils.Log(nil, "查询订单,支付渠道不支持", orderInfo.ChannelType)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发起查询
|
|
||||||
result := paymentService.PayOrderQuery(ctx, query)
|
|
||||||
utils.Log(nil, "主动查询订单支付状态,上游返回数据", result)
|
|
||||||
// 查询成功,校验状态
|
|
||||||
var status int
|
|
||||||
if result.Code == payCommon.PAY_SUCCESS_CODE {
|
|
||||||
var msg string
|
|
||||||
switch result.Result.TradeState {
|
|
||||||
case "SUCCESS":
|
|
||||||
// 成功
|
|
||||||
status = common.ORDER_STATUS_PAYED
|
|
||||||
msg = "支付成功"
|
|
||||||
case "REFUND":
|
|
||||||
// 退款 订单支付完成才能退款,所以支付单的状态是支付完成
|
|
||||||
status = common.ORDER_STATUS_PAYED
|
|
||||||
msg = "已支付,发生退款"
|
|
||||||
case "NOTPAY":
|
|
||||||
// 未支付
|
|
||||||
return
|
|
||||||
case "CLOSED":
|
|
||||||
// 关闭
|
|
||||||
status = common.ORDER_STATUS_CLOSE
|
|
||||||
msg = "订单关闭"
|
|
||||||
}
|
|
||||||
// 回调通知下游
|
|
||||||
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.PayerTotal), msg)
|
|
||||||
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
|
||||||
if notifyResult.ErrCode != errorcode.Success {
|
|
||||||
utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(orderInfo)
|
}(orderInfo)
|
||||||
|
|
||||||
|
// // 发起查询上游支付
|
||||||
|
// go func(orderInfo ordersmodel.OrdersLeftPayChannelList) {
|
||||||
|
// defer func() {
|
||||||
|
// <-ch
|
||||||
|
// wg.Done()
|
||||||
|
// }()
|
||||||
|
//
|
||||||
|
// query := paymentService.PayOrderQueryRequest{
|
||||||
|
// OrderId: orderInfo.Id,
|
||||||
|
// }
|
||||||
|
// switch utils.PayType(orderInfo.ChannelType) {
|
||||||
|
// case common.PAY_CHANNLE_TYPE_WECHAT:
|
||||||
|
// wx := backend.WechatPayChannel{}
|
||||||
|
// _ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
||||||
|
// query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
||||||
|
// query.Wx = paymentService.WxPay{
|
||||||
|
// AppId: orderInfo.AppId,
|
||||||
|
// MchId: wx.MchId,
|
||||||
|
// SerialNo: wx.SerialNo,
|
||||||
|
// ApiV3Key: wx.ApiV3Key,
|
||||||
|
// PrivateKey: wx.PrivateKey,
|
||||||
|
// }
|
||||||
|
// case common.PAY_CHANNLE_TYPE_ZFB:
|
||||||
|
// ali := backend.AliPayChannel{}
|
||||||
|
// query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
||||||
|
// _ = json.Unmarshal([]byte(orderInfo.ExtJson), &ali)
|
||||||
|
// query.Ali = paymentService.AliPay{
|
||||||
|
// AppId: orderInfo.AppId,
|
||||||
|
// PrivateKey: ali.PrivateKey,
|
||||||
|
// AppPublicCert: ali.AppPublicCert,
|
||||||
|
// AlipayRootCert: ali.AlipayRootCert,
|
||||||
|
// AlipayPublicCert: ali.AlipayPublicCert,
|
||||||
|
// }
|
||||||
|
// default:
|
||||||
|
// utils.Log(nil, "查询订单,支付渠道不支持", orderInfo.ChannelType)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 发起查询
|
||||||
|
// result := paymentService.PayOrderQuery(ctx, query)
|
||||||
|
// utils.Log(nil, "主动查询订单支付状态,上游返回数据", result)
|
||||||
|
// // 查询成功,校验状态
|
||||||
|
// var status int
|
||||||
|
// if result.Code == payCommon.PAY_SUCCESS_CODE {
|
||||||
|
// var msg string
|
||||||
|
// switch result.Result.TradeState {
|
||||||
|
// case "SUCCESS":
|
||||||
|
// // 成功
|
||||||
|
// status = common.ORDER_STATUS_PAYED
|
||||||
|
// msg = "支付成功"
|
||||||
|
// case "REFUND":
|
||||||
|
// // 退款 订单支付完成才能退款,所以支付单的状态是支付完成
|
||||||
|
// status = common.ORDER_STATUS_PAYED
|
||||||
|
// msg = "已支付,发生退款"
|
||||||
|
// case "NOTPAY":
|
||||||
|
// // 未支付
|
||||||
|
// return
|
||||||
|
// case "CLOSED":
|
||||||
|
// // 关闭
|
||||||
|
// status = common.ORDER_STATUS_CLOSE
|
||||||
|
// msg = "订单关闭"
|
||||||
|
// }
|
||||||
|
// // 回调通知下游
|
||||||
|
// notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.PayerTotal), msg)
|
||||||
|
// //utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
||||||
|
// if notifyResult.ErrCode != errorcode.Success {
|
||||||
|
// utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }(orderInfo)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,13 @@ func PayPage(c *gin.Context) {
|
||||||
if orderId == "" {
|
if orderId == "" {
|
||||||
message = "页面不存在"
|
message = "页面不存在"
|
||||||
} else {
|
} else {
|
||||||
orderInfo, code = thirdpay.PayPageCheckOrder(orderId)
|
var returnUrl string
|
||||||
|
orderInfo, returnUrl, code = thirdpay.PayPageCheckOrder(orderId)
|
||||||
if code != errorcode.Success {
|
if code != errorcode.Success {
|
||||||
|
if code == errorcode.OrderPayed && returnUrl != "" {
|
||||||
|
c.Redirect(http.StatusTemporaryRedirect, returnUrl)
|
||||||
|
return
|
||||||
|
}
|
||||||
message = errorcode.GetMsg(code, "")
|
message = errorcode.GetMsg(code, "")
|
||||||
} else {
|
} else {
|
||||||
amount = fmt.Sprintf("%.2f", float64(orderInfo.Amount)/100)
|
amount = fmt.Sprintf("%.2f", float64(orderInfo.Amount)/100)
|
||||||
|
|
|
@ -106,11 +106,6 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
// 付款
|
// 付款
|
||||||
payPage.GET("/submit", front.GetPayLink)
|
payPage.GET("/submit", front.GetPayLink)
|
||||||
|
|
||||||
//router.GET(common.PayPageAddress, middlewares.ValidateRequest(), front.PayPage)
|
|
||||||
//// 收银台 支付渠道列表
|
|
||||||
//router.POST(common.FRONT_V1+"/payPage/list", middlewares.ValidateRequest(), front.PayChannelList)
|
|
||||||
//// 获取付款链接
|
|
||||||
//v1.POST("/payPage/link", middlewares.ValidateRequest(), front.GetPayLink)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
|
@ -3,6 +3,8 @@ package thirdpay
|
||||||
import (
|
import (
|
||||||
"PaymentCenter/app/constants/common"
|
"PaymentCenter/app/constants/common"
|
||||||
"PaymentCenter/app/constants/errorcode"
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/data"
|
||||||
|
"PaymentCenter/app/http/entities"
|
||||||
"PaymentCenter/app/http/entities/backend"
|
"PaymentCenter/app/http/entities/backend"
|
||||||
"PaymentCenter/app/http/entities/front"
|
"PaymentCenter/app/http/entities/front"
|
||||||
"PaymentCenter/app/models/orderrequestlogmodel"
|
"PaymentCenter/app/models/orderrequestlogmodel"
|
||||||
|
@ -17,6 +19,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/qit-team/snow-core/db"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
@ -220,13 +223,62 @@ func (this *payUrl) PayUrlV2Service() (result front.PayReqsV2Response, code int)
|
||||||
return this.result, code
|
return this.result, code
|
||||||
}
|
}
|
||||||
|
|
||||||
func PayPageCheckOrder(orderId string) (order ordersmodel.Orders, code int) {
|
// 收银台 订单查询
|
||||||
|
func PayPageCheckOrder(orderId string) (order ordersmodel.Orders, returnUrl string, code int) {
|
||||||
orderInfo := &ordersmodel.Orders{}
|
orderInfo := &ordersmodel.Orders{}
|
||||||
orderInfo, code = services.OrderFindOne(&ordersmodel.Orders{}, builder.Eq{"id": orderId})
|
orderInfo, code = services.OrderFindOne(&ordersmodel.Orders{}, builder.Eq{"id": orderId})
|
||||||
if code != errorcode.Success {
|
if code != errorcode.Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理中的订单,需要查询第三方支付平台的订单状态
|
||||||
|
if orderInfo.Status == common.ORDER_STATUS_PAYING {
|
||||||
|
ordrRepo := data.NewOrderRepo(db.GetDb())
|
||||||
|
orderPayInfo := []ordersmodel.OrdersLeftPayChannelList{}
|
||||||
|
err := ordrRepo.OrdersLeftPayChannelList(builder.Eq{"orders.id": orderInfo.Id}, entities.PageRequest{Page: 1, PageSize: 1}, &orderPayInfo)
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(nil, "订单查询失败", orderInfo)
|
||||||
|
code = handErr(err)
|
||||||
|
return
|
||||||
|
} else if len(orderPayInfo) == 1 {
|
||||||
|
OrderQueryAndNotify(context.Background(), &orderPayInfo[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 订单支付成功,需要查询订单的请求日志,不要影响正常流程
|
||||||
|
if orderInfo.Status == common.ORDER_STATUS_PAYED {
|
||||||
|
merchantRequest, _ := OrderQueryRequestLog(*orderInfo)
|
||||||
|
returnUrl = merchantRequest.ReturnUrl
|
||||||
|
}
|
||||||
|
|
||||||
code = services.OrderStatusCheck(*orderInfo)
|
code = services.OrderStatusCheck(*orderInfo)
|
||||||
return *orderInfo, code
|
return *orderInfo, returnUrl, code
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取订单的下游请求日志
|
||||||
|
func OrderQueryRequestLog(order ordersmodel.Orders) (merchantRequest front.PayReqs, code int) {
|
||||||
|
reqLog := orderrequestlogmodel.OrderRequestLog{
|
||||||
|
AppId: order.AppId,
|
||||||
|
OutTradeNo: order.OutTradeNo,
|
||||||
|
}
|
||||||
|
|
||||||
|
has, err := services.OrderRequestLogs(&reqLog)
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(nil, "商户请求订单日志查询失败", order)
|
||||||
|
code = handErr(err)
|
||||||
|
return
|
||||||
|
} else if !has {
|
||||||
|
utils.Log(nil, "商户请求订单日志不存在", order)
|
||||||
|
code = errorcode.SystemError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = json.Unmarshal([]byte(reqLog.MerchantRequest), &merchantRequest); err != nil {
|
||||||
|
utils.Log(nil, "解析商户请求订单日志失败", order)
|
||||||
|
code = handErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return merchantRequest, errorcode.Success
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
package thirdpay
|
||||||
|
|
||||||
|
import (
|
||||||
|
"PaymentCenter/app/constants/common"
|
||||||
|
"PaymentCenter/app/constants/errorcode"
|
||||||
|
"PaymentCenter/app/http/entities/backend"
|
||||||
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
|
"PaymentCenter/app/services/thirdpay/thirdpay_notify"
|
||||||
|
"PaymentCenter/app/third/paymentService"
|
||||||
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
"PaymentCenter/app/utils"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/goccy/go-json"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 发起查询上游支付,并回调下游
|
||||||
|
func OrderQueryAndNotify(ctx context.Context, orderInfo *ordersmodel.OrdersLeftPayChannelList) {
|
||||||
|
|
||||||
|
query := paymentService.PayOrderQueryRequest{
|
||||||
|
OrderId: orderInfo.Id,
|
||||||
|
}
|
||||||
|
switch utils.PayType(orderInfo.ChannelType) {
|
||||||
|
case common.PAY_CHANNLE_TYPE_WECHAT:
|
||||||
|
wx := backend.WechatPayChannel{}
|
||||||
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &wx)
|
||||||
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_WECHAT
|
||||||
|
query.Wx = paymentService.WxPay{
|
||||||
|
AppId: orderInfo.AppId,
|
||||||
|
MchId: wx.MchId,
|
||||||
|
SerialNo: wx.SerialNo,
|
||||||
|
ApiV3Key: wx.ApiV3Key,
|
||||||
|
PrivateKey: wx.PrivateKey,
|
||||||
|
}
|
||||||
|
case common.PAY_CHANNLE_TYPE_ZFB:
|
||||||
|
ali := backend.AliPayChannel{}
|
||||||
|
query.PayChannel = payCommon.PAY_CHANNLE_TYPE_ZFB
|
||||||
|
_ = json.Unmarshal([]byte(orderInfo.ExtJson), &ali)
|
||||||
|
query.Ali = paymentService.AliPay{
|
||||||
|
AppId: orderInfo.AppId,
|
||||||
|
PrivateKey: ali.PrivateKey,
|
||||||
|
AppPublicCert: ali.AppPublicCert,
|
||||||
|
AlipayRootCert: ali.AlipayRootCert,
|
||||||
|
AlipayPublicCert: ali.AlipayPublicCert,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
utils.Log(nil, "查询订单,支付渠道不支持", orderInfo.ChannelType)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发起查询
|
||||||
|
result := paymentService.PayOrderQuery(ctx, query)
|
||||||
|
utils.Log(nil, "主动查询订单支付状态,上游返回数据", result)
|
||||||
|
// 查询成功,校验状态
|
||||||
|
var status int
|
||||||
|
if result.Code == payCommon.PAY_SUCCESS_CODE {
|
||||||
|
var msg string
|
||||||
|
switch result.Result.TradeState {
|
||||||
|
case "SUCCESS":
|
||||||
|
// 成功
|
||||||
|
status = common.ORDER_STATUS_PAYED
|
||||||
|
msg = "支付成功"
|
||||||
|
case "REFUND":
|
||||||
|
// 退款 订单支付完成才能退款,所以支付单的状态是支付完成
|
||||||
|
status = common.ORDER_STATUS_PAYED
|
||||||
|
msg = "已支付,发生退款"
|
||||||
|
case "NOTPAY":
|
||||||
|
// 未支付
|
||||||
|
return
|
||||||
|
case "CLOSED":
|
||||||
|
// 关闭
|
||||||
|
status = common.ORDER_STATUS_CLOSE
|
||||||
|
msg = "订单关闭"
|
||||||
|
}
|
||||||
|
// 回调通知下游
|
||||||
|
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.PayerTotal), msg)
|
||||||
|
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
||||||
|
if notifyResult.ErrCode != errorcode.Success {
|
||||||
|
utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
||||||
"PaymentCenter/app/models/paychannelmodel"
|
"PaymentCenter/app/models/paychannelmodel"
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
|
"PaymentCenter/config"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -55,6 +56,8 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrder
|
||||||
var payOrderResponse PayOrderResponse
|
var payOrderResponse PayOrderResponse
|
||||||
switch payOrderRequest.ChannelType {
|
switch payOrderRequest.ChannelType {
|
||||||
case payCommon.PAY_CHANNEL_WECHAT_H5:
|
case payCommon.PAY_CHANNEL_WECHAT_H5:
|
||||||
|
// 由于微信H5支付return_url 必须是申请的支付域名,所以统一走支付中心的域名,支付成功后由支付中心页面进行跳转到下游地址
|
||||||
|
payOrderRequest.ReturnUrl = config.GetConf().PayService.Host + common.PayPageAddress + "?no=" + strconv.FormatInt(payOrderRequest.OrderId, 10) + "&return=true"
|
||||||
// 微信H5支付
|
// 微信H5支付
|
||||||
info, err = WxH5PayInfo(c, payOrderRequest)
|
info, err = WxH5PayInfo(c, payOrderRequest)
|
||||||
case payCommon.PAY_CHANNEL_ALIPAY_WEB:
|
case payCommon.PAY_CHANNEL_ALIPAY_WEB:
|
||||||
|
|
|
@ -113,8 +113,7 @@
|
||||||
.payment-option input[type="radio"] {
|
.payment-option input[type="radio"] {
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 选中状态样式 */
|
|
||||||
.payment-option.selected {
|
.payment-option.selected {
|
||||||
border-color: #007BFF;
|
border-color: #007BFF;
|
||||||
background-color: #f0f7ff;
|
background-color: #f0f7ff;
|
||||||
|
@ -125,7 +124,7 @@
|
||||||
{{if eq .code 200 }}
|
{{if eq .code 200 }}
|
||||||
<body>
|
<body>
|
||||||
<!-- 页面内容 -->
|
<!-- 页面内容 -->
|
||||||
<div class="payment-info">
|
<div class="payment-info" id="payment-info">
|
||||||
<h2>订单支付</h2>
|
<h2>订单支付</h2>
|
||||||
<p>{{.desc}}</p>
|
<p>{{.desc}}</p>
|
||||||
<p>交易号:{{ .id }}</p>
|
<p>交易号:{{ .id }}</p>
|
||||||
|
@ -137,12 +136,12 @@
|
||||||
<div id="pay"></div>
|
<div id="pay"></div>
|
||||||
<!-- 支付方式列表 -->
|
<!-- 支付方式列表 -->
|
||||||
<ul id="payment-list"></ul>
|
<ul id="payment-list"></ul>
|
||||||
|
</div>
|
||||||
<!-- Loading状态 -->
|
|
||||||
<div id="loading" class="loading-container" style="display: none;">
|
<!-- Loading状态 -->
|
||||||
<div class="loading-spinner"></div>
|
<div id="loading" class="loading-container" style="display: none;">
|
||||||
<p class="loading-text">支付处理中,请稍候...</p>
|
<div class="loading-spinner"></div>
|
||||||
</div>
|
<p class="loading-text">支付处理中,请稍等...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -161,94 +160,30 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否是支付回调
|
|
||||||
function isPaymentCallback() {
|
|
||||||
return getQueryParam('callback') === 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取预设的支付方式
|
|
||||||
function getPresetPaymentMethod() {
|
|
||||||
return getQueryParam('preset_method') || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查订单状态
|
|
||||||
function checkOrderStatus(orderNo) {
|
|
||||||
return fetch(`/pay/front/api/v1/payPage/status?no=${orderNo}`, {
|
|
||||||
method: 'GET',
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('网络响应不正常');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
if (data.code !== 200) {
|
|
||||||
throw new Error(data.message || '获取订单状态失败');
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示Loading状态
|
// 显示Loading状态
|
||||||
function showLoading() {
|
function showLoading() {
|
||||||
|
document.getElementById('payment-info').style.display = 'none';
|
||||||
document.getElementById('pay-container').style.display = 'none';
|
document.getElementById('pay-container').style.display = 'none';
|
||||||
document.getElementById('loading').style.display = 'flex';
|
document.getElementById('loading').style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏Loading状态
|
|
||||||
function hideLoading() {
|
|
||||||
document.getElementById('pay-container').style.display = 'block';
|
|
||||||
document.getElementById('loading').style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理支付回调
|
// 处理支付回调
|
||||||
function handlePaymentCallback() {
|
function handlePaymentCallback() {
|
||||||
const orderNo = getQueryParam('no');
|
|
||||||
if (!orderNo) {
|
|
||||||
console.error('订单号不存在');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showLoading();
|
showLoading();
|
||||||
|
const loadingText = document.querySelector('.loading-text');
|
||||||
|
loadingText.textContent = `支付处理中,请稍等...`;
|
||||||
|
|
||||||
// 检查订单状态
|
// 1秒后刷新页面
|
||||||
checkOrderStatus(orderNo)
|
setTimeout(() => {
|
||||||
.then(data => {
|
clearInterval(dotInterval);
|
||||||
if (data.data.status === 'SUCCESS') {
|
window.location.reload();
|
||||||
// 支付成功,跳转到指定链接
|
}, 1000);
|
||||||
if (data.data.redirectUrl) {
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.href = data.data.redirectUrl;
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
hideLoading();
|
|
||||||
alert('支付成功!');
|
|
||||||
}
|
|
||||||
} else if (data.data.status === 'PENDING') {
|
|
||||||
// 支付处理中,1秒后再次检查
|
|
||||||
setTimeout(() => {
|
|
||||||
handlePaymentCallback();
|
|
||||||
}, 1000);
|
|
||||||
} else {
|
|
||||||
// 支付失败或其他状态
|
|
||||||
hideLoading();
|
|
||||||
alert('支付未完成: ' + (data.data.message || '未知错误'));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
hideLoading();
|
|
||||||
console.error('检查订单状态失败:', error);
|
|
||||||
alert('检查订单状态失败: ' + error.message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取支付方式列表
|
// 获取支付方式列表
|
||||||
function fetchPaymentMethods() {
|
function fetchPaymentMethods() {
|
||||||
const id = getQueryParam('no');
|
const id = getQueryParam('no');
|
||||||
const presetMethod = getPresetPaymentMethod();
|
console.log('Order no:', id);
|
||||||
console.log('Order no:', id, 'Preset method:', presetMethod);
|
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
|
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -272,11 +207,11 @@
|
||||||
const pay = document.getElementById('pay');
|
const pay = document.getElementById('pay');
|
||||||
pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
|
pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
|
||||||
} else if (data.data.length === 1) {
|
} else if (data.data.length === 1) {
|
||||||
// 只有一个支付方式时,显示支付中状态并直接跳转
|
// 只有一个支付方式时,显示空白页并直接跳转
|
||||||
showLoading();
|
showLoading();
|
||||||
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
|
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
|
||||||
} else {
|
} else {
|
||||||
renderPaymentMethods(data.data, presetMethod);
|
renderPaymentMethods(data.data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -290,14 +225,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// 渲染支付方式列表
|
// 渲染支付方式列表
|
||||||
function renderPaymentMethods(paymentMethods, presetMethod) {
|
function renderPaymentMethods(paymentMethods) {
|
||||||
const pay = document.getElementById('pay');
|
const pay = document.getElementById('pay');
|
||||||
pay.innerHTML = '<h3>请选择支付方式</h3>';
|
pay.innerHTML = '<h3>请选择支付方式</h3>';
|
||||||
|
|
||||||
const paymentList = document.getElementById('payment-list');
|
const paymentList = document.getElementById('payment-list');
|
||||||
paymentList.innerHTML = '';
|
paymentList.innerHTML = '';
|
||||||
|
|
||||||
let hasPresetMethod = false;
|
// 标记是否是第一个支付方式
|
||||||
|
let isFirstMethod = true;
|
||||||
|
|
||||||
paymentMethods.forEach(method => {
|
paymentMethods.forEach(method => {
|
||||||
const listItem = document.createElement('li');
|
const listItem = document.createElement('li');
|
||||||
|
@ -308,12 +244,12 @@
|
||||||
radioInput.name = 'paymentMethod';
|
radioInput.name = 'paymentMethod';
|
||||||
radioInput.value = method.pay_channel_id;
|
radioInput.value = method.pay_channel_id;
|
||||||
radioInput.id = `method-${method.pay_channel_id}`;
|
radioInput.id = `method-${method.pay_channel_id}`;
|
||||||
|
|
||||||
// 检查是否是预设的支付方式
|
// 如果是第一个支付方式,默认选中
|
||||||
if (presetMethod && (method.pay_channel_id === presetMethod || method.pay_name.includes(presetMethod))) {
|
if(isFirstMethod) {
|
||||||
radioInput.checked = true;
|
radioInput.checked = true;
|
||||||
listItem.classList.add('selected');
|
listItem.classList.add('selected');
|
||||||
hasPresetMethod = true;
|
isFirstMethod = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = document.createElement('label');
|
const label = document.createElement('label');
|
||||||
|
@ -344,15 +280,6 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 如果没有匹配的预设支付方式,默认选中第一个
|
|
||||||
if (!hasPresetMethod && paymentMethods.length > 0) {
|
|
||||||
const firstItem = document.querySelector('.payment-option');
|
|
||||||
if (firstItem) {
|
|
||||||
firstItem.classList.add('selected');
|
|
||||||
firstItem.querySelector('input[type="radio"]').checked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加提交按钮
|
// 添加提交按钮
|
||||||
const submitButton = document.createElement('button');
|
const submitButton = document.createElement('button');
|
||||||
submitButton.type = 'button';
|
submitButton.type = 'button';
|
||||||
|
@ -377,7 +304,7 @@
|
||||||
|
|
||||||
// 页面加载时执行
|
// 页面加载时执行
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (isPaymentCallback()) {
|
if (getQueryParam('return')) {
|
||||||
// 如果是支付回调,处理支付结果
|
// 如果是支付回调,处理支付结果
|
||||||
handlePaymentCallback();
|
handlePaymentCallback();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue