Compare commits
4 Commits
b2722abfa9
...
79cc31ee71
Author | SHA1 | Date |
---|---|---|
|
79cc31ee71 | |
|
b20417cb60 | |
|
93044a47c7 | |
|
a9651471b6 |
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
code = services.OrderStatusCheck(*orderInfo)
|
// 处理中的订单,需要查询第三方支付平台的订单状态
|
||||||
return *orderInfo, code
|
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)
|
||||||
|
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:
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
<title>收银台页面</title>
|
<title>收银台页面</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
/* 基础样式 */
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
/* 段落样式 */
|
/* 段落样式 */
|
||||||
p {
|
p {
|
||||||
color: #666666;
|
color: #666666;
|
||||||
|
@ -23,6 +31,8 @@
|
||||||
/* 列表项样式 */
|
/* 列表项样式 */
|
||||||
li {
|
li {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 按钮样式 */
|
/* 按钮样式 */
|
||||||
|
@ -33,29 +43,107 @@
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 0.3s ease;
|
transition: background-color 0.3s ease;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 按钮悬停样式 */
|
/* 按钮悬停样式 */
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #0056b3;
|
background-color: #0056b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* loading样式 */
|
||||||
|
.loading-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
border: 5px solid #f3f3f3;
|
||||||
|
border-top: 5px solid #007BFF;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg); }
|
||||||
|
100% { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
color: #666;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 支付信息卡片 */
|
||||||
|
.payment-info {
|
||||||
|
background: #f9f9f9;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-info h2 {
|
||||||
|
margin-top: 0;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 支付方式选项 */
|
||||||
|
.payment-option {
|
||||||
|
padding: 15px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-option:hover {
|
||||||
|
border-color: #007BFF;
|
||||||
|
background-color: #f0f7ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-option input[type="radio"] {
|
||||||
|
margin-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-option.selected {
|
||||||
|
border-color: #007BFF;
|
||||||
|
background-color: #f0f7ff;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
{{if eq .code 200 }}
|
{{if eq .code 200 }}
|
||||||
<body>
|
<body>
|
||||||
<!-- 页面内容 -->
|
<!-- 页面内容 -->
|
||||||
<div>
|
<div class="payment-info" id="payment-info">
|
||||||
|
<h2>订单支付</h2>
|
||||||
<p>{{.desc}}</p>
|
<p>{{.desc}}</p>
|
||||||
<p>交易号:{{ .id }}</p>
|
<p>交易号:{{ .id }}</p>
|
||||||
<p>交易金额:{{ .amount }} 元</p>
|
<p>交易金额:<strong style="color: #ff5500; font-size: 24px;">{{ .amount }}</strong> 元</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
|
<!-- 支付方式选择区域 -->
|
||||||
|
<div id="pay-container">
|
||||||
<div id="pay"></div>
|
<div id="pay"></div>
|
||||||
<!-- 支付方式列表 -->
|
<!-- 支付方式列表 -->
|
||||||
<ul id="payment-list"></ul>
|
<ul id="payment-list"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Loading状态 -->
|
||||||
|
<div id="loading" class="loading-container" style="display: none;">
|
||||||
|
<div class="loading-spinner"></div>
|
||||||
|
<p class="loading-text">支付处理中,请稍等...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -72,6 +160,26 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 显示Loading状态
|
||||||
|
function showLoading() {
|
||||||
|
document.getElementById('payment-info').style.display = 'none';
|
||||||
|
document.getElementById('pay-container').style.display = 'none';
|
||||||
|
document.getElementById('loading').style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理支付回调
|
||||||
|
function handlePaymentCallback() {
|
||||||
|
showLoading();
|
||||||
|
const loadingText = document.querySelector('.loading-text');
|
||||||
|
loadingText.textContent = `支付处理中,请稍等...`;
|
||||||
|
|
||||||
|
// 1秒后刷新页面
|
||||||
|
setTimeout(() => {
|
||||||
|
clearInterval(dotInterval);
|
||||||
|
window.location.reload();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取支付方式列表
|
// 获取支付方式列表
|
||||||
function fetchPaymentMethods() {
|
function fetchPaymentMethods() {
|
||||||
const id = getQueryParam('no');
|
const id = getQueryParam('no');
|
||||||
|
@ -89,7 +197,6 @@
|
||||||
} else {
|
} else {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('无效');
|
throw new Error('无效');
|
||||||
}
|
}
|
||||||
|
@ -100,15 +207,17 @@
|
||||||
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();
|
||||||
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);
|
renderPaymentMethods(data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('data', data);
|
console.error('获取支付方式失败:', error);
|
||||||
|
const pay = document.getElementById('pay');
|
||||||
|
pay.innerHTML = '<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>';
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error('Order no not found in URL');
|
console.error('Order no not found in URL');
|
||||||
|
@ -122,48 +231,100 @@
|
||||||
|
|
||||||
const paymentList = document.getElementById('payment-list');
|
const paymentList = document.getElementById('payment-list');
|
||||||
paymentList.innerHTML = '';
|
paymentList.innerHTML = '';
|
||||||
|
|
||||||
|
// 标记是否是第一个支付方式
|
||||||
|
let isFirstMethod = true;
|
||||||
|
|
||||||
paymentMethods.forEach(method => {
|
paymentMethods.forEach(method => {
|
||||||
const listItem = document.createElement('li');
|
const listItem = document.createElement('li');
|
||||||
|
listItem.className = 'payment-option';
|
||||||
|
|
||||||
const radioInput = document.createElement('input');
|
const radioInput = document.createElement('input');
|
||||||
radioInput.type = 'radio';
|
radioInput.type = 'radio';
|
||||||
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}`;
|
||||||
|
|
||||||
|
// 如果是第一个支付方式,默认选中
|
||||||
|
if(isFirstMethod) {
|
||||||
|
radioInput.checked = true;
|
||||||
|
listItem.classList.add('selected');
|
||||||
|
isFirstMethod = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const label = document.createElement('label');
|
||||||
|
label.htmlFor = `method-${method.pay_channel_id}`;
|
||||||
|
label.textContent = method.pay_name;
|
||||||
|
|
||||||
|
if (method.icon_url) {
|
||||||
|
const icon = document.createElement('img');
|
||||||
|
icon.src = method.icon_url;
|
||||||
|
icon.style.height = '24px';
|
||||||
|
icon.style.marginRight = '10px';
|
||||||
|
label.prepend(icon);
|
||||||
|
}
|
||||||
|
|
||||||
listItem.appendChild(radioInput);
|
listItem.appendChild(radioInput);
|
||||||
listItem.appendChild(document.createTextNode(method.pay_name));
|
listItem.appendChild(label);
|
||||||
paymentList.appendChild(listItem);
|
paymentList.appendChild(listItem);
|
||||||
|
|
||||||
|
// 点击整个区域也可以选择
|
||||||
|
listItem.addEventListener('click', () => {
|
||||||
|
// 移除所有选中样式
|
||||||
|
document.querySelectorAll('.payment-option').forEach(item => {
|
||||||
|
item.classList.remove('selected');
|
||||||
|
});
|
||||||
|
// 添加当前选中样式
|
||||||
|
listItem.classList.add('selected');
|
||||||
|
radioInput.checked = true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 添加提交按钮
|
// 添加提交按钮
|
||||||
const submitButton = document.createElement('button');
|
const submitButton = document.createElement('button');
|
||||||
submitButton.type = 'button';
|
submitButton.type = 'button';
|
||||||
submitButton.textContent = '提交';
|
submitButton.textContent = '立即支付';
|
||||||
|
|
||||||
submitButton.onclick = function () {
|
submitButton.onclick = function () {
|
||||||
const no = getQueryParam('no');
|
const no = getQueryParam('no');
|
||||||
const selectedMethod = document.querySelector('input[name="paymentMethod"]:checked');
|
const selectedMethod = document.querySelector('input[name="paymentMethod"]:checked');
|
||||||
if (selectedMethod) {
|
if (selectedMethod) {
|
||||||
|
showLoading();
|
||||||
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${selectedMethod.value}&no=${no}`;
|
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${selectedMethod.value}&no=${no}`;
|
||||||
} else {
|
} else {
|
||||||
alert('请选择支付方式');
|
alert('请选择支付方式');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
paymentList.appendChild(submitButton);
|
|
||||||
|
const buttonContainer = document.createElement('div');
|
||||||
|
buttonContainer.style.textAlign = 'center';
|
||||||
|
buttonContainer.appendChild(submitButton);
|
||||||
|
paymentList.appendChild(buttonContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 页面加载时执行
|
||||||
// 在页面加载时调用 fetchPaymentMethods 函数
|
window.onload = function() {
|
||||||
window.onload = fetchPaymentMethods;
|
if (getQueryParam('return')) {
|
||||||
|
// 如果是支付回调,处理支付结果
|
||||||
|
handlePaymentCallback();
|
||||||
|
} else {
|
||||||
|
// 否则获取支付方式
|
||||||
|
fetchPaymentMethods();
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{ else}}
|
{{ else}}
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="payment-info" style="text-align: center;">
|
||||||
|
<h2 style="color: #ff0000;">支付异常</h2>
|
||||||
<p>{{.message}}</p>
|
<p>{{.message}}</p>
|
||||||
|
<button onclick="window.location.href='/'">返回首页</button>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue