Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a2f3b6d6e | ||
|
|
e906090ba6 | ||
|
|
077070b2cb | ||
|
|
fff616c9d0 | ||
|
|
19504a7e2b | ||
|
|
0ed85860fc | ||
|
|
e7e1cae418 | ||
|
|
69bf33e06a | ||
|
|
ae4ed8f88e | ||
|
|
112584b850 | ||
|
|
7d926f4dae | ||
|
|
f966b31324 | ||
|
|
cd656eb455 | ||
|
|
7448512a97 | ||
|
|
84b3a81daa | ||
|
|
13388f197d | ||
|
|
0185003c19 | ||
|
|
27382565de | ||
|
|
0c175e3c82 | ||
|
|
a9a94a1413 | ||
|
|
8478d47abf | ||
|
|
a3c2693417 | ||
|
|
ec98e9d54b | ||
|
|
41f29e2c77 | ||
|
|
2e1aa7e44f | ||
|
|
b1785e047f | ||
|
|
28c9b6a923 | ||
|
|
3ecd0fcfa6 | ||
|
|
a0e5cc2790 | ||
|
|
c3140ccb32 | ||
|
|
cf0b09bf0f | ||
|
|
30457a71f5 | ||
|
|
ee63905620 | ||
|
|
953eb29877 | ||
|
|
5957b01401 | ||
|
|
f0cc80f368 | ||
|
|
bdce931178 | ||
|
|
9844fc277d | ||
|
|
f39929eab7 | ||
|
|
5176296506 | ||
|
|
e303768e08 | ||
|
|
d780dafc13 | ||
|
|
9c0f9e821d | ||
|
|
35cb4b847d | ||
|
|
534030bd2f | ||
|
|
858255fd94 | ||
|
|
c953a4a8a1 | ||
|
|
52b59bd609 |
@@ -1,9 +1,14 @@
|
||||
# 监听地址,格式为 ip:port,例如 :8080
|
||||
LISTEN=127.0.0.1:8080
|
||||
|
||||
# 日志文件保存路径
|
||||
LOG=/var/log/bepusdt/
|
||||
|
||||
# SQLite 数据库文件路径(如果使用 MySQL,此项可忽略)
|
||||
SQLITE=/var/lib/bepusdt/sqlite.db
|
||||
# MySQL 数据库连接字符串(留空则使用 SQLite)
|
||||
# 格式:user:password@tcp(host:port)/database?charset=utf8mb4&parseTime=True&loc=Local
|
||||
|
||||
# MySQL 数据库
|
||||
# MYSQL_DSN=user:password@tcp(127.0.0.1:3306)/bepusdt?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s&readTimeout=10s&writeTimeout=10s
|
||||
|
||||
# PostgreSQL 数据库
|
||||
# POSTGRESQL_DSN=postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3
|
||||
@@ -0,0 +1,53 @@
|
||||
name: BUG 反馈|使用异常|功能建议|其它问题
|
||||
description: "提交在使用 BEpusdt 过程中遇到的 BUG 反馈、使用异常、对接失败等问题"
|
||||
body:
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: 完整性要求
|
||||
description: |-
|
||||
请勾选以下所有选项以证明您已经阅读并理解了以下要求,否则该 issue 将被关闭。
|
||||
options:
|
||||
- label: 我保证阅读了相关文档和 FAQ,确认问题不是由于误解功能或配置错误引起的。
|
||||
required: true
|
||||
- label: 我提供了完整环境和日志信息,而不是出于自己的判断只给出截取的部分。
|
||||
required: true
|
||||
- label: 我搜索了 issues, 没有发现已提出的类似问题。
|
||||
required: true
|
||||
- label: 问题在 Release 最新的版本上可以成功复现
|
||||
required: true
|
||||
- label: 我理解如果没有提供足够的信息,维护者可以直接关闭该 issue,而不需要进一步的解释。
|
||||
required: true
|
||||
- label: 我明白任何人针对我提交的问题没有义务提供帮助,包括项目维护者。
|
||||
required: true
|
||||
- type: dropdown
|
||||
attributes:
|
||||
label: 问题类型
|
||||
description: 请选择您遇到的问题类型
|
||||
options:
|
||||
- BUG 反馈
|
||||
- 使用异常
|
||||
- 对接失败
|
||||
- 功能建议
|
||||
- 其它问题
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: 报告描述
|
||||
description: |-
|
||||
请提供问题的详细描述。以及你认为有价值的信息。
|
||||
如果问题在更新后出现,请提供**具体**出现问题的版本号。
|
||||
validations:
|
||||
required: true
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |-
|
||||
## 日志信息
|
||||
默认的日志目录在 `/var/log/bepusdt/` 下,请将相关时间段的日志内容粘贴在下面的代码块中。
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: 日志内容
|
||||
description: 请粘贴对应的日志信息,如果有的话
|
||||
placeholder: |
|
||||
请在这里粘贴日志内容...
|
||||
render: shell
|
||||
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Telegram Group
|
||||
url: https://t.me/BEpusdtChat
|
||||
about: Telegram 交流群组
|
||||
@@ -10,17 +10,21 @@
|
||||
<img src="./static/payment/assets/img/tether.svg" width="15%" alt="tether">
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.gnu.org/licenses/gpl-3.0.html"><img src="https://img.shields.io/badge/license-GPLV3-blue" alt="license GPLV3"></a>
|
||||
<a href="https://golang.org"><img src="https://img.shields.io/badge/Golang-1.24-red" alt="Go version 1.24"></a>
|
||||
<a href="https://github.com/gin-gonic/gin">
|
||||
<img src="https://img.shields.io/badge/Gin-v1.10-blue" alt="Gin Web Framework">
|
||||
<a href="https://www.gnu.org/licenses/gpl-3.0.html">
|
||||
<img src="https://img.shields.io/github/license/v03413/bepusdt" alt="license GPLV3">
|
||||
</a>
|
||||
<a href="https://github.com/v03413/bepusdt">
|
||||
<img src="https://img.shields.io/github/v/release/v03413/bepusdt" alt="GitHub Release">
|
||||
</a>
|
||||
<a href="https://github.com/v03413/bepusdt">
|
||||
<img src="https://img.shields.io/github/downloads/v03413/bepusdt/total" alt="GitHub Release">
|
||||
</a>
|
||||
<a href="https://hub.docker.com/r/v03413/bepusdt">
|
||||
<img src="https://img.shields.io/docker/pulls/v03413/bepusdt?style=flat-square&logo=docker" alt="Docker Pulls">
|
||||
</a>
|
||||
<a href="https://github.com/gin-gonic/gin">
|
||||
<img src="https://img.shields.io/github/stars/v03413/bepusdt?style=flat-square&logo=github" alt="GitHub Stars">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## 🪧 介绍
|
||||
@@ -58,7 +62,7 @@ docker run -d --restart=unless-stopped -p 8080:8080 v03413/bepusdt:latest
|
||||
|
||||
- 安装:[Docker](docs/docker/docker.md) [Linux](docs/linux/install.md) [1Panel](./docs/1panel/README.md) [宝塔](./docs/bt_panel/README.md)
|
||||
- 开发:[API对接](docs/api/api.md) [订单回调](docs/notify/readme.md) [Python](https://github.com/luoyanglang/bepusdt-python-sdk) [PHP](https://github.com/v03413/bepusdt-php-sdk)
|
||||
- 对接:[独角数卡](docs/dujiaoka/dujiaoka.md) [异次元](./docs/acg-faka.md) [萌次元](./docs/mcy-shop.md) [彩虹易支付](https://github.com/v03413/Epay-BEpusdt) [WHMCS](https://github.com/v03413/whmcs-gateway-epusdt)
|
||||
- 对接:[独角数卡](docs/api/dujiaoka/dujiaoka.md) [彩虹易支付](https://github.com/v03413/Epay-BEpusdt) [whmcs](https://github.com/v03413/whmcs-gateway-epusdt) [其它](docs/api/other.md)
|
||||
- 其它:[https 配置](./docs/ssl.md) [时钟同步](docs/linux/systemd-timesyncd.md) [收银台修改](docs/payment-template/README.md)
|
||||
|
||||
## 🖼 功能截图
|
||||
|
||||
@@ -16,6 +16,13 @@ var MySQLDSNFlag = &cli.StringFlag{
|
||||
Sources: cli.EnvVars("MYSQL_DSN"),
|
||||
}
|
||||
|
||||
var PostgresDSNFlag = &cli.StringFlag{
|
||||
Name: "postgres",
|
||||
Value: "",
|
||||
Usage: "PostgreSQL 数据库连接字符串 (DSN),例如: postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3",
|
||||
Sources: cli.EnvVars("POSTGRESQL_DSN"),
|
||||
}
|
||||
|
||||
var LogFlag = &cli.StringFlag{
|
||||
Name: "log",
|
||||
Value: "/var/log/bepusdt/",
|
||||
|
||||
@@ -15,11 +15,12 @@ import (
|
||||
var Reset = &cli.Command{
|
||||
Name: "reset",
|
||||
Usage: "忘记密码时,此命令可重置账号密码登录入口",
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, PostgresDSNFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
dsn := c.String("mysql")
|
||||
mysql := c.String("mysql")
|
||||
postgres := c.String("postgres")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, dsn); err != nil {
|
||||
if err := model.Init(sqlite, mysql, postgres); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,11 +27,12 @@ import (
|
||||
var Start = &cli.Command{
|
||||
Name: "start",
|
||||
Usage: "启动收款网关",
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, LogFlag, ListenFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, PostgresDSNFlag, LogFlag, ListenFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
dsn := c.String("mysql")
|
||||
mysql := c.String("mysql")
|
||||
postgres := c.String("postgres")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, dsn); err != nil {
|
||||
if err := model.Init(sqlite, mysql, postgres); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
const (
|
||||
UsdtErc20 = "0xdac17f958d2ee523a2206206994597c13d831ec7"
|
||||
UsdtBep20 = "0x55d398326f99059ff775485246999027b3197955"
|
||||
UsdtXlayer = "0x1e4a5963abfd975d8c9021ce480b42188849d41d"
|
||||
UsdtXlayer = "0x779ded0c9e1022225f8e0630b35a9b54be713736"
|
||||
UsdtPlasma = "0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb"
|
||||
UsdtPolygon = "0xc2132d05d31c914a87c6611c10748aeb04b58e8f"
|
||||
UsdtArbitrum = "0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"
|
||||
|
||||
@@ -4,9 +4,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/v03413/bepusdt/app/handler/base"
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
"github.com/v03413/bepusdt/app/task/notify"
|
||||
"github.com/v03413/bepusdt/app/utils"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
@@ -31,6 +33,70 @@ type paidReq struct {
|
||||
RefHash string `json:"ref_hash"`
|
||||
}
|
||||
|
||||
type createReq struct {
|
||||
Amount float64 `json:"amount" binding:"required"`
|
||||
OrderID string `json:"order_id" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Fiat model.Fiat `json:"fiat"`
|
||||
Currencies string `json:"currencies"`
|
||||
Timeout int64 `json:"timeout"`
|
||||
}
|
||||
|
||||
func (Order) Create(ctx *gin.Context) {
|
||||
var req createReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
base.Response(ctx, 400, err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
host := utils.GetRequestHost(ctx.Request)
|
||||
|
||||
// 创建待付款订单
|
||||
order, err := model.BuildPendingOrder(model.OrderParams{
|
||||
Money: decimal.NewFromFloat(req.Amount),
|
||||
ApiType: model.OrderApiTypeAdmin, // 使用 Admin 类型
|
||||
OrderId: req.OrderID,
|
||||
Name: req.Name,
|
||||
Timeout: req.Timeout,
|
||||
Fiat: req.Fiat,
|
||||
CurrencyLimit: req.Currencies,
|
||||
})
|
||||
if err != nil {
|
||||
base.Response(ctx, 400, gin.H{
|
||||
"status": "failed",
|
||||
"message": "failed to create order: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// NotifyURL RedirectURL 同为付款链接
|
||||
url := model.CheckoutCashier(host, order.TradeId)
|
||||
|
||||
// Update order with generated URLs
|
||||
hostUri := model.GetK(model.ApiAppUri)
|
||||
if hostUri == "" {
|
||||
hostUri = host
|
||||
}
|
||||
order.NotifyUrl = hostUri + "/api/v1/pay/notify"
|
||||
order.ReturnUrl = url
|
||||
|
||||
if err := model.Db.Save(&order).Error; err != nil {
|
||||
base.Response(ctx, 400, gin.H{
|
||||
"status": "failed",
|
||||
"message": "failed to update order urls: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回响应数据
|
||||
base.Response(ctx, 200, gin.H{
|
||||
"status": "success",
|
||||
"message": "order created",
|
||||
"payment_url": url,
|
||||
})
|
||||
}
|
||||
|
||||
func (Order) List(ctx *gin.Context) {
|
||||
var req oListReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
@@ -175,9 +241,13 @@ func (Order) ManualNotify(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
go notify.Handle(order)
|
||||
if err := notify.Handle(order); err != nil {
|
||||
base.BadRequest(ctx, err.Error())
|
||||
|
||||
base.Ok(ctx, "回调已触发")
|
||||
return
|
||||
}
|
||||
|
||||
base.Ok(ctx, "订单回调成功!")
|
||||
}
|
||||
|
||||
func (Order) Del(ctx *gin.Context) {
|
||||
|
||||
@@ -13,10 +13,11 @@ type Wallet struct {
|
||||
}
|
||||
|
||||
type wAddReq struct {
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Address string `json:"address" binding:"required"`
|
||||
TradeType string `json:"trade_type" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Remark string `json:"remark"`
|
||||
Address string `json:"address" binding:"required"`
|
||||
TradeType string `json:"trade_type" binding:"required"`
|
||||
OtherNotify uint8 `json:"other_notify"`
|
||||
}
|
||||
|
||||
type wModReq struct {
|
||||
@@ -57,7 +58,7 @@ func (Wallet) Add(ctx *gin.Context) {
|
||||
MatchAddr: strings.TrimSpace(req.Address),
|
||||
TradeType: req.TradeType,
|
||||
Status: model.WaStatusEnable,
|
||||
OtherNotify: model.WaOtherDisable,
|
||||
OtherNotify: req.OtherNotify,
|
||||
}
|
||||
|
||||
if !wallet.IsValid() {
|
||||
|
||||
@@ -271,6 +271,28 @@ func (Auth) Menu(ctx *gin.Context) {
|
||||
},
|
||||
{
|
||||
Id: "06",
|
||||
Path: "/create-order",
|
||||
Name: "create-order",
|
||||
Component: "order/create-order",
|
||||
Meta: meta{
|
||||
Title: "create-order",
|
||||
Hide: false,
|
||||
Disable: false,
|
||||
KeepAlive: true,
|
||||
Affix: false,
|
||||
Link: "",
|
||||
Iframe: false,
|
||||
IsFull: false,
|
||||
Roles: []string{"admin"},
|
||||
SvgIcon: "form",
|
||||
Icon: "",
|
||||
Sort: 1,
|
||||
Type: 2,
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
{
|
||||
Id: "07",
|
||||
Path: "/github-api-doc",
|
||||
Name: "github-api-doc",
|
||||
Component: "about/doc",
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -32,11 +34,46 @@ type createReq struct {
|
||||
Rate string `json:"rate"`
|
||||
}
|
||||
|
||||
type createOrderReq struct {
|
||||
Amount float64 `json:"amount" binding:"required"`
|
||||
OrderID string `json:"order_id" binding:"required"`
|
||||
NotifyURL string `json:"notify_url" binding:"required"`
|
||||
RedirectURL string `json:"redirect_url" binding:"required"`
|
||||
Signature string `json:"signature" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
Fiat model.Fiat `json:"fiat"`
|
||||
Currencies string `json:"currencies"`
|
||||
Timeout int64 `json:"timeout"`
|
||||
}
|
||||
|
||||
type updateOrderReq struct {
|
||||
TradeID string `json:"trade_id" binding:"required"`
|
||||
Currency string `json:"currency" binding:"required"`
|
||||
Network string `json:"network" binding:"required"`
|
||||
}
|
||||
|
||||
type cancelReq struct {
|
||||
TradeID string `json:"trade_id" binding:"required"`
|
||||
Signature string `json:"signature" binding:"required"`
|
||||
}
|
||||
|
||||
type methodsReq struct {
|
||||
TradeID string `json:"trade_id" binding:"required"`
|
||||
Currency string `json:"currency"`
|
||||
}
|
||||
|
||||
type PaymentItem struct {
|
||||
Amount string `json:"amount"`
|
||||
ActualAmount string `json:"actual_amount"`
|
||||
Fiat string `json:"fiat"`
|
||||
ExchangeRate string `json:"exchange_rate"`
|
||||
Currency string `json:"currency"`
|
||||
Network string `json:"network"`
|
||||
TokenNetName string `json:"token_net_name"`
|
||||
TokenCustomName string `json:"token_custom_name"`
|
||||
IsPopular bool `json:"is_popular"`
|
||||
}
|
||||
|
||||
func (Epusdt) SignVerify(ctx *gin.Context) {
|
||||
rawData, err := ctx.GetRawData()
|
||||
if err != nil {
|
||||
@@ -73,10 +110,38 @@ func (Epusdt) SignVerify(ctx *gin.Context) {
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
var req createReq
|
||||
func (Epusdt) Notify(ctx *gin.Context) {
|
||||
rawData, err := ctx.GetRawData()
|
||||
if err != nil {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
m := make(map[string]any)
|
||||
if err = json.Unmarshal(rawData, &m); err != nil {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
sign, ok := m["signature"]
|
||||
if !ok {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
if utils.EpusdtSign(m, model.AuthToken()) != sign {
|
||||
ctx.String(200, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.String(200, "ok")
|
||||
}
|
||||
|
||||
// CreateOrder Order creation API
|
||||
func (Epusdt) CreateOrder(ctx *gin.Context) {
|
||||
var req createOrderReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("请求参数错误:%s", err.Error())))
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("CreateOrder: request error: %s", err.Error())))
|
||||
|
||||
return
|
||||
}
|
||||
@@ -87,6 +152,116 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
host = "https://" + ctx.Request.Host
|
||||
}
|
||||
|
||||
if req.Fiat == "" {
|
||||
req.Fiat = model.CNY
|
||||
}
|
||||
|
||||
// 创建待付款订单
|
||||
order, err := model.BuildPendingOrder(model.OrderParams{
|
||||
Money: decimal.NewFromFloat(req.Amount),
|
||||
ApiType: model.OrderApiTypeEpusdt,
|
||||
OrderId: req.OrderID,
|
||||
RedirectUrl: req.RedirectURL,
|
||||
NotifyUrl: req.NotifyURL,
|
||||
Name: req.Name,
|
||||
Timeout: req.Timeout,
|
||||
Fiat: req.Fiat,
|
||||
CurrencyLimit: req.Currencies,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("CreateOrder: order create failed: %s", err.Error())))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info(fmt.Sprintf("订单创建成功 商户订单:%s", req.OrderID))
|
||||
|
||||
// 返回响应数据
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"fiat": order.Fiat,
|
||||
"trade_id": order.TradeId,
|
||||
"order_id": order.OrderId,
|
||||
"name": order.Name,
|
||||
"status": order.Status,
|
||||
"amount": order.Money,
|
||||
"expiration_time": uint64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCashier(host, order.TradeId),
|
||||
"network": GetPaymentItem("", order),
|
||||
}))
|
||||
}
|
||||
|
||||
// UpdateOrder 更新订单,返回付款链接。更新订单不需要签名,因为创建订单时已经验证,只需要提交参数更新订单即可。
|
||||
func (Epusdt) UpdateOrder(ctx *gin.Context) {
|
||||
// 接收 trade_id, currency, network 三个参数
|
||||
var req updateOrderReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("UpdateOrder: request error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// 解析请求地址
|
||||
host := "http://" + ctx.Request.Host
|
||||
if ctx.Request.TLS != nil {
|
||||
host = "https://" + ctx.Request.Host
|
||||
}
|
||||
|
||||
// 获取订单
|
||||
order, ok := model.GetTradeOrder(req.TradeID)
|
||||
if !ok {
|
||||
ctx.JSON(200, respFailJson("order not found"))
|
||||
return
|
||||
}
|
||||
|
||||
// 根据 currency 和 network 解析出 TradeType
|
||||
tradeType, err := model.GetTradeTypeByCurrencyAndNetwork(req.Currency, req.Network)
|
||||
if err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("UpdateOrder: unsupported payment method: %s - %s", req.Currency, req.Network)))
|
||||
return
|
||||
}
|
||||
|
||||
// 重建订单(更新支付方式)
|
||||
// 注意:RebuildOrder 需要 OrderParams,我们需要从现有订单构造参数
|
||||
money, _ := decimal.NewFromString(order.Money)
|
||||
params := model.OrderParams{
|
||||
Money: money,
|
||||
OrderId: order.OrderId,
|
||||
TradeType: tradeType, // 新的交易类型
|
||||
RedirectUrl: order.ReturnUrl,
|
||||
NotifyUrl: order.NotifyUrl,
|
||||
Name: order.Name,
|
||||
Timeout: int64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
Fiat: order.Fiat,
|
||||
}
|
||||
|
||||
newOrder, err := model.RebuildOrder(order, params)
|
||||
if err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("update order failed: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// 返回响应数据
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"fiat": newOrder.Fiat,
|
||||
"trade_type": newOrder.TradeType,
|
||||
"trade_id": newOrder.TradeId,
|
||||
"order_id": newOrder.OrderId,
|
||||
"status": newOrder.Status,
|
||||
"amount": newOrder.Money,
|
||||
"actual_amount": newOrder.Amount,
|
||||
"token": newOrder.Address,
|
||||
"expiration_time": uint64(newOrder.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCounter(host, newOrder.TradeId),
|
||||
}))
|
||||
}
|
||||
|
||||
func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
var req createReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(200, respFailJson(fmt.Sprintf("请求参数错误:%s", err.Error())))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if req.Fiat == "" {
|
||||
req.Fiat = model.CNY
|
||||
}
|
||||
@@ -126,7 +301,7 @@ func (Epusdt) CreateTransaction(ctx *gin.Context) {
|
||||
"actual_amount": order.Amount,
|
||||
"token": order.Address,
|
||||
"expiration_time": uint64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCounter(host, order.TradeId),
|
||||
"payment_url": model.CheckoutCounter(utils.GetRequestHost(ctx.Request), order.TradeId),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -192,6 +367,37 @@ func (Epusdt) CheckoutCounter(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (Epusdt) CheckoutCashier(ctx *gin.Context) {
|
||||
tradeId := ctx.Param("trade_id")
|
||||
order, ok := model.GetTradeOrder(tradeId)
|
||||
if !ok {
|
||||
ctx.String(200, "order not found")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
uri, err := url.ParseRequestURI(order.ReturnUrl)
|
||||
if err != nil {
|
||||
ctx.String(200, "sync address error")
|
||||
log.Error("CheckoutCashier: sync address error: ", err.Error())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, "cashier.html", gin.H{
|
||||
"http_host": uri.Host,
|
||||
"amount": order.Amount,
|
||||
"expire": int64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"return_url": order.ReturnUrl,
|
||||
"trade_id": tradeId,
|
||||
"order_id": order.OrderId,
|
||||
"name": order.Name,
|
||||
"money": order.Money,
|
||||
"fiat": order.Fiat,
|
||||
"network": GetPaymentItem("", order),
|
||||
})
|
||||
}
|
||||
|
||||
func (Epusdt) CheckStatus(ctx *gin.Context) {
|
||||
tradeId := ctx.Param("trade_id")
|
||||
order, ok := model.GetTradeOrder(tradeId)
|
||||
@@ -219,6 +425,116 @@ func (Epusdt) CheckStatus(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
var req methodsReq
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(500, respFailJson(fmt.Sprintf("request error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
order, ok := model.GetTradeOrder(req.TradeID)
|
||||
if !ok {
|
||||
ctx.JSON(400, respFailJson("order not found"))
|
||||
return
|
||||
}
|
||||
|
||||
if order.Status == model.OrderStatusExpired {
|
||||
ctx.JSON(400, respFailJson("order expired"))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"methods": GetPaymentItem(model.Crypto(req.Currency), order),
|
||||
}))
|
||||
}
|
||||
|
||||
func GetPaymentItem(crypto model.Crypto, order model.Order) []PaymentItem {
|
||||
fiat := order.Fiat
|
||||
|
||||
var methods = make([]PaymentItem, 0)
|
||||
allTrades := model.GetAllTradeConfig()
|
||||
|
||||
// 解析限定币种
|
||||
var whitelist = make(map[string]bool)
|
||||
var blacklist = make(map[string]bool)
|
||||
if order.CurrencyLimit != "" {
|
||||
for _, c := range strings.Split(order.CurrencyLimit, ",") {
|
||||
c = strings.TrimSpace(c)
|
||||
if strings.HasPrefix(c, "-") {
|
||||
blacklist[strings.ToUpper(strings.TrimPrefix(c, "-"))] = true
|
||||
} else {
|
||||
whitelist[strings.ToUpper(c)] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for tradeTypeStr, conf := range allTrades {
|
||||
// 如果指定了货币,则进行过滤
|
||||
if crypto != "" && conf.Crypto != crypto {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check blacklist
|
||||
if len(blacklist) > 0 && blacklist[string(conf.Crypto)] {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check whitelist
|
||||
if len(whitelist) > 0 && !whitelist[string(conf.Crypto)] {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查是否有可用钱包
|
||||
count := len(model.GetAvailableAddress(model.TradeType(tradeTypeStr)))
|
||||
if count == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 获取汇率配置的浮动语法
|
||||
syntax := model.GetK(model.ConfKey(fmt.Sprintf("rate_float_%s_%s", conf.Crypto, fiat)))
|
||||
|
||||
// 获取汇率
|
||||
rate, err := model.GetOrderRate(conf.Crypto, fiat, syntax)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("GetPaymentMethods: get order rate error: %s", err.Error()))
|
||||
continue
|
||||
}
|
||||
|
||||
// 计算实际支付金额 (加密货币)
|
||||
// Money 是法币金额
|
||||
moneyDecimal, _ := decimal.NewFromString(order.Money)
|
||||
|
||||
// 计算精度
|
||||
atom, precision := model.GetAtomicity(model.TradeType(tradeTypeStr))
|
||||
actualAmount := moneyDecimal.DivRound(rate, precision)
|
||||
if actualAmount.LessThan(atom) {
|
||||
actualAmount = atom
|
||||
}
|
||||
|
||||
methods = append(methods, PaymentItem{
|
||||
Amount: order.Money,
|
||||
ActualAmount: actualAmount.String(),
|
||||
Fiat: string(fiat),
|
||||
ExchangeRate: rate.String(),
|
||||
Currency: string(conf.Crypto),
|
||||
Network: string(conf.Network),
|
||||
TokenNetName: conf.NetworkName,
|
||||
TokenCustomName: "", // 暂为空
|
||||
IsPopular: false, // 暂为 false
|
||||
})
|
||||
}
|
||||
|
||||
// Sort by Currency A-Z
|
||||
sort.Slice(methods, func(i, j int) bool {
|
||||
if methods[i].Currency != methods[j].Currency {
|
||||
return methods[i].Currency < methods[j].Currency
|
||||
}
|
||||
return methods[i].Network < methods[j].Network
|
||||
})
|
||||
|
||||
return methods
|
||||
}
|
||||
|
||||
func respFailJson(message string) gin.H {
|
||||
|
||||
return gin.H{"status_code": 400, "message": message}
|
||||
|
||||
@@ -6,13 +6,14 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/natefinch/lumberjack"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
Task *logrus.Logger
|
||||
bepusdt *logrus.Logger
|
||||
logFiles []*os.File
|
||||
Task *logrus.Logger
|
||||
be *logrus.Logger
|
||||
loggers []*lumberjack.Logger
|
||||
)
|
||||
|
||||
func newLogger(file string) (*logrus.Logger, error) {
|
||||
@@ -25,15 +26,16 @@ func newLogger(file string) (*logrus.Logger, error) {
|
||||
})
|
||||
|
||||
logger.SetLevel(logrus.InfoLevel)
|
||||
|
||||
output, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
output := &lumberjack.Logger{
|
||||
Filename: file,
|
||||
MaxSize: 300,
|
||||
MaxBackups: 5,
|
||||
MaxAge: 7,
|
||||
Compress: true,
|
||||
}
|
||||
|
||||
// 保存文件句柄
|
||||
logFiles = append(logFiles, output)
|
||||
logger.SetOutput(output)
|
||||
loggers = append(loggers, output)
|
||||
|
||||
return logger, nil
|
||||
}
|
||||
@@ -46,7 +48,7 @@ func Init(dir string) error {
|
||||
|
||||
var err error
|
||||
|
||||
bepusdt, err = newLogger(filepath.Join(dir, "bepusdt.log"))
|
||||
be, err = newLogger(filepath.Join(dir, "bepusdt.log"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -60,39 +62,34 @@ func Init(dir string) error {
|
||||
}
|
||||
|
||||
func Debug(args ...interface{}) {
|
||||
bepusdt.Debugln(args...)
|
||||
be.Debugln(args...)
|
||||
}
|
||||
|
||||
func Info(args ...interface{}) {
|
||||
bepusdt.Infoln(args...)
|
||||
be.Infoln(args...)
|
||||
}
|
||||
|
||||
func Error(args ...interface{}) {
|
||||
bepusdt.Errorln(args...)
|
||||
be.Errorln(args...)
|
||||
}
|
||||
|
||||
func Warn(args ...interface{}) {
|
||||
bepusdt.Warnln(args...)
|
||||
be.Warnln(args...)
|
||||
}
|
||||
|
||||
func GetWriter() *io.PipeWriter {
|
||||
|
||||
return bepusdt.Writer()
|
||||
return be.Writer()
|
||||
}
|
||||
|
||||
func Close() {
|
||||
var lastErr error
|
||||
for _, f := range logFiles {
|
||||
for _, f := range loggers {
|
||||
if f != nil {
|
||||
if err := f.Close(); err != nil {
|
||||
lastErr = err
|
||||
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("日志句柄资源关闭错误:%s", err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logFiles = nil
|
||||
|
||||
if lastErr != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("日志句柄资源关闭错误:%s", lastErr.Error()))
|
||||
}
|
||||
loggers = nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (c Conf) TableName() string {
|
||||
|
||||
func SetK(k ConfKey, v string) {
|
||||
if err = Db.Transaction(func(db *gorm.DB) error {
|
||||
if err2 := db.Where("`k` = ?", k).Delete(&Conf{}).Error; err2 != nil {
|
||||
if err2 := db.Where("k = ?", k).Delete(&Conf{}).Error; err2 != nil {
|
||||
|
||||
return err2
|
||||
}
|
||||
@@ -105,6 +105,15 @@ func CheckoutCounter(host, id string) string {
|
||||
return fmt.Sprintf("%s/pay/checkout-counter/%s", uri, id)
|
||||
}
|
||||
|
||||
func CheckoutCashier(host, id string) string {
|
||||
uri := GetK(ApiAppUri)
|
||||
if uri == "" {
|
||||
uri = host
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/pay/cashier/%s", uri, id)
|
||||
}
|
||||
|
||||
func ConfInit() {
|
||||
var hash = utils.StrSha256(utils.Md5String(time.Now().String()))
|
||||
var secure = "/" + hash[:10]
|
||||
@@ -113,36 +122,39 @@ func ConfInit() {
|
||||
var password = hash[20:30]
|
||||
var encrypt, _ = bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
var data = map[ConfKey]string{
|
||||
ApiAppUri: "",
|
||||
ApiAuthToken: token,
|
||||
AdminSecure: secure,
|
||||
AdminUsername: username,
|
||||
AdminPassword: string(encrypt),
|
||||
RateSyncInterval: "3600",
|
||||
AtomUSDT: "0.01",
|
||||
AtomUSDC: "0.01",
|
||||
AtomTRX: "0.01",
|
||||
AtomBNB: "0.00001",
|
||||
AtomETH: "0.000001",
|
||||
MonitorMinAmount: "0.01",
|
||||
PaymentMinAmount: "0.01",
|
||||
PaymentMaxAmount: "99999",
|
||||
RpcEndpointTron: "grpc.trongrid.io:50051",
|
||||
RpcEndpointBsc: "https://binance-smart-chain-public.nodies.app/",
|
||||
RpcEndpointSolana: "https://solana-rpc.publicnode.com/",
|
||||
RpcEndpointXlayer: "https://xlayerrpc.okx.com/",
|
||||
RpcEndpointPolygon: "https://polygon-public.nodies.app/",
|
||||
RpcEndpointArbitrum: "https://arb1.arbitrum.io/rpc",
|
||||
RpcEndpointEthereum: "https://ethereum-public.nodies.app/",
|
||||
RpcEndpointBase: "https://base-public.nodies.app/",
|
||||
RpcEndpointAptos: "https://aptos-rest.publicnode.com/",
|
||||
RpcEndpointPlasma: "https://rpc.plasma.to/",
|
||||
NotifyMaxRetry: "10",
|
||||
BlockHeightMaxDiff: "1000",
|
||||
PaymentTimeout: "1200", // 20分钟
|
||||
PaymentStaticPath: "",
|
||||
PaymentMatchMode: string(Classic),
|
||||
SystemInstallLock: "0",
|
||||
ApiAppUri: "",
|
||||
ApiAuthToken: token,
|
||||
AdminSecure: secure,
|
||||
AdminUsername: username,
|
||||
AdminPassword: string(encrypt),
|
||||
RateSyncInterval: "3600",
|
||||
AtomUSDT: "0.01",
|
||||
AtomUSDC: "0.01",
|
||||
AtomTRX: "0.01",
|
||||
AtomBNB: "0.00001",
|
||||
AtomETH: "0.000001",
|
||||
MonitorMinAmount: "0.01",
|
||||
PaymentMinAmount: "0.01",
|
||||
PaymentMaxAmount: "99999",
|
||||
RpcEndpointTron: "grpc.trongrid.io:50051",
|
||||
RpcEndpointBsc: "https://binance-smart-chain-public.nodies.app/",
|
||||
RpcEndpointSolana: "https://solana-rpc.publicnode.com/",
|
||||
RpcEndpointXlayer: "https://xlayerrpc.okx.com/",
|
||||
RpcEndpointPolygon: "https://polygon-public.nodies.app/",
|
||||
RpcEndpointArbitrum: "https://arb1.arbitrum.io/rpc",
|
||||
RpcEndpointEthereum: "https://ethereum-public.nodies.app/",
|
||||
RpcEndpointBase: "https://base-public.nodies.app/",
|
||||
RpcEndpointAptos: "https://aptos-rest.publicnode.com/",
|
||||
RpcEndpointPlasma: "https://rpc.plasma.to/",
|
||||
NotifyMaxRetry: "10",
|
||||
BlockHeightMaxDiff: "1000",
|
||||
BlockOffsetConfirm: "0",
|
||||
PaymentTimeout: "1200", // 20分钟
|
||||
PaymentStaticPath: "",
|
||||
PaymentMatchMode: string(Classic),
|
||||
SystemInstallLock: "0",
|
||||
RateSyncCoingeckoApiUrl: "https://api.coingecko.com",
|
||||
RateSyncCoingeckoApiKey: "",
|
||||
}
|
||||
|
||||
var rows = make([]Conf, 0)
|
||||
|
||||
@@ -15,6 +15,7 @@ type Range struct {
|
||||
}
|
||||
type TradeTypeConf struct {
|
||||
Alias string // 类型别名,主要用户前端展示
|
||||
NetworkName string // 网络名称,用于前端展示
|
||||
Network Network // 所属区块链网络
|
||||
Crypto Crypto // 币种类型
|
||||
Native bool // 是否原生币
|
||||
@@ -61,9 +62,12 @@ const (
|
||||
RpcEndpointTron ConfKey = "rpc_endpoint_tron" // TRON RPC节点
|
||||
RpcEndpointTronGridApiKey ConfKey = "rpc_endpoint_tron_grid_api_key" // TRON RPC节点 TronGrid Api Key
|
||||
|
||||
RateSyncInterval ConfKey = "rate_sync_interval" // 汇率同步间隔,单位秒
|
||||
NotifyMaxRetry ConfKey = "notify_max_retry" // 最大重试次数,订单回调失败
|
||||
BlockHeightMaxDiff ConfKey = "block_height_max_diff" // 区块高度最大差值,超过此值则以当前区块高度为准,重新开始扫描
|
||||
RateSyncCoingeckoApiUrl ConfKey = "rate_sync_coingecko_api_url" // 汇率同步 Coingecko Api URL
|
||||
RateSyncCoingeckoApiKey ConfKey = "rate_sync_coingecko_api_key" // 汇率同步 Coingecko Api Key
|
||||
RateSyncInterval ConfKey = "rate_sync_interval" // 汇率同步间隔,单位秒
|
||||
NotifyMaxRetry ConfKey = "notify_max_retry" // 最大重试次数,订单回调失败
|
||||
BlockHeightMaxDiff ConfKey = "block_height_max_diff" // 区块高度最大差值,超过此值则以当前区块高度为准,重新开始扫描
|
||||
BlockOffsetConfirm ConfKey = "block_offset_confirm" // 区块偏移确认数,扫描时以当前区块高度减去此偏移量为准,避免重链导致的订单回调失败
|
||||
|
||||
NotifierParams ConfKey = "notifier_params" // 通知参数 (token, chat_id, email
|
||||
NotifierChannel ConfKey = "notifier_channel" // 通知渠道 (telegram, wechat, email
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -19,14 +20,16 @@ type Id struct {
|
||||
}
|
||||
|
||||
type AutoTimeAt struct {
|
||||
CreatedAt *Datetime `gorm:"column:created_at;type:Datetime;not null;comment:记录创建时间;index" json:"created_at"`
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;type:Datetime;not null;comment:最后更新时间" json:"updated_at"`
|
||||
CreatedAt *Datetime `gorm:"column:created_at;not null;comment:记录创建时间;index" json:"created_at"`
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;not null;comment:最后更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func Init(path, dsn string) error {
|
||||
if dsn != "" {
|
||||
|
||||
return initMySQL(dsn)
|
||||
func Init(path, mysql, postgres string) error {
|
||||
if postgres != "" {
|
||||
return initPostgres(postgres)
|
||||
}
|
||||
if mysql != "" {
|
||||
return initMySQL(mysql)
|
||||
}
|
||||
|
||||
return initSqlite(path)
|
||||
@@ -120,6 +123,45 @@ func initMySQL(dsn string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func initPostgres(dsn string) error {
|
||||
// 首次启动可能出现 SLOW SQL 告警,这是由于连接池首次连接预热引起的,后续连接将正常
|
||||
|
||||
var err error
|
||||
Db, err = gorm.Open(postgres.New(postgres.Config{DSN: dsn, PreferSimpleProtocol: true}), &gorm.Config{})
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
{
|
||||
sqlDB, err := Db.DB()
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
sqlDB.SetMaxIdleConns(10)
|
||||
sqlDB.SetMaxOpenConns(100)
|
||||
sqlDB.SetConnMaxLifetime(30 * time.Minute)
|
||||
sqlDB.SetConnMaxIdleTime(10 * time.Minute)
|
||||
}
|
||||
|
||||
if err = AutoMigrate(); err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var count int64
|
||||
Db.Model(&Conf{}).Count(&count)
|
||||
if count == 0 {
|
||||
ConfInit()
|
||||
}
|
||||
|
||||
RefreshC()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func AutoMigrate() error {
|
||||
return Db.AutoMigrate(&Wallet{}, &Order{}, &NotifyRecord{}, &Conf{}, &Rate{})
|
||||
}
|
||||
|
||||
@@ -49,33 +49,35 @@ const (
|
||||
const (
|
||||
OrderApiTypeEpusdt = "epusdt" // epusdt
|
||||
OrderApiTypeEpay = "epay" // 彩虹易支付
|
||||
OrderApiTypeAdmin = "admin" // 管理后台
|
||||
)
|
||||
|
||||
var calcMutex sync.Mutex
|
||||
|
||||
type Order struct {
|
||||
Id
|
||||
OrderId string `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID" json:"order_id"`
|
||||
TradeId string `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID" json:"trade_id"`
|
||||
TradeType TradeType `gorm:"column:trade_type;type:varchar(20);not null;index;comment:交易类型" json:"trade_type"`
|
||||
Fiat Fiat `gorm:"column:fiat;type:varchar(16);not null;index;default:CNY;comment:法定货币" json:"fiat"`
|
||||
Crypto Crypto `gorm:"column:crypto;type:varchar(16);not null;index;default:USDT;comment:加密货币" json:"crypto"`
|
||||
Rate string `gorm:"column:rate;type:varchar(10);not null;comment:交易汇率" json:"rate"`
|
||||
Amount string `gorm:"column:amount;type:varchar(32);not null;default:0.00;comment:交易数额" json:"amount"`
|
||||
Money string `gorm:"column:money;type:varchar(32);not null;default:0.00;comment:交易金额" json:"money"`
|
||||
Address string `gorm:"column:address;type:varchar(128);index;not null;comment:收款地址" json:"address"`
|
||||
FromAddress string `gorm:"column:from_address;type:varchar(128);not null;default:'';comment:支付地址" json:"from_address"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);not null;default:1;index;comment:交易状态" json:"status"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
|
||||
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:varchar(255);not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:varchar(255);not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
NotifyNum int `gorm:"column:notify_num;type:int(11);not null;default:0;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;type:tinyint(1);not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
|
||||
RefBlockNum int64 `gorm:"column:ref_block_num;type:varchar(64);not null;default:0;comment:区块索引" json:"ref_block_num"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at;type:datetime;not null;comment:失效时间" json:"expired_at"`
|
||||
ConfirmedAt *time.Time `gorm:"column:confirmed_at;type:datetime;not null;comment:交易确认时间" json:"confirmed_at"`
|
||||
OrderId string `gorm:"column:order_id;type:varchar(128);not null;index;comment:商户ID" json:"order_id"`
|
||||
TradeId string `gorm:"column:trade_id;type:varchar(128);not null;uniqueIndex;comment:本地ID" json:"trade_id"`
|
||||
TradeType TradeType `gorm:"column:trade_type;type:varchar(20);not null;index;comment:交易类型" json:"trade_type"`
|
||||
Fiat Fiat `gorm:"column:fiat;type:varchar(16);not null;index;default:CNY;comment:法定货币" json:"fiat"`
|
||||
Crypto Crypto `gorm:"column:crypto;type:varchar(16);not null;index;default:USDT;comment:加密货币" json:"crypto"`
|
||||
CurrencyLimit string `gorm:"column:currency_limit;type:varchar(255);not null;default:'';comment:限定币种" json:"currency_limit"`
|
||||
Rate string `gorm:"column:rate;type:varchar(10);not null;comment:交易汇率" json:"rate"`
|
||||
Amount string `gorm:"column:amount;type:varchar(32);not null;default:0.00;comment:交易数额" json:"amount"`
|
||||
Money string `gorm:"column:money;type:varchar(32);not null;default:0.00;comment:交易金额" json:"money"`
|
||||
Address string `gorm:"column:address;type:varchar(128);index;not null;comment:收款地址" json:"address"`
|
||||
FromAddress string `gorm:"column:from_address;type:varchar(128);not null;default:'';comment:支付地址" json:"from_address"`
|
||||
Status int `gorm:"column:status;not null;default:1;index;comment:交易状态" json:"status"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
|
||||
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:varchar(255);not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:varchar(255);not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
NotifyNum int `gorm:"column:notify_num;not null;default:0;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
|
||||
RefBlockNum int `gorm:"column:ref_block_num;not null;default:0;comment:区块索引" json:"ref_block_num"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at;not null;comment:失效时间" json:"expired_at"`
|
||||
ConfirmedAt *time.Time `gorm:"column:confirmed_at;not null;comment:交易确认时间" json:"confirmed_at"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
@@ -103,11 +105,11 @@ func (o *Order) SetFailed() {
|
||||
Db.Save(o)
|
||||
}
|
||||
|
||||
func (o *Order) MarkConfirming(blockNum int64, from, hash string, at time.Time) {
|
||||
func (o *Order) MarkConfirming(blockNum int, from, hash string, at time.Time) {
|
||||
o.FromAddress = from
|
||||
o.ConfirmedAt = &at
|
||||
o.RefHash = hash
|
||||
o.RefBlockNum = blockNum
|
||||
o.RefBlockNum = int(blockNum)
|
||||
o.Status = OrderStatusConfirming
|
||||
|
||||
Db.Save(o)
|
||||
|
||||
@@ -58,9 +58,17 @@ func CoingeckoRate() error {
|
||||
tokens[id] = token
|
||||
}
|
||||
|
||||
var url = fmt.Sprintf("https://api.coingecko.com/api/v3/simple/price?ids=%s&vs_currencies=%s", strings.Join(ids, ","), strings.Join(fiats, ","))
|
||||
var url = fmt.Sprintf("%s/api/v3/simple/price?ids=%s&vs_currencies=%s", GetC(RateSyncCoingeckoApiUrl), strings.Join(ids, ","), strings.Join(fiats, ","))
|
||||
var client = &http.Client{Timeout: 15 * time.Second}
|
||||
resp, err := client.Get(url)
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("x-cg-demo-api-key", GetC(RateSyncCoingeckoApiKey))
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
@@ -75,13 +83,13 @@ func CoingeckoRate() error {
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
||||
return errors.New("响应异常 StatusCode != 200")
|
||||
return errors.New("CoingeckoRate: " + http.StatusText(resp.StatusCode))
|
||||
}
|
||||
|
||||
var data = gjson.ParseBytes(body)
|
||||
if data.Get("status.error_code").Exists() {
|
||||
|
||||
return errors.New(data.Get("status.error_message").String())
|
||||
return errors.New("CoingeckoRate: " + data.Get("status.error_message").String())
|
||||
}
|
||||
|
||||
var rows = make([]Rate, 0)
|
||||
@@ -104,7 +112,7 @@ func CoingeckoRate() error {
|
||||
|
||||
if len(rows) == 0 {
|
||||
|
||||
return errors.New("响应无数据")
|
||||
return errors.New("CoingeckoRate: no data")
|
||||
}
|
||||
|
||||
Db.Create(&rows)
|
||||
@@ -163,7 +171,7 @@ func round(val float64, precision int) float64 {
|
||||
return math.Floor(val*p+0.5) / p
|
||||
}
|
||||
|
||||
func getOrderRate(token Crypto, fiat Fiat, syntax string) (decimal.Decimal, error) {
|
||||
func GetOrderRate(token Crypto, fiat Fiat, syntax string) (decimal.Decimal, error) {
|
||||
var r Rate
|
||||
Db.Where("crypto = ? and fiat = ?", token, fiat).Order("created_at desc").Limit(1).Find(&r)
|
||||
if r.ID == 0 {
|
||||
|
||||
@@ -30,6 +30,7 @@ var supportCrypto = map[Crypto]CoinId{
|
||||
var registry = map[TradeType]TradeTypeConf{
|
||||
UsdtPlasma: {
|
||||
Alias: "USDT・Plasma",
|
||||
NetworkName: "Plasma",
|
||||
Network: conf.Plasma,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtPlasma,
|
||||
@@ -40,6 +41,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtTrc20: {
|
||||
Alias: "USDT・TRC20",
|
||||
NetworkName: "TRC20",
|
||||
Network: conf.Tron,
|
||||
Crypto: USDT,
|
||||
Contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", // 占位,目前实际没使用
|
||||
@@ -51,6 +53,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtErc20: {
|
||||
Alias: "USDT・ERC20",
|
||||
NetworkName: "ERC20",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtErc20,
|
||||
@@ -61,6 +64,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtBep20: {
|
||||
Alias: "USDT・BEP20",
|
||||
NetworkName: "BEP20",
|
||||
Network: conf.Bsc,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtBep20,
|
||||
@@ -71,6 +75,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtAptos: {
|
||||
Alias: "USDT・Aptos",
|
||||
NetworkName: "Aptos",
|
||||
Network: conf.Aptos,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtAptos,
|
||||
@@ -81,6 +86,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtXlayer: {
|
||||
Alias: "USDT・X Layer",
|
||||
NetworkName: "X Layer",
|
||||
Network: conf.Xlayer,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtXlayer,
|
||||
@@ -91,6 +97,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtSolana: {
|
||||
Alias: "USDT・Solana",
|
||||
NetworkName: "Solana",
|
||||
Network: conf.Solana,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtSolana,
|
||||
@@ -102,6 +109,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtPolygon: {
|
||||
Alias: "USDT・Polygon",
|
||||
NetworkName: "Polygon",
|
||||
Network: conf.Polygon,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtPolygon,
|
||||
@@ -112,6 +120,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdtArbitrum: {
|
||||
Alias: "USDT・Arbitrum",
|
||||
NetworkName: "Arbitrum",
|
||||
Network: conf.Arbitrum,
|
||||
Crypto: USDT,
|
||||
Contract: conf.UsdtArbitrum,
|
||||
@@ -122,6 +131,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcErc20: {
|
||||
Alias: "USDC・ERC20",
|
||||
NetworkName: "ERC20",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcErc20,
|
||||
@@ -132,6 +142,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcBep20: {
|
||||
Alias: "USDC・BEP20",
|
||||
NetworkName: "BEP20",
|
||||
Network: conf.Bsc,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcBep20,
|
||||
@@ -142,6 +153,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcXlayer: {
|
||||
Alias: "USDC・X Layer",
|
||||
NetworkName: "X Layer",
|
||||
Network: conf.Xlayer,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcXlayer,
|
||||
@@ -152,6 +164,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcPolygon: {
|
||||
Alias: "USDC・Polygon",
|
||||
NetworkName: "Polygon",
|
||||
Network: conf.Polygon,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcPolygon,
|
||||
@@ -162,6 +175,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcArbitrum: {
|
||||
Alias: "USDC・Arbitrum",
|
||||
NetworkName: "Arbitrum",
|
||||
Network: conf.Arbitrum,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcArbitrum,
|
||||
@@ -172,6 +186,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcBase: {
|
||||
Alias: "USDC・Base",
|
||||
NetworkName: "Base",
|
||||
Network: conf.Base,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcBase,
|
||||
@@ -182,6 +197,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcTrc20: {
|
||||
Alias: "USDC・TRC20",
|
||||
NetworkName: "TRC20",
|
||||
Network: conf.Tron,
|
||||
Crypto: USDC,
|
||||
Contract: "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8", // 占位,目前实际没使用
|
||||
@@ -193,6 +209,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcSolana: {
|
||||
Alias: "USDC・Solana",
|
||||
NetworkName: "Solana",
|
||||
Network: conf.Solana,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcSolana,
|
||||
@@ -204,6 +221,7 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
},
|
||||
UsdcAptos: {
|
||||
Alias: "USDC・Aptos",
|
||||
NetworkName: "Aptos",
|
||||
Network: conf.Aptos,
|
||||
Crypto: USDC,
|
||||
Contract: conf.UsdcAptos,
|
||||
@@ -213,11 +231,12 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
EndpointKey: RpcEndpointAptos,
|
||||
},
|
||||
TronTrx: {
|
||||
Alias: "Tron・Trx",
|
||||
Network: conf.Tron,
|
||||
Crypto: TRX,
|
||||
Native: true,
|
||||
Decimal: -6,
|
||||
Alias: "Tron・Trx",
|
||||
NetworkName: "Tron",
|
||||
Network: conf.Tron,
|
||||
Crypto: TRX,
|
||||
Native: true,
|
||||
Decimal: -6,
|
||||
AmountRange: Range{
|
||||
MinAmount: decimal.NewFromFloat(0.1),
|
||||
MaxAmount: decimal.NewFromFloat(1000000),
|
||||
@@ -227,11 +246,12 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
AddrCaseSens: true,
|
||||
},
|
||||
EthereumEth: {
|
||||
Alias: "Ethereum・Eth",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: ETH,
|
||||
Native: true,
|
||||
Decimal: conf.EthereumEthDecimals,
|
||||
Alias: "Ethereum・Eth",
|
||||
NetworkName: "Ethereum",
|
||||
Network: conf.Ethereum,
|
||||
Crypto: ETH,
|
||||
Native: true,
|
||||
Decimal: conf.EthereumEthDecimals,
|
||||
AmountRange: Range{
|
||||
MinAmount: decimal.NewFromFloat(0.000001),
|
||||
MaxAmount: decimal.NewFromFloat(1000000),
|
||||
@@ -240,11 +260,12 @@ var registry = map[TradeType]TradeTypeConf{
|
||||
EndpointKey: RpcEndpointEthereum,
|
||||
},
|
||||
BscBnb: {
|
||||
Alias: "Bsc・Bnb",
|
||||
Network: conf.Bsc,
|
||||
Crypto: BNB,
|
||||
Native: true,
|
||||
Decimal: conf.BscBnbDecimals,
|
||||
Alias: "Bsc・Bnb",
|
||||
NetworkName: "Bsc",
|
||||
Network: conf.Bsc,
|
||||
Crypto: BNB,
|
||||
Native: true,
|
||||
Decimal: conf.BscBnbDecimals,
|
||||
AmountRange: Range{
|
||||
MinAmount: decimal.NewFromFloat(0.00001),
|
||||
MaxAmount: decimal.NewFromFloat(1000000),
|
||||
@@ -293,6 +314,16 @@ func GetAllAlias() map[string]string {
|
||||
return alias
|
||||
}
|
||||
|
||||
func GetAllTradeConfig() map[string]TradeTypeConf {
|
||||
var config = make(map[string]TradeTypeConf)
|
||||
|
||||
for t, c := range registry {
|
||||
config[string(t)] = c
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
func GetNetworkTrades(n Network) []TradeType {
|
||||
list, ok := networkTradesMap[n]
|
||||
if !ok {
|
||||
@@ -319,7 +350,9 @@ func GetContractDecimal(addr string) int32 {
|
||||
|
||||
func GetTxUrl(t TradeType, hash string) string {
|
||||
if url, ok := explorerUrlMap[t]; ok {
|
||||
|
||||
if url == "" {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(url, hash)
|
||||
}
|
||||
|
||||
@@ -391,3 +424,12 @@ func AddrCaseSens(t TradeType) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func GetTradeTypeByCurrencyAndNetwork(currency, network string) (TradeType, error) {
|
||||
for t, c := range registry {
|
||||
if string(c.Crypto) == currency && (string(c.Network) == network || c.NetworkName == network) {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no matching trade type found for currency %s on network %s", currency, network)
|
||||
}
|
||||
|
||||
@@ -13,17 +13,18 @@ import (
|
||||
)
|
||||
|
||||
type OrderParams struct {
|
||||
Money decimal.Decimal `json:"money"` // 交易金额 (单位:法币)s
|
||||
ApiType string `json:"api_type"` // 支付 API 类型
|
||||
Address string `json:"address"` // 收款地址
|
||||
OrderId string `json:"order_id"` // 商户订单 ID
|
||||
TradeType TradeType `json:"trade_type"` // 交易类型
|
||||
RedirectUrl string `json:"redirect_url"` // 成功跳转地址
|
||||
NotifyUrl string `json:"notify_url"` // 异步通知地址
|
||||
Name string `json:"name"` // 商品名称
|
||||
Timeout int64 `json:"timeout"` // 订单超时时间(秒)
|
||||
Rate string `json:"rate"` // 强制指定汇率
|
||||
Fiat Fiat `json:"fiat"` // 法币类型
|
||||
Money decimal.Decimal `json:"money"` // 交易金额 (单位:法币)s
|
||||
ApiType string `json:"api_type"` // 支付 API 类型
|
||||
Address string `json:"address"` // 收款地址
|
||||
OrderId string `json:"order_id"` // 商户订单 ID
|
||||
TradeType TradeType `json:"trade_type"` // 交易类型
|
||||
RedirectUrl string `json:"redirect_url"` // 成功跳转地址
|
||||
NotifyUrl string `json:"notify_url"` // 异步通知地址
|
||||
Name string `json:"name"` // 商品名称
|
||||
Timeout int64 `json:"timeout"` // 订单超时时间(秒)
|
||||
Rate string `json:"rate"` // 强制指定汇率
|
||||
Fiat Fiat `json:"fiat"` // 法币类型
|
||||
CurrencyLimit string `json:"currency_limit"` // 限定币种
|
||||
}
|
||||
|
||||
type Trade struct {
|
||||
@@ -102,6 +103,8 @@ func RebuildOrder(t Order, p OrderParams) (Order, error) {
|
||||
t.Amount = data.Amount
|
||||
t.TradeType = p.TradeType
|
||||
t.Address = data.Address
|
||||
t.Crypto = data.Crypto
|
||||
t.Rate = fmt.Sprintf("%v", data.Rate)
|
||||
t.ExpiredAt = CalcTradeExpiredAt(p.Timeout)
|
||||
|
||||
return t, Db.Save(&t).Error
|
||||
@@ -114,27 +117,27 @@ func NewOrder(p OrderParams, data Trade) (Order, error) {
|
||||
}
|
||||
|
||||
zero := time.Unix(0, 0)
|
||||
crypto, _ := GetCrypto(p.TradeType)
|
||||
tradeOrder := Order{
|
||||
OrderId: p.OrderId,
|
||||
TradeId: tradeId,
|
||||
RefHash: tradeId,
|
||||
TradeType: p.TradeType,
|
||||
Rate: fmt.Sprintf("%v", data.Rate),
|
||||
Amount: data.Amount,
|
||||
Money: p.Money.String(),
|
||||
Address: data.Address,
|
||||
Status: OrderStatusWaiting,
|
||||
Name: p.Name,
|
||||
ApiType: p.ApiType,
|
||||
ReturnUrl: p.RedirectUrl,
|
||||
NotifyUrl: p.NotifyUrl,
|
||||
NotifyNum: 0,
|
||||
NotifyState: OrderNotifyStateFail,
|
||||
ExpiredAt: CalcTradeExpiredAt(p.Timeout),
|
||||
Fiat: p.Fiat,
|
||||
Crypto: crypto,
|
||||
ConfirmedAt: &zero, // 默认填充一个0值时间,尽量避免数据库出现允许 NULL 值存在
|
||||
OrderId: p.OrderId,
|
||||
TradeId: tradeId,
|
||||
RefHash: tradeId,
|
||||
TradeType: p.TradeType,
|
||||
Rate: fmt.Sprintf("%v", data.Rate),
|
||||
Amount: data.Amount,
|
||||
Money: p.Money.String(),
|
||||
Address: data.Address,
|
||||
Status: OrderStatusWaiting,
|
||||
Name: p.Name,
|
||||
ApiType: p.ApiType,
|
||||
ReturnUrl: p.RedirectUrl,
|
||||
NotifyUrl: p.NotifyUrl,
|
||||
NotifyNum: 0,
|
||||
NotifyState: OrderNotifyStateFail,
|
||||
ExpiredAt: CalcTradeExpiredAt(p.Timeout),
|
||||
Fiat: p.Fiat,
|
||||
Crypto: data.Crypto,
|
||||
CurrencyLimit: p.CurrencyLimit,
|
||||
ConfirmedAt: &zero, // 默认填充一个0值时间,尽量避免数据库出现允许 NULL 值存在
|
||||
}
|
||||
|
||||
if tradeOrder.Name == "" {
|
||||
@@ -157,7 +160,7 @@ func BuildTrade(p OrderParams) (Trade, error) {
|
||||
}
|
||||
|
||||
// 获取订单汇率
|
||||
rate, err := getOrderRate(crypto, p.Fiat, p.Rate)
|
||||
rate, err := GetOrderRate(crypto, p.Fiat, p.Rate)
|
||||
if err != nil {
|
||||
return Trade{}, err
|
||||
}
|
||||
@@ -191,3 +194,41 @@ func BuildTrade(p OrderParams) (Trade, error) {
|
||||
Amount: amount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BuildPendingOrder 创建待支付订单(不锁定地址和汇率)
|
||||
func BuildPendingOrder(p OrderParams) (Order, error) {
|
||||
var order Order
|
||||
|
||||
maxAmount := decimal.NewFromFloat(cast.ToFloat64(GetC(PaymentMaxAmount)))
|
||||
minAmount := decimal.NewFromFloat(cast.ToFloat64(GetC(PaymentMinAmount)))
|
||||
if p.Money.GreaterThan(maxAmount) || p.Money.LessThan(minAmount) {
|
||||
return order, fmt.Errorf("交易金额必须在 %s - %s 之间", minAmount.String(), maxAmount.String())
|
||||
}
|
||||
|
||||
Db.Where("order_id = ?", p.OrderId).Order("id desc").Limit(1).Find(&order)
|
||||
if order.Status == OrderStatusSuccess || order.Status == OrderStatusConfirming || order.Status == OrderStatusWaiting {
|
||||
return order, nil
|
||||
}
|
||||
|
||||
// 默认使用 USDT
|
||||
crypto := USDT
|
||||
if p.TradeType != "" {
|
||||
c, err := GetCrypto(p.TradeType)
|
||||
if err == nil {
|
||||
crypto = c
|
||||
}
|
||||
} else if p.CurrencyLimit != "" {
|
||||
// 如果指定了唯一的币种限制,且不是黑名单模式,则使用该币种
|
||||
cur := strings.ToUpper(p.CurrencyLimit)
|
||||
if !strings.Contains(cur, ",") && !strings.HasPrefix(cur, "-") {
|
||||
crypto = Crypto(cur)
|
||||
}
|
||||
}
|
||||
|
||||
return NewOrder(p, Trade{
|
||||
Crypto: crypto,
|
||||
Rate: decimal.Zero,
|
||||
Amount: "0",
|
||||
Address: "",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ type TronTransfer struct {
|
||||
RecvAddress string
|
||||
Timestamp time.Time
|
||||
TradeType TradeType
|
||||
BlockNum int64
|
||||
BlockNum int
|
||||
}
|
||||
|
||||
type TronResource struct {
|
||||
|
||||
@@ -14,11 +14,11 @@ const (
|
||||
type Wallet struct {
|
||||
Id
|
||||
Name string `gorm:"column:name;type:varchar(32);not null;default:-';comment:名称" json:"name"`
|
||||
Status uint8 `gorm:"column:status;type:tinyint(1);not null;default:1;comment:地址状态" json:"status"`
|
||||
Status uint8 `gorm:"column:status;not null;default:1;comment:地址状态" json:"status"`
|
||||
Address string `gorm:"column:address;type:varchar(128);not null;index;comment:钱包地址" json:"address"`
|
||||
MatchAddr string `gorm:"column:match_addr;type:varchar(128);not null;uniqueIndex:idx_address;comment:匹配地址" json:"match_addr"`
|
||||
TradeType string `gorm:"column:trade_type;type:varchar(20);not null;uniqueIndex:idx_address;comment:交易类型" json:"trade_type"`
|
||||
OtherNotify uint8 `gorm:"column:other_notify;type:tinyint(1);not null;default:0;comment:其它通知" json:"other_notify"`
|
||||
OtherNotify uint8 `gorm:"column:other_notify;not null;default:0;comment:其它通知" json:"other_notify"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);not null;default:'';comment:备注" json:"remark"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ func adminInit(e *gin.Engine) {
|
||||
var orderHdr = new(admin.Order)
|
||||
{
|
||||
PostRegister(orderRtr, "/list", true, orderHdr.List)
|
||||
PostRegister(orderRtr, "/create", true, orderHdr.Create)
|
||||
PostRegister(orderRtr, "/detail", true, orderHdr.Detail)
|
||||
PostRegister(orderRtr, "/paid", true, orderHdr.Paid)
|
||||
PostRegister(orderRtr, "/manual_notify", true, orderHdr.ManualNotify)
|
||||
|
||||
@@ -10,6 +10,7 @@ func epusdtInit(engine *gin.Engine) {
|
||||
epHdr := new(epusdt.Epusdt)
|
||||
{
|
||||
epGrp.GET("/checkout-counter/:trade_id", epHdr.CheckoutCounter)
|
||||
epGrp.GET("/cashier/:trade_id", epHdr.CheckoutCashier)
|
||||
epGrp.GET("/check-status/:trade_id", epHdr.CheckStatus)
|
||||
}
|
||||
|
||||
@@ -18,5 +19,13 @@ func epusdtInit(engine *gin.Engine) {
|
||||
orderGrp.Use(epHdr.SignVerify)
|
||||
orderGrp.POST("/create-transaction", epHdr.CreateTransaction)
|
||||
orderGrp.POST("/cancel-transaction", epHdr.CancelTransaction)
|
||||
orderGrp.POST("/create-order", epHdr.CreateOrder)
|
||||
}
|
||||
|
||||
payApiGrp := engine.Group("/api/v1/pay")
|
||||
{
|
||||
payApiGrp.POST("/methods", epHdr.GetPaymentMethods)
|
||||
payApiGrp.POST("/update-order", epHdr.UpdateOrder)
|
||||
payApiGrp.POST("/notify", epHdr.Notify)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,17 @@ import (
|
||||
)
|
||||
|
||||
type aptos struct {
|
||||
versionChunkSize int64
|
||||
versionConfirmedOffset int64
|
||||
lastVersion int64
|
||||
versionChunkSize int
|
||||
versionConfirmedOffset int
|
||||
lastVersion int
|
||||
versionQueue *chanx.UnboundedChan[version]
|
||||
client *http.Client
|
||||
earliestBlockTs atomic.Int64
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Start int64
|
||||
Limit int64
|
||||
Start int
|
||||
Limit int
|
||||
}
|
||||
|
||||
var apt aptos
|
||||
@@ -68,7 +68,7 @@ func newAptos() aptos {
|
||||
}
|
||||
|
||||
func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
if syncBreak(conf.Aptos) {
|
||||
if syncBreak(conf.Aptos, a.versionQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
now := gjson.GetBytes(body, "ledger_version").Int()
|
||||
now := int(gjson.GetBytes(body, "ledger_version").Int())
|
||||
if now <= 0 {
|
||||
log.Task.Warn("syncVersionForward Error: invalid ledger_version:", now)
|
||||
|
||||
@@ -116,7 +116,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
a.versionQueue.In <- version{Start: a.lastVersion, Limit: sub}
|
||||
} else {
|
||||
chunks := (sub + a.versionChunkSize - 1) / a.versionChunkSize
|
||||
for i := int64(0); i < chunks; i++ {
|
||||
for i := 0; i < chunks; i++ {
|
||||
limit := a.versionChunkSize
|
||||
start := a.lastVersion + a.versionChunkSize*i
|
||||
if i == chunks-1 {
|
||||
@@ -133,7 +133,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
a.lastVersion = now
|
||||
}
|
||||
|
||||
func (a *aptos) syncVersionBackward(ctx context.Context, now int64) {
|
||||
func (a *aptos) syncVersionBackward(ctx context.Context, now int) {
|
||||
var o model.Order
|
||||
trade := model.GetNetworkTrades(conf.Aptos)
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)",
|
||||
@@ -153,7 +153,7 @@ func (a *aptos) syncVersionBackward(ctx context.Context, now int64) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if syncBreak(conf.Aptos) {
|
||||
if syncBreak(conf.Aptos, a.versionQueue.Len()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func (a *aptos) versionParse(n any) {
|
||||
timestamp := time.Unix(tsNano/1e9, tsNano%1e9)
|
||||
a.recordEarliestBlockTs(timestamp.Unix())
|
||||
|
||||
ver := trans.Get("version").Int()
|
||||
ver := int(trans.Get("version").Int())
|
||||
hash := trans.Get("hash").String()
|
||||
addrOwner := make(map[string]string) // [address] => owner address
|
||||
addrType := make(map[string]model.TradeType) // [address] => tradeType
|
||||
@@ -408,6 +408,15 @@ func (a *aptos) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
if a.lastVersion == 0 {
|
||||
return
|
||||
}
|
||||
if a.lastVersion-o.RefBlockNum < a.versionConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", model.Endpoint(conf.Aptos)+"v1/transactions/by_hash/"+o.RefHash, nil)
|
||||
resp, err := a.client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -33,7 +32,7 @@ var chainBlockNum sync.Map
|
||||
|
||||
type block struct {
|
||||
RollDelayOffset int64 // 延迟偏移量,某些RPC节点如果不延迟,会报错 block is out of range,目前发现 https://rpc.xlayer.tech/ 存在此问题
|
||||
ConfirmedOffset int64 // 确认偏移量,开启交易确认后,区块高度需要减去此值认为交易已确认
|
||||
ConfirmedOffset int // 确认偏移量,开启交易确认后,区块高度需要减去此值认为交易已确认
|
||||
}
|
||||
|
||||
type evmNative struct {
|
||||
@@ -57,7 +56,7 @@ type evmBlock struct {
|
||||
}
|
||||
|
||||
func (e *evm) syncBlocksForward(ctx context.Context) {
|
||||
if syncBreak(e.Network) {
|
||||
if syncBreak(e.Network, e.blockScanQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -150,7 +149,7 @@ func (e *evm) syncBlocksBackward(now int64) {
|
||||
defer ticker.Stop()
|
||||
|
||||
for from := start; from <= now; from += blockParseMaxNum {
|
||||
if syncBreak(e.Network) {
|
||||
if syncBreak(e.Network, e.blockScanQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -256,7 +255,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
var array = itm.Get("result.transactions").Array()
|
||||
if e.Native.Parse && len(array) != 0 {
|
||||
|
||||
nativeTransfers = append(nativeTransfers, e.parseNativeTransfer(array, utils.HexStr2Int(blockNumHex).Int64(), blockTime)...)
|
||||
nativeTransfers = append(nativeTransfers, e.parseNativeTransfer(array, int(utils.HexStr2Int(blockNumHex).Int64()), blockTime)...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +278,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
log.Task.Info(fmt.Sprintf("区块扫描完成(%s): %d → %d 成功率:%s", e.Network, b.From, b.To, conf.GetSuccessRate(e.Network)))
|
||||
}
|
||||
|
||||
func (e *evm) parseNativeTransfer(array []gjson.Result, num int64, timestamp time.Time) []transfer {
|
||||
func (e *evm) parseNativeTransfer(array []gjson.Result, num int, timestamp time.Time) []transfer {
|
||||
nativeTransfers := make([]transfer, 0)
|
||||
for _, tx := range array {
|
||||
if tx.Get("input").String() != "0x" {
|
||||
@@ -372,20 +371,13 @@ func (e *evm) parseEventTransfer(b evmBlock, timestamp map[string]time.Time) ([]
|
||||
continue
|
||||
}
|
||||
|
||||
blockNum, err := strconv.ParseInt(itm.Get("blockNumber").String(), 0, 64)
|
||||
if err != nil {
|
||||
log.Task.Warn("evmBlockParse Error parsing block number:", err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
transfers = append(transfers, transfer{
|
||||
Network: e.Network,
|
||||
FromAddress: from,
|
||||
RecvAddress: recv,
|
||||
Amount: decimal.NewFromBigInt(amount, model.GetContractDecimal(to)),
|
||||
TxHash: itm.Get("transactionHash").String(),
|
||||
BlockNum: blockNum,
|
||||
BlockNum: cast.ToInt(itm.Get("blockNumber").String()),
|
||||
Timestamp: timestamp[itm.Get("blockNumber").String()],
|
||||
TradeType: tradeType,
|
||||
})
|
||||
@@ -399,6 +391,16 @@ func (e *evm) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
last, ok := chainBlockNum.Load(e.Network)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if last.(int)-o.RefBlockNum < e.Block.ConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["%s"],"id":1}`, o.RefHash))
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", e.rpcEndpoint(), bytes.NewBuffer(post))
|
||||
if err != nil {
|
||||
@@ -452,7 +454,13 @@ func (e *evm) rpcEndpoint() string {
|
||||
return model.Endpoint(model.Network(e.Network))
|
||||
}
|
||||
|
||||
func syncBreak(network string) bool {
|
||||
func syncBreak(network string, num int) bool {
|
||||
if num >= blockQueueLimit {
|
||||
log.Task.Warn(fmt.Sprintf("%s 同步阻塞,当前区块消费堆积数量:%d", network, num))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
trades := model.GetNetworkTrades(model.Network(network))
|
||||
if len(trades) == 0 {
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package notify
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -31,55 +32,58 @@ type EpNotify struct {
|
||||
Status int `json:"status"` // 1:等待支付,2:支付成功,3:订单超时
|
||||
}
|
||||
|
||||
func Handle(order model.Order) {
|
||||
func Handle(order model.Order) error {
|
||||
if order.Status != model.OrderStatusSuccess {
|
||||
|
||||
return
|
||||
return errors.New("订单未支付 无法回调")
|
||||
}
|
||||
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
var err error
|
||||
if order.ApiType == model.OrderApiTypeEpay {
|
||||
epay(ctx, order)
|
||||
|
||||
return
|
||||
err = epay(ctx, order)
|
||||
} else {
|
||||
err = epusdt(ctx, order)
|
||||
}
|
||||
|
||||
epusdt(ctx, order)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("订单回调成功:", order.TradeId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func epay(ctx context.Context, order model.Order) {
|
||||
func epay(ctx context.Context, order model.Order) error {
|
||||
var client = http.Client{Timeout: time.Second * 5}
|
||||
var notifyUrl = fmt.Sprintf("%s?%s", order.NotifyUrl, epay2.BuildNotifyParams(order))
|
||||
|
||||
postReq, err2 := http.NewRequestWithContext(ctx, "GET", notifyUrl, nil)
|
||||
if err2 != nil {
|
||||
log.Error("Notify NewRequest Error:", err2)
|
||||
|
||||
return
|
||||
return err2
|
||||
}
|
||||
|
||||
postReq.Header.Set("Powered-By", "https://github.com/v03413/bepusdt")
|
||||
resp, err := client.Do(postReq)
|
||||
if err != nil {
|
||||
log.Error("Notify Handle Error:", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
markNotifyFail(order, fmt.Sprintf("resp.StatusCode != 200"))
|
||||
|
||||
return
|
||||
return fmt.Errorf("商户系统返回状态码错误:%d(必须是200)", resp.StatusCode)
|
||||
}
|
||||
|
||||
all, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
markNotifyFail(order, fmt.Sprintf("io.ReadAll(resp.Body) Error: %v", err))
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
var bodyStr = strings.ToLower(strings.TrimSpace(string(all)))
|
||||
@@ -88,19 +92,17 @@ func epay(ctx context.Context, order model.Order) {
|
||||
if !strings.Contains(bodyStr, "success") && !strings.Contains(bodyStr, "ok") {
|
||||
markNotifyFail(order, "商户系统必须响应 success 或 ok 才会认定回调成功")
|
||||
|
||||
return
|
||||
return fmt.Errorf("商户系统必须响应 success 或 ok 才会认定回调成功,实际响应:%s", string(all))
|
||||
}
|
||||
|
||||
if err = order.SetNotifyState(model.OrderNotifyStateSucc); err != nil {
|
||||
log.Error("订单标记通知成功错误:", err, order.OrderId)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("订单通知成功:", order.OrderId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func epusdt(ctx context.Context, order model.Order) {
|
||||
func epusdt(ctx context.Context, order model.Order) error {
|
||||
var data = make(map[string]interface{})
|
||||
var body = EpNotify{
|
||||
TradeId: order.TradeId,
|
||||
@@ -113,15 +115,11 @@ func epusdt(ctx context.Context, order model.Order) {
|
||||
}
|
||||
var jsonBody, err = json.Marshal(body)
|
||||
if err != nil {
|
||||
log.Error("Notify Json Marshal Error:", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(jsonBody, &data); err != nil {
|
||||
log.Error("Notify JSON Unmarshal Error:", err)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
// 签名
|
||||
@@ -132,9 +130,9 @@ func epusdt(ctx context.Context, order model.Order) {
|
||||
var client = http.Client{Timeout: time.Second * 5}
|
||||
var postReq, err2 = http.NewRequestWithContext(ctx, "POST", order.NotifyUrl, strings.NewReader(string(jsonBody)))
|
||||
if err2 != nil {
|
||||
markNotifyFail(order, err.Error())
|
||||
markNotifyFail(order, err2.Error())
|
||||
|
||||
return
|
||||
return err2
|
||||
}
|
||||
|
||||
postReq.Header.Set("Content-Type", "application/json")
|
||||
@@ -144,35 +142,33 @@ func epusdt(ctx context.Context, order model.Order) {
|
||||
if err != nil {
|
||||
markNotifyFail(order, err.Error())
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
markNotifyFail(order, fmt.Sprintf("商户系统返回状态码错误:%d(必须是200)", resp.StatusCode))
|
||||
|
||||
return
|
||||
return fmt.Errorf("商户系统返回状态码错误:%d(必须是200)", resp.StatusCode)
|
||||
}
|
||||
|
||||
if err = order.SetNotifyState(model.OrderNotifyStateSucc); err != nil {
|
||||
log.Error("订单标记通知成功错误:", err, order.OrderId)
|
||||
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("订单通知成功:", order.OrderId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Bepusdt(order model.Order) {
|
||||
if order.ApiType != model.OrderApiTypeEpusdt {
|
||||
func Bepusdt(o model.Order) {
|
||||
if o.ApiType != model.OrderApiTypeEpusdt {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var todo = func() error {
|
||||
var o model.Order
|
||||
var db = model.Db.Begin()
|
||||
if err := db.Where("trade_id = ? and status = ?", order.TradeId, order.Status).First(&o).Error; err != nil {
|
||||
if err := db.Where("trade_id = ? and status = ?", o.TradeId, o.Status).Limit(1).Find(&o).Error; err != nil {
|
||||
db.Rollback()
|
||||
|
||||
return err
|
||||
@@ -220,7 +216,7 @@ func Bepusdt(order model.Order) {
|
||||
if err2 != nil {
|
||||
db.Rollback()
|
||||
|
||||
return err
|
||||
return err2
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@@ -241,7 +237,7 @@ func Bepusdt(order model.Order) {
|
||||
|
||||
all, _ := io.ReadAll(resp.Body)
|
||||
|
||||
log.Info(fmt.Sprintf("订单回调成功[%d]:%s %s", order.Status, o.TradeId, string(all)))
|
||||
log.Info(fmt.Sprintf("订单回调成功[%d]:%s %s", o.Status, o.TradeId, string(all)))
|
||||
|
||||
db.Commit()
|
||||
|
||||
@@ -254,8 +250,8 @@ func Bepusdt(order model.Order) {
|
||||
}()
|
||||
}
|
||||
|
||||
func markNotifyFail(order model.Order, reason string) {
|
||||
log.Warn(fmt.Sprintf("订单回调失败(%v):%s %v", order.TradeId, reason, order.SetNotifyState(model.OrderNotifyStateFail)))
|
||||
func markNotifyFail(o model.Order, reason string) {
|
||||
log.Warn(fmt.Sprintf("订单回调失败(%v):%s %v", o.TradeId, reason, o.SetNotifyState(model.OrderNotifyStateFail)))
|
||||
|
||||
notifier.NotifyFail(order, reason)
|
||||
notifier.NotifyFail(o, reason)
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ import (
|
||||
// - https://github.com/solana-program/token/blob/6d18ff73b1dd30703a30b1ca941cb0f1d18c2b2a/program/src/instruction.rs
|
||||
|
||||
type solana struct {
|
||||
slotConfirmedOffset int64
|
||||
lastSlotNum int64
|
||||
slotQueue *chanx.UnboundedChan[int64]
|
||||
slotConfirmedOffset int
|
||||
lastSlotNum int
|
||||
slotQueue *chanx.UnboundedChan[int]
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ func newSolana() solana {
|
||||
return solana{
|
||||
slotConfirmedOffset: 60,
|
||||
lastSlotNum: 0,
|
||||
slotQueue: chanx.NewUnboundedChan[int64](context.Background(), 30),
|
||||
slotQueue: chanx.NewUnboundedChan[int](context.Background(), 30),
|
||||
client: utils.NewHttpClient(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
if syncBreak(conf.Solana) {
|
||||
if syncBreak(conf.Solana, s.slotQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
now := gjson.GetBytes(body, "result").Int()
|
||||
now := int(gjson.GetBytes(body, "result").Int())
|
||||
if now <= 0 {
|
||||
log.Task.Warn("syncSlotForward Error: invalid slot number:", now)
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
s.syncSlotBackward(now)
|
||||
}
|
||||
|
||||
if now-s.lastSlotNum > cast.ToInt64(model.GetC(model.BlockHeightMaxDiff)) { // 区块高度变化过大,强制丢块重扫
|
||||
if now-s.lastSlotNum > cast.ToInt(model.GetC(model.BlockHeightMaxDiff)) { // 区块高度变化过大,强制丢块重扫
|
||||
s.lastSlotNum = now
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
s.lastSlotNum = now
|
||||
}
|
||||
|
||||
func (s *solana) syncSlotBackward(now int64) {
|
||||
func (s *solana) syncSlotBackward(now int) {
|
||||
if now == 0 || s.lastSlotNum != 0 {
|
||||
|
||||
return
|
||||
@@ -132,14 +132,14 @@ func (s *solana) syncSlotBackward(now int64) {
|
||||
}
|
||||
|
||||
// Solana 大概1秒3个区块(大概值,实际存在波动)
|
||||
num := (time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) * 3 // 计算需要反向扫描的区块数量
|
||||
num := int((time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) * 3) // 计算需要反向扫描的区块数量
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Millisecond * 125)
|
||||
defer ticker.Stop()
|
||||
|
||||
for i := int64(0); i < num; i++ {
|
||||
if syncBreak(conf.Solana) {
|
||||
for i := 0; i < num; i++ {
|
||||
if syncBreak(conf.Solana, s.slotQueue.Len()) {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (s *solana) slotDispatch(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (s *solana) slotParse(n any) {
|
||||
slot := n.(int64)
|
||||
slot := n.(int)
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[%d,{"encoding":"json","maxSupportedTransactionVersion":0,"transactionDetails":"full","rewards":false}]}`, slot))
|
||||
network := conf.Solana
|
||||
|
||||
@@ -361,6 +361,15 @@ func (s *solana) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
if s.lastSlotNum == 0 {
|
||||
return
|
||||
}
|
||||
if s.lastSlotNum-o.RefBlockNum < s.slotConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"getSignatureStatuses","params":[["%s"],{"searchTransactionHistory":true}]}`, o.RefHash))
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", model.Endpoint(conf.Solana), bytes.NewBuffer(post))
|
||||
resp, err := s.client.Do(req)
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"github.com/v03413/bepusdt/app/model"
|
||||
)
|
||||
|
||||
// 区块扫描队列最大长度,避免可能因为 Rpc Rate Limit 问题导致消费队列堆积,进而导致OOM,暂时简单限制队列长度
|
||||
// 如果直接使用固定长度的 Channel 控制,会导致区块高度同步时也彻底阻塞,无法对外界输出日志导致无法观察,彻底垮掉
|
||||
// 如果确实是因为 Rate Limit 问题导致的异常,优先考虑的是提升 Rpc 节点的质量和稳定性
|
||||
const blockQueueLimit = 100
|
||||
|
||||
type Task struct {
|
||||
Duration time.Duration
|
||||
Callback func(ctx context.Context)
|
||||
|
||||
@@ -23,7 +23,7 @@ type transfer struct {
|
||||
RecvAddress string
|
||||
Timestamp time.Time
|
||||
TradeType model.TradeType
|
||||
BlockNum int64
|
||||
BlockNum int
|
||||
}
|
||||
|
||||
type resource struct {
|
||||
@@ -40,7 +40,8 @@ var resourceQueue = chanx.NewUnboundedChan[[]resource](context.Background(), 30)
|
||||
var notOrderQueue = chanx.NewUnboundedChan[[]transfer](context.Background(), 30) // 非订单队列
|
||||
var transferQueue = chanx.NewUnboundedChan[[]transfer](context.Background(), 30) // 交易转账队列
|
||||
|
||||
const batchInterval = time.Second * 1 // 批处理缓解数据库读取压力
|
||||
const batchInterval = time.Second * 1 // 批处理缓解数据库读取压力
|
||||
const orderCheckInterval = time.Second * 10 // 订单过期检查间隔
|
||||
|
||||
func init() {
|
||||
Register(Task{Callback: orderTransferHandle})
|
||||
@@ -50,6 +51,7 @@ func init() {
|
||||
|
||||
func orderTransferHandle(ctx context.Context) {
|
||||
var batch = make([]transfer, 0, 1000)
|
||||
var lastCheckTime = time.Now()
|
||||
ticker := time.NewTicker(batchInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
@@ -63,11 +65,22 @@ func orderTransferHandle(ctx context.Context) {
|
||||
}
|
||||
batch = append(batch, transfers...)
|
||||
case <-ticker.C:
|
||||
// 每10秒强制检查一次过期订单,即使没有交易,防止无交易时订单不过期
|
||||
var shouldCheck = time.Since(lastCheckTime) >= orderCheckInterval
|
||||
if len(batch) == 0 && !shouldCheck {
|
||||
continue
|
||||
}
|
||||
|
||||
if shouldCheck {
|
||||
lastCheckTime = time.Now()
|
||||
}
|
||||
|
||||
var other = make([]transfer, 0)
|
||||
// getAllWaitingOrders 内部包含过期检查逻辑
|
||||
var orders = getAllWaitingOrders()
|
||||
if len(batch) == 0 {
|
||||
continue
|
||||
}
|
||||
var other = make([]transfer, 0)
|
||||
var orders = getAllWaitingOrders()
|
||||
for _, t := range batch {
|
||||
// 判断数额是否在允许范围内
|
||||
if !model.IsAmountValid(t.TradeType, t.Amount) {
|
||||
|
||||
@@ -32,10 +32,11 @@ var usdtTrc20ContractAddress = []byte{0x41, 0xa6, 0x14, 0xf8, 0x03, 0xb6, 0xfd,
|
||||
var usdcTrc20ContractAddress = []byte{0x41, 0x34, 0x87, 0xb6, 0x3d, 0x30, 0xb5, 0xb2, 0xc8, 0x7f, 0xb7, 0xff, 0xa8, 0xbc, 0xfa, 0xde, 0x38, 0xea, 0xac, 0x1a, 0xbe}
|
||||
|
||||
type tron struct {
|
||||
lastBlockNum int64
|
||||
blockScanQueue *chanx.UnboundedChan[int64]
|
||||
conn map[string]*grpc.ClientConn
|
||||
connMu sync.RWMutex
|
||||
lastBlockNum int
|
||||
blockConfirmedOffset int
|
||||
blockScanQueue *chanx.UnboundedChan[int]
|
||||
conn map[string]*grpc.ClientConn
|
||||
connMu sync.RWMutex
|
||||
}
|
||||
|
||||
var tr tron
|
||||
@@ -49,9 +50,10 @@ func init() {
|
||||
|
||||
func newTron() tron {
|
||||
return tron{
|
||||
lastBlockNum: 0,
|
||||
blockScanQueue: chanx.NewUnboundedChan[int64](context.Background(), 30),
|
||||
conn: make(map[string]*grpc.ClientConn),
|
||||
lastBlockNum: 0,
|
||||
blockConfirmedOffset: 30,
|
||||
blockScanQueue: chanx.NewUnboundedChan[int](context.Background(), 30),
|
||||
conn: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,10 +81,10 @@ func (t *tron) syncBlocksForward(context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var now = block.BlockHeader.RawData.Number
|
||||
var now = int(block.BlockHeader.RawData.Number)
|
||||
|
||||
// 区块高度变化过大,强制丢块重扫
|
||||
if now-t.lastBlockNum > cast.ToInt64(model.GetC(model.BlockHeightMaxDiff)) {
|
||||
if now-t.lastBlockNum > cast.ToInt(model.GetC(model.BlockHeightMaxDiff)) {
|
||||
t.syncBlocksBackward(now)
|
||||
t.lastBlockNum = now - 1
|
||||
}
|
||||
@@ -103,7 +105,7 @@ func (t *tron) syncBlocksForward(context.Context) {
|
||||
}
|
||||
|
||||
// syncBlocksBackward 反向同步区块,针对程序启动前就已经存在待支付订单时,补齐之前的区块数据,自适应偏移数量
|
||||
func (t *tron) syncBlocksBackward(now int64) {
|
||||
func (t *tron) syncBlocksBackward(now int) {
|
||||
var o model.Order
|
||||
trade := model.GetNetworkTrades(conf.Tron)
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, trade).Order("created_at asc").Limit(1).Find(&o)
|
||||
@@ -114,7 +116,7 @@ func (t *tron) syncBlocksBackward(now int64) {
|
||||
|
||||
// 波场出块速度大概3秒一个,同时再冗余5个区块
|
||||
num := (time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) / 3 // 计算需要反向扫描的区块数量
|
||||
start := now - num - 5 // 计算反向扫描的起始区块高度
|
||||
start := now - int(num) - 5 // 计算反向扫描的起始区块高度
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
@@ -156,7 +158,7 @@ func (t *tron) blockDispatch(context.Context) {
|
||||
}
|
||||
|
||||
func (t *tron) blockParse(n any) {
|
||||
var num = n.(int64)
|
||||
var num = n.(int)
|
||||
|
||||
var conn *grpc.ClientConn
|
||||
var err error
|
||||
@@ -169,11 +171,11 @@ func (t *tron) blockParse(n any) {
|
||||
conf.RecordSuccess(conf.Tron)
|
||||
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
|
||||
bok, err2 := api.NewWalletClient(conn).GetBlockByNum2(ctx, &api.NumberMessage{Num: num})
|
||||
bok, err2 := api.NewWalletClient(conn).GetBlockByNum2(ctx, &api.NumberMessage{Num: int64(num)})
|
||||
cancel()
|
||||
if err2 != nil {
|
||||
conf.RecordFailure(conf.Tron)
|
||||
t.blockScanQueue.In <- num
|
||||
t.blockScanQueue.In <- int(num)
|
||||
log.Task.Warn("GetBlockByNum2 ", err2)
|
||||
|
||||
return
|
||||
@@ -248,7 +250,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: t.base58CheckEncode(foo.ToAddress),
|
||||
Timestamp: timestamp,
|
||||
TradeType: model.TronTrx,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -278,7 +280,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: receiver,
|
||||
Timestamp: timestamp,
|
||||
TradeType: model.UsdtTrc20,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -304,7 +306,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: receiver,
|
||||
Timestamp: timestamp,
|
||||
TradeType: tradeType,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -319,7 +321,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: to,
|
||||
Timestamp: timestamp,
|
||||
TradeType: tradeType,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -395,6 +397,12 @@ func (t *tron) tradeConfirmHandle(ctx context.Context) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var handle = func(o model.Order) {
|
||||
if model.GetC(model.BlockOffsetConfirm) == "1" {
|
||||
if t.lastBlockNum == 0 || t.lastBlockNum-o.RefBlockNum < t.blockConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
conn, err := t.client()
|
||||
if err != nil {
|
||||
log.Task.Error("grpc.NewClient", err)
|
||||
@@ -460,6 +468,12 @@ func (t *tron) base58CheckEncode(input []byte) string {
|
||||
}
|
||||
|
||||
func (t *tron) syncBreak() bool {
|
||||
if t.blockScanQueue.Len() >= blockQueueLimit {
|
||||
log.Task.Warn("tron 同步阻塞,当前区块消费堆积数量:", t.blockScanQueue.Len())
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
var count int64 = 0
|
||||
trade := []model.TradeType{model.TronTrx, model.UsdtTrc20, model.UsdcTrc20}
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, trade).Count(&count)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -204,3 +205,34 @@ func StrSha256(str string) string {
|
||||
hash.Write([]byte(str))
|
||||
return fmt.Sprintf("%x", hash.Sum(nil))
|
||||
}
|
||||
|
||||
// GetRequestHost 识别完整的请求主机地址
|
||||
func GetRequestHost(r *http.Request) string {
|
||||
scheme := "http"
|
||||
|
||||
if r.TLS != nil {
|
||||
scheme = "https"
|
||||
} else {
|
||||
// 检查各种代理转发的协议头
|
||||
// Nginx、Apache、Caddy 通用
|
||||
if proto := r.Header.Get("X-Forwarded-Proto"); proto == "https" {
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("X-Forwarded-Ssl") == "on" {
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("Front-End-Https") == "on" {
|
||||
// Apache mod_proxy
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("X-Url-Scheme") == "https" {
|
||||
// Caddy
|
||||
scheme = "https"
|
||||
} else if r.Header.Get("CF-Visitor") != "" {
|
||||
// Cloudflare
|
||||
// CF-Visitor 格式: {"scheme":"https"}
|
||||
if strings.Contains(r.Header.Get("CF-Visitor"), `"scheme":"https"`) {
|
||||
scheme = "https"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scheme + "://" + r.Host
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# 异次元发卡对接教程
|
||||
|
||||
异次元发卡开源地址:https://github.com/lizhipay/acg-faka
|
||||
后台插件实际支持epusdt,但存在一些问题,这里做了一些修复并且增加了对TRX的支持,修复兼容版下载地址:[点击下载](https://raw.githubusercontent.com/v03413/bepusdt/refs/heads/main/docs/acg-faka/Epusdt.zip)
|
||||
|
||||
## 对接教程
|
||||
|
||||
### 1. 插件替换
|
||||
|
||||
如果已经安装了原版epusdt插件,请先卸载删除原版插件,然后将下载的修复兼容版解压上传到异次元网站跟目录`app/Pay`,
|
||||
最后确保插件目录结构如下:
|
||||
|
||||
```
|
||||
├── Epusdt
|
||||
│ ├── Config
|
||||
│ │ ├── Config.php
|
||||
│ │ ├── Info.php
|
||||
│ │ └── Submit.php
|
||||
│ └── Impl
|
||||
│ ├── Pay.php
|
||||
│ └── Signature.php
|
||||
```
|
||||
|
||||
⚠️ 注意:请确保插件整个目录的权限为`www:www`(一般都是这个),如果不是请自行修改,否则无法正常使用。
|
||||
|
||||
返回异次元后台,点击`支付插件`,如果发现以下如图所示,说明插件安装成功。
|
||||

|
||||
|
||||
### 2. 插件配置
|
||||
|
||||
- 支付网关:必须`http(s)://`开头,斜杠`/`结尾
|
||||
- 密钥:搭建`Bepusdt`时候的参数`AUTH_TOKEN`
|
||||
|
||||

|
||||
|
||||
找到插件,点击右侧的`配置`按钮,填写好相关参数,点击`确认`保存即可。
|
||||
|
||||
### 3. 添加支付
|
||||
|
||||
#### 添加支付
|
||||
|
||||
异次元后台 -> 支付接口 -> 添加支付 -> 选择`Epusdt`
|
||||
|
||||

|
||||

|
||||
|
||||
#### 支付配置
|
||||
|
||||

|
||||
|
||||
如上图所示,重点就是`支付类型`,按你的需求选择`USDT-TRC20`或者`TRON-TRX`,其他参数按照实际情况填写即可。
|
||||
|
Before Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 314 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 346 KiB |
@@ -0,0 +1,53 @@
|
||||
# 异次元发卡 BEpusdt 对接指南
|
||||
|
||||
异次元应用商店提供的 `Epusdt` 插件存在一些问题,本文档提供优化适配版本的安装和配置方案。
|
||||
|
||||
## 对接流程
|
||||
|
||||
### 1. 前置条件
|
||||
|
||||
请先按照异次元官方文档完成 `Epusdt` 支付插件的标准安装流程。
|
||||
|
||||
- 位置:应用商店 → 支付接口
|
||||
- 搜索并安装官方 `Epusdt` 插件
|
||||
|
||||
### 2. 插件更新
|
||||
|
||||
[下载兼容适配版本](https://raw.githubusercontent.com/v03413/bepusdt/refs/heads/main/docs/api/acg-faka/Epusdt.zip)
|
||||
|
||||
**安装步骤:**
|
||||
|
||||
1. 进入异次元网站根目录
|
||||
2. 定位到 `app/Plugins/Epusdt` 目录
|
||||
3. 删除目录内所有文件
|
||||
4. 解压下载的插件包,将所有文件移入该目录
|
||||
|
||||
**权限配置:**
|
||||
|
||||
⚠️ 确保插件目录权限为 `www:www`(通常为默认配置)。如权限不符,请执行:
|
||||
|
||||
```bash
|
||||
chown -R www:www app/Plugins/Epusdt
|
||||
chmod -R 755 app/Plugins/Epusdt
|
||||
```
|
||||
|
||||
### 3. 插件配置
|
||||
|
||||
在异次元后台进行以下配置:
|
||||
|
||||
| 配置项 | 说明 | 示例 |
|
||||
|------|------------------------------|----------------------------|
|
||||
| 支付网关 | 必须以 `http(s)://` 开头,以 `/` 结尾 | `https://api.example.com/` |
|
||||
| 对接密钥 | 从 BEpusdt 后台获取 | - |
|
||||
| 法币单位 | 按需选择,默认推荐 `CNY` | `CNY` `USD` `JPY` |
|
||||
|
||||
### 4. 创建支付方式
|
||||
|
||||
在异次元后台完成以下操作:
|
||||
|
||||
1. 导航到:支付接口 → 添加支付
|
||||
2. 选择支付插件:`BEpusdt`
|
||||
3. 根据业务需求填写相关参数
|
||||
4. 保存配置
|
||||
|
||||
配置完成后,系统将自动启用该支付方式。
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
## 接口列表
|
||||
|
||||
### 1. 创建订单
|
||||
### 1. 创建交易
|
||||
|
||||
创建支付订单并获取收银台地址。
|
||||
创建支付订单并获取收银台付款地址。
|
||||
|
||||
> **注意**:使用相同 `order_id` 创建订单时,系统会根据最新参数重建订单(订单金额、交易类型、收款地址、法币类型),同时超时时间重置。这意味着商户可以基于同一订单号实现独立收银台,灵活变更支付参数。
|
||||
|
||||
@@ -37,7 +37,7 @@ POST /api/v1/order/create-transaction
|
||||
| fiat | string | ❌ | 法币类型,默认 `CNY`<br/>可选:`CNY`、`USD`、`EUR`、`GBP`、`JPY` |
|
||||
| address | string | ❌ | 指定收款地址(留空则自动分配) |
|
||||
| name | string | ❌ | 商品名称 |
|
||||
| timeout | number | ❌ | 订单超时时间(秒),最低 60 秒<br/>留空则使用配置文件 `expire_time`,默认 600 秒 |
|
||||
| timeout | number | ❌ | 订单超时时间(秒),最低 120 秒<br/>留空则使用配置 `payment_timeout`,默认 600 秒 |
|
||||
| rate | string | ❌ | 强制指定汇率,支持多种写法:<br/>• `7.4` - 固定汇率 7.4<br/>• `~1.02` - 最新汇率上浮 2%<br/>• `~0.97` - 最新汇率下浮 3%<br/>• `+0.3` - 最新汇率加 0.3<br/>• `-0.2` - 最新汇率减 0.2<br/>留空则使用系统配置汇率 |
|
||||
|
||||
#### 请求示例
|
||||
@@ -69,9 +69,10 @@ POST /api/v1/order/create-transaction
|
||||
| data.order_id | string | 商户订单编号 |
|
||||
| data.amount | string | 请求支付金额(法币) |
|
||||
| data.actual_amount | string | 实际支付金额(加密货币) |
|
||||
| data.status | string | 订单状态,1 表示待付款 |
|
||||
| data.token | string | 收款地址 |
|
||||
| data.expiration_time | number | 订单有效期(秒) |
|
||||
| data.payment_url | string | 收银台地址 |
|
||||
| data.payment_url | string | 收银台付款链接地址 |
|
||||
|
||||
> **计算公式**:`actual_amount` = `amount` ÷ 汇率
|
||||
|
||||
@@ -89,6 +90,7 @@ POST /api/v1/order/create-transaction
|
||||
"actual_amount": "4.25",
|
||||
"token": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
||||
"expiration_time": 1200,
|
||||
"status": 1,
|
||||
"payment_url": "https://example.com/pay/checkout-counter/b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
},
|
||||
"request_id": ""
|
||||
@@ -97,7 +99,7 @@ POST /api/v1/order/create-transaction
|
||||
|
||||
---
|
||||
|
||||
### 2. 取消订单
|
||||
### 2. 取消交易订单
|
||||
|
||||
取消指定订单,系统将停止监控该订单并释放金额占用。
|
||||
|
||||
@@ -138,7 +140,271 @@ POST /api/v1/order/cancel-transaction
|
||||
|
||||
---
|
||||
|
||||
### 3. 支付回调通知
|
||||
### 3. 创建订单
|
||||
|
||||
创建支付订单并获取收银台付款链接,让用户自由选择已添加的付款方式。
|
||||
|
||||
> **注意**:使用相同 `order_id` 创建订单时,系统会根据最新参数重建订单(订单金额、交易类型、收款地址、法币类型),同时超时时间重置。这意味着商户可以基于同一订单号实现独立收银台,灵活变更支付参数。
|
||||
|
||||
#### 请求地址
|
||||
|
||||
```http
|
||||
POST /api/v1/order/create-order
|
||||
```
|
||||
|
||||
#### 请求参数
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------------|--------|----|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| order_id | string | ✅ | 商户订单编号(唯一标识) |
|
||||
| amount | number | ✅ | 支付金额(法币金额) |
|
||||
| notify_url | string | ✅ | 支付结果异步回调地址 |
|
||||
| redirect_url | string | ✅ | 支付成功后商户跳转地址 |
|
||||
| signature | string | ✅ | 签名字符串(详见[签名算法](#签名算法)) |
|
||||
| currencies | string | ❌ | 限定交易币种,留空则提不限制付款币种。<br/>多个币种请使用半角逗号分隔,黑名单模式以短横线开头。<br/>例如可配置为:<br/>`USDT`(仅限 USDT)<br/>`USDT,USDC` (限 USDT/USDC)<br/>`-ETH,-BNB` (表示排除 ETH/BNB 两个币种) |
|
||||
| fiat | string | ❌ | 法币类型,默认 `CNY`<br/>可选:`CNY`、`USD`、`EUR`、`GBP`、`JPY` |
|
||||
| name | string | ❌ | 商品名称 |
|
||||
| timeout | number | ❌ | 订单超时时间(秒),最低 180 秒<br/>留空则使用配置 `payment_timeout`,默认 600 秒 |
|
||||
|
||||
#### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"order_id": "20250120001",
|
||||
"amount": 28.88,
|
||||
"fiat": "CNY",
|
||||
"currencies": "USDT,USDC",
|
||||
"name": "测试商品",
|
||||
"notify_url": "https://example.com/notify",
|
||||
"redirect_url": "https://example.com/success",
|
||||
"timeout": 1200,
|
||||
"signature": "1cd4b52df5587cfb1968b0c0c6e156cd"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应参数
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
|----------------------|--------|--------------|
|
||||
| status_code | number | 状态码,200 表示成功 |
|
||||
| message | string | 响应消息 |
|
||||
| data | object | 订单数据 |
|
||||
| data.fiat | string | 交易法币类型 |
|
||||
| data.trade_id | string | 系统交易 ID |
|
||||
| data.order_id | string | 商户订单编号 |
|
||||
| data.amount | string | 请求支付金额(法币) |
|
||||
| data.status | string | 订单状态,1 表示待付款 |
|
||||
| data.expiration_time | number | 订单有效期(秒) |
|
||||
| data.payment_url | string | 收银台订单链接 |
|
||||
|
||||
> **计算公式**:`actual_amount` = `amount` ÷ 汇率
|
||||
|
||||
#### 响应示例
|
||||
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"fiat": "CNY",
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415",
|
||||
"order_id": "20250120001",
|
||||
"amount": "28.88",
|
||||
"expiration_time": 1200,
|
||||
"payment_url": "https://example.com/pay/order/b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. 更新订单付款方式
|
||||
|
||||
用于向订单付款链接传递付款方式,得到收银台付款地址。
|
||||
|
||||
> **注意**:使用相同 `trade_id` 更新订单时,系统会根据最新交易类型更新订单付款方式。
|
||||
|
||||
#### 请求地址
|
||||
|
||||
```http
|
||||
POST /api/v1/pay/update-order
|
||||
```
|
||||
|
||||
#### 请求参数
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------------|--------|----|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| trade_id | string | ✅ | 系统交易 ID |
|
||||
| currency | string | ✅ | 加密货币币种<br/>您已添加的加密货币币种,可选:`USDT`、`USDC`、`TRX` 等。 |
|
||||
| network | string | ✅ | 加密货币所属的网络名<br/>例如:`tron`、`polygon`、`bsc` 等。 |
|
||||
|
||||
#### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415",
|
||||
"currency": "USDT",
|
||||
"network": "tron"
|
||||
}
|
||||
```
|
||||
|
||||
#### 响应参数
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
|----------------------|--------|--------------|
|
||||
| status_code | number | 状态码,200 表示成功 |
|
||||
| message | string | 响应消息 |
|
||||
| data | object | 订单数据 |
|
||||
| data.fiat | string | 交易法币类型 |
|
||||
| data.trade_id | string | 系统交易 ID |
|
||||
| data.order_id | string | 商户订单编号 |
|
||||
| data.amount | string | 请求支付金额(法币) |
|
||||
| data.actual_amount | string | 实际支付金额(加密货币) |
|
||||
| data.status | string | 订单状态,1 表示待付款 |
|
||||
| data.expiration_time | number | 订单有效期(秒) |
|
||||
| data.payment_url | string | 收银台订单链接 |
|
||||
|
||||
> **计算公式**:`actual_amount` = `amount` ÷ 汇率
|
||||
|
||||
#### 响应示例
|
||||
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"fiat": "CNY",
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415",
|
||||
"order_id": "20250120001",
|
||||
"amount": "28.88",
|
||||
"actual_amount": "4.25",
|
||||
"expiration_time": 1200,
|
||||
"status": 1,
|
||||
"payment_url": "https://example.com/pay/order/b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. 订单可用付款方式列表:
|
||||
|
||||
## 接口说明
|
||||
- **URL**:`POST /api/v1/pay/methods`
|
||||
|
||||
---
|
||||
|
||||
## 请求参数
|
||||
|
||||
### 请求体(JSON)
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| trade_id | string | 是 | 系统交易 ID |
|
||||
| currency | string | 否 | 货币名称(如 USDT / USDC / TRX),不传则返回全部可用方式 |
|
||||
|
||||
### 请求示例
|
||||
```json
|
||||
{
|
||||
"trade_id": "b3d2477c-d945-41da-96b7-f925bbd1b415"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 响应参数
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| status_code | number | 状态码,200 表示成功 |
|
||||
| message | string | 响应消息 |
|
||||
| data | object | 数据对象 |
|
||||
| data.methods | array | 可用付款方式列表 |
|
||||
|
||||
### methods 字段说明
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| amount | number | 应付金额(法币) |
|
||||
| actual_amount | number | 实际支付金额(加密货币) |
|
||||
| fiat | string | 应付金额法币单位 |
|
||||
| exchange_rate | number | 汇率 |
|
||||
| currency | string | 货币名称 |
|
||||
| network | string | 网络名称 |
|
||||
| token_net_name | string | 代币协议标准名 |
|
||||
| token_custom_name | string | 用户自定义显示名称 |
|
||||
| is_popular | boolean | 是否为流行网络 |
|
||||
|
||||
---
|
||||
|
||||
## 响应示例
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"methods": [
|
||||
{
|
||||
"amount": "28.88",
|
||||
"actual_amount": "4.25",
|
||||
"fiat": "CNY",
|
||||
"exchange_rate": "",
|
||||
"currency": "USDT",
|
||||
"network": "bsc",
|
||||
"token_net_name": "BEP20",
|
||||
"token_custom_name": "",
|
||||
"is_popular": true
|
||||
},
|
||||
{
|
||||
"amount": "28.88",
|
||||
"actual_amount": "4.25",
|
||||
"fiat": "CNY",
|
||||
"exchange_rate": "",
|
||||
"currency": "USDC",
|
||||
"network": "arbitrum",
|
||||
"token_net_name": "Arbitrum",
|
||||
"token_custom_name": "ARBITRUM-ONE",
|
||||
"is_popular": true
|
||||
},
|
||||
{
|
||||
"amount": "34.28",
|
||||
"actual_amount": "10",
|
||||
"fiat": "CNY",
|
||||
"exchange_rate": "",
|
||||
"currency": "TRX",
|
||||
"network": "tron",
|
||||
"token_net_name": "TRC20",
|
||||
"token_custom_name": "",
|
||||
"is_popular": true
|
||||
},
|
||||
]
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
TODO: `is_popular` 当前临时返回为 `false` 待后期完善该功能。
|
||||
|
||||
TODO: `token_custom_name` 当前临时返回为空字符串,待后期完善该功能。
|
||||
|
||||
## 如果货币不存在则不响应内容
|
||||
```json
|
||||
{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"methods": [
|
||||
]
|
||||
},
|
||||
"request_id": ""
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 6. 支付回调通知
|
||||
|
||||
订单状态变更时,系统会向 `notify_url` 发送 POST 请求。
|
||||
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
# Dujiao-Next 对接教程
|
||||
|
||||
本文档介绍如何在 [Dujiao-Next](https://github.com/dujiao-next/dujiao-next)(独角next)中对接 BEpusdt。
|
||||
|
||||
## 前置条件
|
||||
|
||||
- BEpusdt 已成功安装并运行
|
||||
- Dujiao-Next 已部署
|
||||
|
||||
## 配置步骤
|
||||
|
||||
### 1. 进入支付渠道配置
|
||||
|
||||
Dujiao-Next 后台 → 支付渠道 → 新增渠道
|
||||
|
||||
### 2. 基本参数填写
|
||||
|
||||
| 参数名称 | 填写内容 | 说明 |
|
||||
|---------|---------|------|
|
||||
| 渠道名称 | USDT-TRC20 支付 | 自定义名称,建议包含币种 |
|
||||
| 渠道类型 | `epusdt` | 固定值,选择 BEpusdt |
|
||||
| 支付方式 | `usdt-trc20` / `usdc-trc20` / `trx` | 选择支持的币种 |
|
||||
| 交互方式 | `qr` 或 `redirect` | 二维码或跳转收银台 |
|
||||
|
||||
### 3. 支持的渠道类型
|
||||
|
||||
Dujiao-Next 支持以下 BEpusdt 币种:
|
||||
|
||||
| 渠道类型 | 说明 | 对应 trade_type |
|
||||
|---------|------|----------------|
|
||||
| `usdt-trc20` | USDT (TRC20) | `usdt.trc20` |
|
||||
| `usdc-trc20` | USDC (TRC20) | `usdc.trc20` |
|
||||
| `trx` | TRX | `tron.trx` |
|
||||
|
||||
> **注意**:选择渠道类型后,系统会自动设置对应的 `trade_type`,无需手动填写。
|
||||
|
||||
### 4. 渠道配置参数
|
||||
|
||||
在「渠道配置」中填写以下 JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"gateway_url": "https://your-bepusdt-domain.com",
|
||||
"auth_token": "your-api-token",
|
||||
"fiat": "CNY",
|
||||
"notify_url": "https://your-api-domain.com/api/v1/payments/callback",
|
||||
"return_url": "https://your-user-domain.com/pay"
|
||||
}
|
||||
```
|
||||
|
||||
### 5. 配置参数说明
|
||||
|
||||
| 参数 | 必填 | 说明 | 示例 |
|
||||
|------|------|------|------|
|
||||
| `gateway_url` | ✅ | BEpusdt 网关地址 | `https://pay.example.com` |
|
||||
| `auth_token` | ✅ | BEpusdt API Token | 从 BEpusdt 后台获取 |
|
||||
| `trade_type` | ❌ | 交易类型(自动设置) | `usdt.trc20` / `usdc.trc20` / `tron.trx` |
|
||||
| `fiat` | ❌ | 法币类型,默认 `CNY` | `CNY` / `USD` |
|
||||
| `notify_url` | ✅ | 异步回调地址 | `https://api.example.com/api/v1/payments/callback` |
|
||||
| `return_url` | ✅ | 支付成功跳转地址 | `https://shop.example.com/pay` |
|
||||
|
||||
> **重要提示**:
|
||||
> - `trade_type` 会根据「支付方式」自动设置,无需在配置中填写
|
||||
> - `notify_url` 路径必须是 `/api/v1/payments/callback`(不是 `/api/public/payment/callback`)
|
||||
> - `return_url` 路径必须是 `/pay`(不是 `/order` 或 `/payment`)
|
||||
|
||||
## 获取 API Token
|
||||
|
||||
1. 登录 BEpusdt 后台
|
||||
2. 系统管理 → 基本设置 → API 设置
|
||||
3. 复制「对接令牌」
|
||||
|
||||
## 配置示例
|
||||
|
||||
### 示例 1:USDT-TRC20 支付
|
||||
|
||||
```
|
||||
渠道名称: USDT-TRC20 支付
|
||||
渠道类型: epusdt
|
||||
支付方式: usdt-trc20
|
||||
交互方式: qr
|
||||
|
||||
渠道配置:
|
||||
{
|
||||
"gateway_url": "http://127.0.0.1:8088",
|
||||
"auth_token": "your-token-here",
|
||||
"fiat": "CNY",
|
||||
"notify_url": "https://api.example.com/api/v1/payments/callback",
|
||||
"return_url": "https://shop.example.com/pay"
|
||||
}
|
||||
```
|
||||
|
||||
### 示例 2:TRX 支付
|
||||
|
||||
```
|
||||
渠道名称: TRX 支付
|
||||
渠道类型: epusdt
|
||||
支付方式: trx
|
||||
交互方式: redirect
|
||||
|
||||
渠道配置:
|
||||
{
|
||||
"gateway_url": "http://127.0.0.1:8088",
|
||||
"auth_token": "your-token-here",
|
||||
"fiat": "CNY",
|
||||
"notify_url": "https://api.example.com/api/v1/payments/callback",
|
||||
"return_url": "https://shop.example.com/pay"
|
||||
}
|
||||
```
|
||||
|
||||
## 回调机制说明
|
||||
|
||||
### 异步通知(notify_url)
|
||||
|
||||
BEpusdt 会在支付状态变化时,向 `notify_url` 发送 POST 请求:
|
||||
|
||||
```
|
||||
POST /api/v1/payments/callback
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
order_id=xxx&trade_id=xxx&amount=xxx&actual_amount=xxx&token=xxx&...&signature=xxx
|
||||
```
|
||||
|
||||
Dujiao-Next 会验证签名并更新订单状态。
|
||||
|
||||
### 同步跳转(return_url)
|
||||
|
||||
用户支付完成后,BEpusdt 会跳转到 `return_url`,并附带参数:
|
||||
|
||||
```
|
||||
https://shop.example.com/pay?order_id=xxx&epusdt_return=1
|
||||
```
|
||||
|
||||
Dujiao-Next 前端会检测 `epusdt_return=1` 参数,自动查询订单状态并显示支付结果。
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 1. 支付创建失败
|
||||
|
||||
**可能原因**:
|
||||
- `gateway_url` 配置错误或 BEpusdt 服务未运行
|
||||
- `auth_token` 与 BEpusdt 配置不一致
|
||||
- 网络连接问题(检查防火墙)
|
||||
|
||||
**解决方法**:
|
||||
- 检查 BEpusdt 服务状态:`curl http://your-bepusdt/health`
|
||||
- 验证 API Token 是否正确
|
||||
- 查看 Dujiao-Next 后端日志
|
||||
|
||||
### 2. 回调未收到或订单状态未更新
|
||||
|
||||
**可能原因**:
|
||||
- `notify_url` 配置错误(路径必须是 `/api/v1/payments/callback`)
|
||||
- BEpusdt 无法访问回调地址(网络/防火墙问题)
|
||||
- 签名验证失败
|
||||
|
||||
**解决方法**:
|
||||
- 确认回调地址可被外网访问:`curl https://your-api/api/v1/payments/callback`
|
||||
- 检查 BEpusdt 日志中的回调错误
|
||||
- 检查 Dujiao-Next 后端日志中的签名验证信息
|
||||
|
||||
### 3. 支付完成后跳转错误
|
||||
|
||||
**可能原因**:
|
||||
- `return_url` 路径配置错误(必须是 `/pay` 不是 `/payment` 或 `/order`)
|
||||
- 前端路由配置问题
|
||||
|
||||
**解决方法**:
|
||||
- 确认 `return_url` 配置为:`https://your-user-domain.com/pay`
|
||||
- 清除浏览器缓存后重试
|
||||
|
||||
### 4. 签名验证失败
|
||||
|
||||
**可能原因**:
|
||||
- `auth_token` 不一致(注意前后空格)
|
||||
- 回调参数被中间件修改
|
||||
|
||||
**解决方法**:
|
||||
- 确保 `auth_token` 完全一致
|
||||
- 检查是否有反向代理修改了请求参数
|
||||
|
||||
### 5. 金额不匹配
|
||||
|
||||
**可能原因**:
|
||||
- 汇率波动导致实际支付金额与订单金额不同
|
||||
- BEpusdt 配置的汇率源问题
|
||||
|
||||
**解决方法**:
|
||||
- BEpusdt 会返回 `actual_amount`(实际支付金额),Dujiao-Next 会记录此金额
|
||||
- 可在订单详情中查看实际支付金额
|
||||
|
||||
## 技术支持
|
||||
|
||||
- Dujiao-Next: [GitHub Issues](https://github.com/dujiao-next/dujiao-next/issues)
|
||||
- BEpusdt: [Telegram 群组](https://t.me/BEpusdtChat)
|
||||
|
||||
---
|
||||
|
||||
**贡献者**: 狼哥 ([@luoyanglang](https://github.com/luoyanglang) | Telegram: [@luoyanglang](https://t.me/luoyanglang))
|
||||
|
||||
> 本文档适用于 Dujiao-Next 最新版本和 BEpusdt 最新版本
|
||||
> 最后更新:2026-02-13
|
||||
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 125 KiB |
@@ -43,7 +43,7 @@
|
||||
| 参数名称 | 填写内容 | 说明 |
|
||||
|------------|-----------------------------------------------------------|---------------------------------------------------------------------------|
|
||||
| **商户ID** | 与 `BEpusdt` 中 `AUTH_TOKEN` 参数保持一致 | 用于身份验证 |
|
||||
| **支付标识** | 收款交易类型 | 可选值:`tron.trx`、`usdt.trc20`、`usdt.erc20` 等<br/>[完整列表参考](../trade-type.md) |
|
||||
| **支付标识** | 收款交易类型 | 可选值:`tron.trx`、`usdt.trc20`、`usdt.erc20` 等<br/>[完整列表参考](../../trade-type.md) |
|
||||
| **商户密钥** | `https://your-domain.com/api/v1/order/create-transaction` | ⚠️ 请将 `your-domain.com` 替换为实际域名 |
|
||||
| **支付处理路由** | `pay/epusdt` | 固定值,无需修改 |
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
|
||||
> 路径:后台 -> 插件管理 -> 应用商店 -> 支付插件 -> 易支付
|
||||
|
||||

|
||||

|
||||
|
||||
找到这个插件,并把他安装下来,随后启用。
|
||||
|
||||

|
||||

|
||||
|
||||
### 2.支付配置
|
||||
|
||||
点击添加配置,配置自己的`Bepusdt`信息,参考如下:
|
||||
|
||||

|
||||

|
||||
|
||||
### 3.增加支付通道
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
,需有对原版代码进行替换;请把这个文件[Pay.php](https://raw.githubusercontent.com/v03413/bepusdt/refs/heads/main/docs/mcy-shop/Pay.php)
|
||||
下载下来,替换到你的网站路径`/app/Plugin/Epay/Config`下的同名文件。
|
||||
|
||||

|
||||

|
||||
|
||||
### 4.增加支付接口
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
> 支付通道:自行选择
|
||||
> 支付配置:选择第二步添加的配置
|
||||
>
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
其它参数根据自己的需求填写即可,填好之后即可开始测试是否对接成功!
|
||||
@@ -0,0 +1,23 @@
|
||||
# 第三方程序对接指南
|
||||
|
||||
## 兼容性说明
|
||||
|
||||
关于第三方程序的适配对接问题,建议您优先向您的程序开发者反馈,或在相关技术社区寻求支持,具体的适配进度和时效性无法保证。
|
||||
|
||||
### 兼容性特性
|
||||
|
||||
1. **Epusdt 兼容**:BEpusdt 与 Epusdt 插件保持高度兼容,理论上所有已适配 `Epusdt` 的程序均可无缝迁移至 `BEpusdt`
|
||||
。建议在正式环境部署前,先在测试环境中进行充分验证。
|
||||
|
||||
2. **彩虹易支付兼容**:原生支持`彩虹易支付`的 `submit.php` 提交接口标准,因此大多数已适配`彩虹易支付`的程序可直接集成使用。
|
||||
|
||||
## 对接教程
|
||||
|
||||
以下是常见程序的对接文档,请根据您的实际需求选择相应教程进行配置。如遇问题,请仔细核对操作步骤,或在相关技术社区寻求协助。
|
||||
|
||||
- [独角数卡](./dujiaoka/dujiaoka.md)
|
||||
- [彩虹易支付](https://github.com/v03413/Epay-BEpusdt)
|
||||
- [WHMCS](https://github.com/v03413/whmcs-gateway-epusdt)
|
||||
- [异次元发卡](acg-faka/README.md)
|
||||
- [萌次元商城](./mcy-faka/mcy-shop.md)
|
||||
|
||||
@@ -44,6 +44,10 @@ require (
|
||||
github.com/gorilla/context v1.1.2 // indirect
|
||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||
github.com/gorilla/sessions v1.4.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
@@ -52,6 +56,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
@@ -70,8 +75,9 @@ require (
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/driver/postgres v1.6.0 // indirect
|
||||
modernc.org/libc v1.65.10 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
|
||||
@@ -106,6 +106,14 @@ github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzq
|
||||
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
@@ -122,8 +130,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
@@ -137,6 +148,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
@@ -274,6 +287,7 @@ google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -284,6 +298,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
|
||||
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
|
||||
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
|
||||
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
|
||||
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
|
||||
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
|
||||
modernc.org/cc/v4 v4.26.1 h1:+X5NtzVBn0KgsBCBe+xkDC7twLb/jNVj9FPgiwSQO3s=
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
.selector-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: white !important;
|
||||
padding: 32px !important;
|
||||
gap: 32px;
|
||||
margin-bottom: 32px !important;
|
||||
border-radius: 7px !important;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
||||
}
|
||||
|
||||
.selector-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.selector-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.coin-select {
|
||||
outline: 1px solid #e8e8e8;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 18px 22px 18px 16px;
|
||||
}
|
||||
|
||||
.coin-select span {
|
||||
margin: 0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.pay-button {
|
||||
cursor: pointer;
|
||||
font-family: Golos, sans-serif;
|
||||
padding: 18px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
background: #667eea;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.pay-button:hover {
|
||||
background-color: #5a67d8;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.pay-button p {
|
||||
color: #fff;
|
||||
margin: 0;
|
||||
height: 20px;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 20px;
|
||||
letter-spacing: -.12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
column-gap: 10px;
|
||||
}
|
||||
|
||||
/* Dropdown Styles */
|
||||
.selector-container {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.coin-select {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
background: var(--bg-card-light, #f8f9fa);
|
||||
/* Fallback or use variable if exists */
|
||||
border: 1px solid var(--border-color, #e9ecef);
|
||||
border-radius: 12px;
|
||||
padding: 12px 16px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.coin-select:hover {
|
||||
border-color: var(--primary-color, #2d60e0);
|
||||
background: #fff;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.coin-select.active {
|
||||
border-color: var(--primary-color, #2d60e0);
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 3px rgba(45, 96, 224, 0.1);
|
||||
}
|
||||
|
||||
.coin-select span {
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
color: #4a5568;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.coin-select svg {
|
||||
color: var(--text-secondary, #8590a6);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.coin-select.active svg {
|
||||
transform: rotate(180deg);
|
||||
color: var(--primary-color, #2d60e0);
|
||||
}
|
||||
|
||||
/* Options Dropdown */
|
||||
.options-list {
|
||||
position: absolute;
|
||||
top: calc(100% + 8px);
|
||||
left: 0;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
border: 1px solid var(--border-color, #e9ecef);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
||||
z-index: 100;
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transform: translateY(-10px);
|
||||
transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.coin-select.active .options-list {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.option-item {
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.option-item:hover {
|
||||
background: var(--bg-hover, #f5f7fa);
|
||||
}
|
||||
|
||||
.option-item.selected {
|
||||
background: rgba(45, 96, 224, 0.08);
|
||||
color: var(--primary-color, #2d60e0);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.option-item .option-text {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.option-item .option-badge {
|
||||
font-size: 12px;
|
||||
padding: 2px 6px;
|
||||
background: #edf2f7;
|
||||
border-radius: 4px;
|
||||
color: #718096;
|
||||
}
|
||||
|
||||
/* Scrollbar styling */
|
||||
.options-list::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.options-list::-webkit-scrollbar-thumb {
|
||||
background-color: #cbd5e0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.options-list::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.pay-button:disabled {
|
||||
background: #bdbdbd; /* 灰色背景 */
|
||||
color: #f5f5f5;
|
||||
cursor: not-allowed;
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
transform: none;
|
||||
}
|
||||
@@ -0,0 +1,724 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
let i18nInitialized = false;
|
||||
let paymentMethods = [];
|
||||
let selectedCurrency = '';
|
||||
let selectedNetwork = '';
|
||||
let selectedMethod = null;
|
||||
let paymentConfig = {};
|
||||
|
||||
// DOM Elements (initialized in init)
|
||||
let currencySelectEl = null;
|
||||
let networkSelectEl = null;
|
||||
let payButton = null;
|
||||
let amountValue = null;
|
||||
let networkBadge = null;
|
||||
|
||||
// countdown
|
||||
let countdownTimer = null;
|
||||
let statusCheckTimer = null;
|
||||
let totalSeconds = 0;
|
||||
|
||||
let tradeId = '';
|
||||
|
||||
function initI18n() {
|
||||
if (i18nInitialized) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
let currentLang = localStorage.getItem('payment_language') || navigator.language.split('-')[0] || 'en';
|
||||
if (currentLang !== 'zh' && currentLang !== 'en') {
|
||||
currentLang = 'en';
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (typeof i18next === 'undefined') {
|
||||
console.error('i18next is not loaded');
|
||||
resolve(); // Fail gracefully
|
||||
return;
|
||||
}
|
||||
|
||||
i18next.init({
|
||||
lng: currentLang,
|
||||
debug: false,
|
||||
resources: {}
|
||||
}, function (err, t) {
|
||||
if (err) {
|
||||
console.error('i18next initialization failed:', err);
|
||||
resolve(); // Fail gracefully
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/payment/assets/locales/' + currentLang + '.json')
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (translations) {
|
||||
i18next.addResourceBundle(currentLang, 'translation', translations);
|
||||
i18nInitialized = true;
|
||||
updateContent();
|
||||
|
||||
// Update language switcher if it exists
|
||||
const languageSwitcher = document.getElementById('languageSwitcher');
|
||||
if (languageSwitcher) {
|
||||
languageSwitcher.value = currentLang;
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error('Failed to load language file:', error);
|
||||
resolve(); // Fail gracefully
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function changeLanguage(lang) {
|
||||
if (!i18next) return;
|
||||
|
||||
const hasLanguage = i18next.hasResourceBundle(lang, 'translation');
|
||||
|
||||
if (!hasLanguage) {
|
||||
fetch('/payment/assets/locales/' + lang + '.json')
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (translations) {
|
||||
i18next.addResourceBundle(lang, 'translation', translations);
|
||||
return i18next.changeLanguage(lang);
|
||||
})
|
||||
.then(function () {
|
||||
localStorage.setItem('payment_language', lang);
|
||||
updateContent();
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error('Failed to load language file:', error);
|
||||
});
|
||||
} else {
|
||||
i18next.changeLanguage(lang, function (err, t) {
|
||||
if (err) {
|
||||
console.error('Language change failed:', err);
|
||||
return;
|
||||
}
|
||||
localStorage.setItem('payment_language', lang);
|
||||
updateContent();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getPaymentConfig() {
|
||||
return paymentConfig;
|
||||
}
|
||||
|
||||
function replacePlaceholders(text) {
|
||||
const config = getPaymentConfig();
|
||||
|
||||
let token = (config.token || '--').toUpperCase();
|
||||
let network = selectedMethod ? (selectedMethod.network || '--').toUpperCase() : '--';
|
||||
let networkName = selectedMethod ? (selectedMethod.token_net_name || '--').toUpperCase() : '--';
|
||||
|
||||
if (selectedMethod) {
|
||||
token = selectedMethod.currency.toUpperCase();
|
||||
network = selectedMethod.network.toUpperCase();
|
||||
networkName = selectedMethod.token_net_name.toUpperCase();
|
||||
} else if (selectedCurrency) {
|
||||
token = selectedCurrency.toUpperCase();
|
||||
}
|
||||
|
||||
return text
|
||||
.replace(/\{\{token\}\}/g, token)
|
||||
.replace(/\{\{network\}\}/g, network)
|
||||
.replace(/\{\{networkName\}\}/g, networkName);
|
||||
}
|
||||
|
||||
function updateContent() {
|
||||
if (!i18next) return;
|
||||
|
||||
const elements = document.querySelectorAll('[data-i18n]');
|
||||
elements.forEach(function (element) {
|
||||
// Special handling for dropdowns to preserve structure
|
||||
if (element.classList.contains('coin-select')) {
|
||||
const sp = element.querySelector('span');
|
||||
if (sp) {
|
||||
const key = element.getAttribute('data-i18n');
|
||||
let translation = i18next.t(key);
|
||||
sp.textContent = translation;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Protect dropdowns from internal structure destruction if not caught above
|
||||
if (element.querySelector('.options-list')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const key = element.getAttribute('data-i18n');
|
||||
|
||||
if (key.startsWith('[')) {
|
||||
const matches = key.match(/\[(.+?)\](.+)/);
|
||||
if (matches) {
|
||||
const attr = matches[1];
|
||||
const transKey = matches[2];
|
||||
let translation = i18next.t(transKey);
|
||||
translation = replacePlaceholders(translation);
|
||||
|
||||
if (attr === 'html') {
|
||||
element.innerHTML = translation;
|
||||
} else {
|
||||
element.setAttribute(attr, translation);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let translation = i18next.t(key);
|
||||
translation = replacePlaceholders(translation);
|
||||
|
||||
if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {
|
||||
element.placeholder = translation;
|
||||
} else {
|
||||
element.innerHTML = translation;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function t(key, defaultValue) {
|
||||
if (i18nInitialized && i18next) {
|
||||
let translation = i18next.t(key);
|
||||
return replacePlaceholders(translation);
|
||||
}
|
||||
return defaultValue || key;
|
||||
}
|
||||
|
||||
function setupDropdown(el, onSelectCallback) {
|
||||
if (!el) return;
|
||||
|
||||
el.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
const otherSelects = document.querySelectorAll('.coin-select');
|
||||
otherSelects.forEach(function (other) {
|
||||
if (other !== el) other.classList.remove('active');
|
||||
});
|
||||
el.classList.toggle('active');
|
||||
});
|
||||
|
||||
// The logic for populating the list is in renderOptions,
|
||||
// but the event listener for global click is needed once.
|
||||
}
|
||||
|
||||
function initSelection() {
|
||||
if (!paymentMethods || paymentMethods.length === 0) return;
|
||||
|
||||
// Extract unique currencies
|
||||
const currencies = [...new Set(paymentMethods.map(function (m) {
|
||||
return m.currency;
|
||||
}))];
|
||||
|
||||
// Render Currency Options
|
||||
renderOptions(currencySelectEl, currencies.map(function (c) {
|
||||
return {value: c, label: c, badge: ''};
|
||||
}), function (val) {
|
||||
selectedCurrency = val;
|
||||
updateNetworkOptions();
|
||||
// We need to update UI for crypto-icon when currency changes
|
||||
updateUI();
|
||||
});
|
||||
|
||||
// Default Select First Currency removed to allow "Please select" state
|
||||
// Initial UI update to ensure consistent state
|
||||
updateUI();
|
||||
}
|
||||
|
||||
function updateNetworkOptions() {
|
||||
const networks = paymentMethods
|
||||
.filter(function (m) {
|
||||
return m.currency === selectedCurrency;
|
||||
})
|
||||
.map(function (m) {
|
||||
return {
|
||||
value: m.token_net_name,
|
||||
label: m.token_net_name.toUpperCase(),
|
||||
fullData: m
|
||||
};
|
||||
});
|
||||
|
||||
renderOptions(networkSelectEl, networks, function (val, item) {
|
||||
selectedNetwork = val;
|
||||
selectedMethod = item.fullData;
|
||||
updateUI();
|
||||
updateContent();
|
||||
});
|
||||
|
||||
// Reset selection but do NOT auto-select
|
||||
selectedNetwork = '';
|
||||
selectedMethod = null;
|
||||
|
||||
// Reset dropdown UI
|
||||
if (networkSelectEl) {
|
||||
const sp = networkSelectEl.querySelector('span');
|
||||
if (sp) {
|
||||
sp.setAttribute('data-i18n', 'payment.selectNetwork');
|
||||
// Let updateContent() handle the text update
|
||||
}
|
||||
}
|
||||
|
||||
updateUI();
|
||||
updateContent();
|
||||
}
|
||||
|
||||
function renderOptions(parent, items, onSelect) {
|
||||
if (!parent) return;
|
||||
|
||||
let list = parent.querySelector('.options-list');
|
||||
if (!list) {
|
||||
list = document.createElement('div');
|
||||
list.className = 'options-list';
|
||||
parent.appendChild(list);
|
||||
}
|
||||
|
||||
list.innerHTML = '';
|
||||
|
||||
items.forEach(function (item) {
|
||||
const itemEl = document.createElement('div');
|
||||
itemEl.className = 'option-item';
|
||||
itemEl.setAttribute('data-value', item.value);
|
||||
|
||||
let html = '<span class="option-text">' + item.label + '</span>';
|
||||
if (item.badge) {
|
||||
html += '<span class="option-badge">' + item.badge + '</span>';
|
||||
}
|
||||
itemEl.innerHTML = html;
|
||||
|
||||
itemEl.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
parent.classList.remove('active');
|
||||
selectOption(parent, item.value);
|
||||
if (onSelect) onSelect(item.value, item);
|
||||
});
|
||||
|
||||
list.appendChild(itemEl);
|
||||
});
|
||||
}
|
||||
|
||||
function selectOption(parent, value) {
|
||||
if (!parent) return;
|
||||
|
||||
const items = parent.querySelectorAll('.option-item');
|
||||
items.forEach(function (item) {
|
||||
item.classList.remove('selected');
|
||||
});
|
||||
|
||||
let selected = null;
|
||||
items.forEach(function (item) {
|
||||
if (item.getAttribute('data-value') === value) selected = item;
|
||||
});
|
||||
|
||||
if (selected) {
|
||||
selected.classList.add('selected');
|
||||
const text = selected.querySelector('.option-text').textContent;
|
||||
const sp = parent.querySelector('span');
|
||||
if (sp) {
|
||||
sp.textContent = text || value;
|
||||
// Avoid i18n overwriting the selected value
|
||||
sp.removeAttribute('data-i18n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
// Update crypto-icon, default to '--' if no selection
|
||||
const cryptoIcon = document.querySelector('.crypto-icon');
|
||||
if (cryptoIcon) {
|
||||
cryptoIcon.textContent = selectedCurrency ? selectedCurrency.toUpperCase() : '--';
|
||||
}
|
||||
|
||||
const subtitleSpan = document.querySelector('.payment-subtitle span[data-i18n]');
|
||||
const subtitleP = document.querySelector('.payment-subtitle');
|
||||
let networkBadge = document.querySelector('.network-badge');
|
||||
|
||||
if (!selectedMethod) {
|
||||
if (payButton) payButton.disabled = true;
|
||||
if (amountValue) amountValue.textContent = '---';
|
||||
|
||||
// Revert to subtitle2 (Please select...)
|
||||
if (subtitleSpan) {
|
||||
subtitleSpan.setAttribute('data-i18n', 'payment.subtitle2');
|
||||
}
|
||||
// Remove badge if exists
|
||||
if (networkBadge) {
|
||||
networkBadge.remove();
|
||||
networkBadge = null; // Clear reference
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch to subtitle (Please use...)
|
||||
if (subtitleSpan) {
|
||||
subtitleSpan.setAttribute('data-i18n', 'payment.subtitleCashier');
|
||||
}
|
||||
|
||||
// Inject network badge if missing
|
||||
if (!networkBadge && subtitleP) {
|
||||
networkBadge = document.createElement('span');
|
||||
networkBadge.className = 'network-badge';
|
||||
networkBadge.setAttribute('data-i18n', 'payment.networkBadge');
|
||||
subtitleP.appendChild(networkBadge);
|
||||
}
|
||||
|
||||
// Update Amount
|
||||
if (amountValue) {
|
||||
amountValue.textContent = selectedMethod.actual_amount + ' ' + selectedMethod.currency;
|
||||
}
|
||||
|
||||
// Update Network Badge
|
||||
if (networkBadge) {
|
||||
networkBadge.textContent = selectedMethod.token_net_name;
|
||||
}
|
||||
|
||||
// Enable Pay Button
|
||||
if (payButton) {
|
||||
payButton.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function createTransaction() {
|
||||
if (!selectedMethod) return;
|
||||
if (payButton && payButton.disabled) return;
|
||||
|
||||
fetch('/api/v1/pay/update-order', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
trade_id: tradeId,
|
||||
currency: selectedMethod.currency,
|
||||
network: selectedMethod.network
|
||||
})
|
||||
})
|
||||
.then(function (response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function (res) {
|
||||
if (res.status_code === 200 && res.data.payment_url) {
|
||||
window.location.href = res.data.payment_url;
|
||||
} else {
|
||||
showMessage(res.message || t('payment.createTransactionFailed', 'Failed to create transaction'));
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
showMessage(t('payment.networkError', 'Network error'));
|
||||
});
|
||||
}
|
||||
|
||||
function showMessage(msg) {
|
||||
if (window.layer && window.layer.msg) {
|
||||
window.layer.msg(msg);
|
||||
} else {
|
||||
alert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function copyToClipboard(text, element, isButton) {
|
||||
if (!text) return;
|
||||
|
||||
navigator.clipboard.writeText(text).then(function () {
|
||||
showCopySuccess(element, isButton);
|
||||
}).catch(function (err) {
|
||||
console.error('复制失败: ', err);
|
||||
fallbackCopy(text, element, isButton);
|
||||
});
|
||||
}
|
||||
|
||||
function showCopySuccess(element, isButton) {
|
||||
const t = window.i18next ? window.i18next.t.bind(window.i18next) : function (key) {
|
||||
const translations = {
|
||||
'payment.copied': '已复制!',
|
||||
'payment.copySuccess': '✓ 已复制!'
|
||||
};
|
||||
return translations[key] || key;
|
||||
};
|
||||
|
||||
if (isButton) {
|
||||
const originalText = element.textContent;
|
||||
element.textContent = t('payment.copied');
|
||||
element.style.background = '#48bb78';
|
||||
setTimeout(function () {
|
||||
element.textContent = originalText;
|
||||
element.style.background = '#667eea';
|
||||
}, 2000);
|
||||
} else {
|
||||
const originalText = element.textContent;
|
||||
const originalColor = element.style.color;
|
||||
element.textContent = t('payment.copySuccess');
|
||||
element.style.color = '#48bb78';
|
||||
setTimeout(function () {
|
||||
element.textContent = originalText;
|
||||
element.style.color = originalColor;
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
function fallbackCopy(text, element, isButton) {
|
||||
const t = window.i18next ? window.i18next.t.bind(window.i18next) : function (key) {
|
||||
const translations = {
|
||||
'payment.copyFailed': '复制失败,请手动复制'
|
||||
};
|
||||
return translations[key] || key;
|
||||
};
|
||||
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.opacity = '0';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
showCopySuccess(element, isButton);
|
||||
} catch (err) {
|
||||
alert(t('payment.copyFailed'));
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
|
||||
function copyAmount() {
|
||||
const amountEl = document.getElementById('payAmount');
|
||||
let text = '';
|
||||
if (selectedMethod && selectedMethod.actual_amount) {
|
||||
text = selectedMethod.actual_amount;
|
||||
} else if (amountEl) {
|
||||
// Fallback to text content if no method selected (though usually it's ---)
|
||||
const content = amountEl.textContent.trim();
|
||||
if (content !== '---') {
|
||||
text = content.split(' ')[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (text) {
|
||||
copyToClipboard(text, amountEl, false);
|
||||
}
|
||||
}
|
||||
|
||||
function startCountdown() {
|
||||
if (countdownTimer) clearInterval(countdownTimer);
|
||||
|
||||
const config = getPaymentConfig();
|
||||
// Ensure expire is a number
|
||||
let expireTime = parseInt(config.expire);
|
||||
if (isNaN(expireTime)) {
|
||||
expireTime = 0;
|
||||
}
|
||||
totalSeconds = expireTime;
|
||||
|
||||
const minutesEl = document.getElementById('minutes');
|
||||
const secondsEl = document.getElementById('seconds');
|
||||
const countdownBanner = document.querySelector('.countdown-banner');
|
||||
|
||||
function updateDisplay() {
|
||||
if (!minutesEl || !secondsEl) return;
|
||||
|
||||
const minutes = Math.floor(Math.max(0, totalSeconds) / 60);
|
||||
const seconds = Math.max(0, totalSeconds) % 60;
|
||||
|
||||
if (totalSeconds <= 0) {
|
||||
minutesEl.textContent = '00';
|
||||
secondsEl.textContent = '00';
|
||||
} else {
|
||||
minutesEl.textContent = minutes.toString().padStart(2, '0');
|
||||
secondsEl.textContent = seconds.toString().padStart(2, '0');
|
||||
}
|
||||
|
||||
if (countdownBanner) {
|
||||
if (totalSeconds <= 300) {
|
||||
countdownBanner.style.background = 'linear-gradient(135deg, #ff4757, #ff3838)';
|
||||
}
|
||||
if (totalSeconds <= 60) {
|
||||
countdownBanner.style.animation = 'urgentBlink 1s infinite';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateDisplay(); // Initial display
|
||||
|
||||
countdownTimer = setInterval(function () {
|
||||
totalSeconds--;
|
||||
updateDisplay();
|
||||
|
||||
if (totalSeconds <= 0) {
|
||||
clearInterval(countdownTimer);
|
||||
if (statusCheckTimer) clearInterval(statusCheckTimer);
|
||||
showTimeoutMessage();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function showTimeoutMessage() {
|
||||
// Prevent multiple overlays
|
||||
if (document.querySelector('.status-overlay')) return;
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'status-overlay';
|
||||
overlay.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); display: flex; align-items: center; justify-content: center; z-index: 9999;';
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.style.cssText = 'background: white; padding: 30px; border-radius: 12px; text-align: center; max-width: 400px; width: 90%; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);';
|
||||
|
||||
const config = getPaymentConfig();
|
||||
|
||||
modal.innerHTML = '<div style="font-size: 48px; margin-bottom: 20px;">⏰</div>' +
|
||||
'<h3 style="color: #e53e3e; margin-bottom: 15px;">' + t('payment.paymentTimeout', 'Payment Timeout') + '</h3>' +
|
||||
'<p style="color: #666; margin-bottom: 25px; line-height: 1.5;">' +
|
||||
t('payment.timeoutMessage', 'Sorry, the payment time has expired.<br>Please restart payment.') +
|
||||
'</p>' +
|
||||
'<button onclick="location.href=\'' + (config.return_url || '/') + '\'" style="background: #667eea; color: white; border: none; padding: 12px 24px; border-radius: 6px; cursor: pointer; font-size: 14px; margin-right: 10px;">' +
|
||||
t('payment.returnToMerchant', 'Return to Merchant') +
|
||||
'</button>';
|
||||
|
||||
overlay.appendChild(modal);
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
|
||||
function showWaitingConfirmation(data) {
|
||||
if (document.getElementById('waiting-overlay')) return;
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
overlay.id = 'waiting-overlay';
|
||||
overlay.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); display: flex; align-items: center; justify-content: center; z-index: 9999;';
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.style.cssText = 'background: white; padding: 30px; border-radius: 12px; text-align: center; max-width: 400px; width: 90%; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);';
|
||||
|
||||
modal.innerHTML = '<div style="font-size: 48px; margin-bottom: 20px; animation: spin 2s linear infinite;">⏳</div>' +
|
||||
'<h3 style="color: #667eea; margin-bottom: 15px;">' + t('payment.waitingConfirmation', 'Waiting for Confirmation') + '</h3>' +
|
||||
'<p style="color: #666; margin-bottom: 20px; line-height: 1.5;">' +
|
||||
'<span style="color: #059669; font-weight: 600; background: linear-gradient(135deg, #ecfdf5, #f0fdf4); padding: 8px 12px; border-radius: 6px; border-left: 3px solid #10b981;">' + t('payment.confirmationMessage', 'Payment detected, confirming...') + '</span><br>' +
|
||||
'<small style="color: #999;">' + t('payment.confirmationNote', 'Please wait patiently') + '</small>' +
|
||||
'</p>' +
|
||||
'<div style="display: flex; justify-content: center; margin-bottom: 20px;">' +
|
||||
'<div style="width: 40px; height: 40px; border: 3px solid #f3f3f3; border-top: 3px solid #667eea; border-radius: 50%; animation: spin 1s linear infinite;"></div>' +
|
||||
'</div>' +
|
||||
'<p style="color: #999; font-size: 12px;">' + t('payment.estimatedTime', 'Estimated time: 1-3 mins') + '</p>';
|
||||
|
||||
const style = document.createElement('style');
|
||||
style.textContent = '@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }';
|
||||
document.head.appendChild(style);
|
||||
|
||||
overlay.appendChild(modal);
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
// Ensure we keep checking
|
||||
if (!statusCheckTimer) {
|
||||
statusCheckTimer = setInterval(checkPaymentStatus, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
function showSuccessMessage(data) {
|
||||
const waitingOverlay = document.getElementById('waiting-overlay');
|
||||
if (waitingOverlay) waitingOverlay.remove();
|
||||
|
||||
// Prevent multiple overlays
|
||||
if (document.querySelector('.success-overlay')) return;
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'success-overlay';
|
||||
overlay.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); display: flex; align-items: center; justify-content: center; z-index: 9999;';
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.style.cssText = 'background: white; padding: 30px; border-radius: 12px; text-align: center; max-width: 400px; width: 90%; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);';
|
||||
|
||||
modal.innerHTML = '<div style="font-size: 48px; margin-bottom: 20px;">✅</div>' +
|
||||
'<h3 style="color: #48bb78; margin-bottom: 15px;">' + t('payment.paymentSuccess', 'Payment Success!') + '</h3>' +
|
||||
'<p style="color: #666; margin-bottom: 20px; line-height: 1.5;">' +
|
||||
t('payment.transactionHash', 'Transaction Hash:') + '<br>' +
|
||||
'<code style="background: #e6f0fa; color: #2563eb; padding: 4px 8px; border-radius: 4px; font-size: 12px; word-break: break-all;">' +
|
||||
(data.trade_hash || t('payment.processing', 'Processing...')) +
|
||||
'</code>' +
|
||||
'</p>' +
|
||||
'<button onclick="location.href=\'' + (data.return_url || '/') + '\'" style="background: #48bb78; color: white; border: none; padding: 12px 24px; border-radius: 6px; cursor: pointer; font-size: 14px;">' +
|
||||
t('payment.returnToMerchant', 'Return to Merchant') +
|
||||
'</button>';
|
||||
|
||||
overlay.appendChild(modal);
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
if (countdownTimer) clearInterval(countdownTimer);
|
||||
if (statusCheckTimer) clearInterval(statusCheckTimer);
|
||||
}
|
||||
|
||||
function checkPaymentStatus() {
|
||||
if (!tradeId) return;
|
||||
|
||||
fetch('/pay/check-status/' + tradeId)
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
// status: 1=pending, 2=success, 3=expired, 5=waiting_confirmation
|
||||
if (data.status === 1) {
|
||||
// Continue polling (timer handles generic polling, waiting confirms uses specific)
|
||||
// If not in waiting confirmation mode, we rely on the main timer
|
||||
} else if (data.status === 2) {
|
||||
showSuccessMessage(data);
|
||||
} else if (data.status === 3) {
|
||||
showTimeoutMessage();
|
||||
} else if (data.status === 5) {
|
||||
showWaitingConfirmation(data);
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error('Check status error:', err);
|
||||
});
|
||||
}
|
||||
|
||||
function init(config) {
|
||||
paymentConfig = config || {};
|
||||
tradeId = paymentConfig.trade_id;
|
||||
|
||||
// Initialize DOM Elements
|
||||
currencySelectEl = document.getElementById('currency-select');
|
||||
networkSelectEl = document.getElementById('network-select');
|
||||
payButton = document.querySelector('.pay-button');
|
||||
amountValue = document.querySelector('.amount-value');
|
||||
networkBadge = document.querySelector('.network-badge');
|
||||
|
||||
// Close dropdowns when clicking outside
|
||||
document.addEventListener('click', function () {
|
||||
const selects = document.querySelectorAll('.coin-select');
|
||||
selects.forEach(function (el) {
|
||||
el.classList.remove('active');
|
||||
});
|
||||
});
|
||||
|
||||
setupDropdown(currencySelectEl);
|
||||
setupDropdown(networkSelectEl);
|
||||
|
||||
if (payButton) {
|
||||
payButton.addEventListener('click', createTransaction);
|
||||
}
|
||||
|
||||
initI18n().then(function () {
|
||||
if (paymentConfig.network && Array.isArray(paymentConfig.network) && paymentConfig.network.length > 0) {
|
||||
paymentMethods = paymentConfig.network;
|
||||
initSelection();
|
||||
} else {
|
||||
showMessage(t('payment.loadPaymentNetworkFailed', 'Failed to load payment network, please check if the wallet has been added'));
|
||||
}
|
||||
|
||||
startCountdown();
|
||||
// Poll status every 5s
|
||||
statusCheckTimer = setInterval(checkPaymentStatus, 5000);
|
||||
// Initial check
|
||||
checkPaymentStatus();
|
||||
});
|
||||
}
|
||||
|
||||
// Expose necessary functions
|
||||
window.copyAmount = copyAmount;
|
||||
window.changeLanguage = changeLanguage;
|
||||
window.Payment = {
|
||||
init: init
|
||||
};
|
||||
})();
|
||||
@@ -2,9 +2,12 @@
|
||||
"payment": {
|
||||
"title": "{{token}} Payment",
|
||||
"subtitle": "Please use <strong>{{networkName}}</strong> {{network}} network for transfer",
|
||||
"subtitleCashier": "Please use <strong>{{token}} {{networkName}}</strong> network for transfer",
|
||||
"subtitle2": "Please select currency and network",
|
||||
"networkBadge": "{{network}}",
|
||||
"paymentAmount": "Payment Amount:",
|
||||
"merchantOrder": "Merchant Order:",
|
||||
"productName": "Product Name:",
|
||||
"orderAmount": "Order Amount:",
|
||||
"amountPrefix": "Approx.",
|
||||
"clickToCopy": "Click to copy amount",
|
||||
@@ -14,11 +17,15 @@
|
||||
"seconds": "sec",
|
||||
"addressLabel": "Receiving Address ({{network}} Network)",
|
||||
"copyAddress": "Copy Address",
|
||||
"selectCurrency": "Please select currency",
|
||||
"selectNetwork": "Please select network",
|
||||
"payNow": "Pay Now",
|
||||
"instructionsTitle": "📋 Transfer Instructions",
|
||||
"instruction1": "Must use <strong>{{network}} network</strong> for transfer, do not send {{warningToken}}!",
|
||||
"instruction2": "The system will automatically confirm the receipt after transfer",
|
||||
"instruction3": "Transfer amount must exactly match the displayed amount",
|
||||
"instruction4": "If you have any questions, please contact customer service",
|
||||
"cashierInstr1": "Please select your preferred payment method for transfer",
|
||||
"poweredBy": "Powered by",
|
||||
"github": "Github",
|
||||
"copied": "Copied!",
|
||||
@@ -33,7 +40,7 @@
|
||||
"estimatedTime": "Estimated confirmation time: 1-3 minutes",
|
||||
"paymentSuccess": "Payment Successful!",
|
||||
"transactionHash": "Your payment has been confirmed. Transaction hash:",
|
||||
"processing": "Processing..."
|
||||
"processing": "Processing...",
|
||||
"loadPaymentNetworkFailed": "Failed to load payment network, please check if wallet is added."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
"payment": {
|
||||
"title": "{{token}} 支付",
|
||||
"subtitle": "请使用 <strong>{{networkName}}</strong> {{network}} 网络进行转账",
|
||||
"subtitleCashier": "请使用 <strong>{{token}} {{networkName}}</strong> 网络进行转账",
|
||||
"subtitle2": "请选择支付币种和网络",
|
||||
"networkBadge": "{{network}}",
|
||||
"paymentAmount": "付款数额:",
|
||||
"merchantOrder": "商户订单:",
|
||||
"productName": "商品名称:",
|
||||
"orderAmount": "订单金额:",
|
||||
"amountPrefix": "约",
|
||||
"clickToCopy": "点击复制金额",
|
||||
@@ -14,11 +17,15 @@
|
||||
"seconds": "秒",
|
||||
"addressLabel": "收款地址 ({{network}} 网络)",
|
||||
"copyAddress": "复制地址",
|
||||
"selectCurrency": "请选择币种",
|
||||
"selectNetwork": "请选择网络",
|
||||
"payNow": "立即支付",
|
||||
"instructionsTitle": "📋 转账说明",
|
||||
"instruction1": "必须使用 <strong>{{network}} 网络</strong> 进行转账,请勿转入 {{warningToken}}!",
|
||||
"instruction2": "转账完成后系统会自动确认到账",
|
||||
"instruction3": "转账金额必须与显示金额完全一致",
|
||||
"instruction4": "如果有其它疑问,请联系客服处理",
|
||||
"cashierInstr1": "请选择您喜欢的付款方式进行转账",
|
||||
"poweredBy": "Powered by",
|
||||
"github": "Github",
|
||||
"copied": "已复制!",
|
||||
@@ -33,7 +40,7 @@
|
||||
"estimatedTime": "预计确认时间:1-3分钟",
|
||||
"paymentSuccess": "支付成功!",
|
||||
"transactionHash": "您的支付已确认,交易哈希:",
|
||||
"processing": "处理中..."
|
||||
"processing": "处理中...",
|
||||
"loadPaymentNetworkFailed": "无法加载付款网络,请检查是否已经完成钱包地址添加。"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>BEpusdt - 收银台</title>
|
||||
<link rel="shortcut icon" href="/payment/assets/img/tether.svg">
|
||||
<link rel="stylesheet" href="/payment/assets/css/core.min.css">
|
||||
<link rel="stylesheet" href="/payment/assets/css/cashier.css">
|
||||
<script src="/payment/assets/js/cashier.js"></script>
|
||||
<script src="/payment/assets/i18n/i18next.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="payment-container">
|
||||
<div class="language-switcher">
|
||||
<select id="languageSwitcher" onchange="changeLanguage(this.value)">
|
||||
<option value="zh">中文</option>
|
||||
<option value="en">English</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="crypto-icon">--</div>
|
||||
<h1 class="payment-title" data-i18n="payment.title">-- 支付</h1>
|
||||
<p class="payment-subtitle">
|
||||
<span class="status-indicator"></span>
|
||||
<span data-i18n="payment.subtitle2">请选择支付币种和网络</span>
|
||||
</p>
|
||||
|
||||
<div class="order-info">
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.paymentAmount">付款数额:</span>
|
||||
<span class="order-value amount-value" id="payAmount" onclick="copyAmount()"
|
||||
data-i18n="[title]payment.clickToCopy" title="点击复制金额">-- --</span>
|
||||
</div>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.merchantOrder">商户订单:</span>
|
||||
<span class="order-value">{{.order_id}}</span>
|
||||
</div>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.productName">商品名称:</span>
|
||||
<span class="order-value">{{.name}}</span>
|
||||
</div>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.orderAmount">订单金额:</span>
|
||||
<span class="order-value">
|
||||
<span class="fiat-amount"><span data-i18n="payment.amountPrefix">约</span> {{.money}}
|
||||
{{.fiat}}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="countdown-banner">
|
||||
<div class="countdown-content">
|
||||
<div class="countdown-info">
|
||||
<div class="countdown-title" data-i18n="payment.countdownTitle">⏰ 支付倒计时</div>
|
||||
<div class="countdown-subtitle" data-i18n="payment.countdownSubtitle">请在指定时间内完成转账,超时勿付请重新下单</div>
|
||||
</div>
|
||||
<div class="countdown-timer" id="countdown">
|
||||
<div class="time-unit">
|
||||
<span class="time-number" id="minutes">15</span>
|
||||
<span class="time-label" data-i18n="payment.minutes">分</span>
|
||||
</div>
|
||||
<span class="time-separator">:</span>
|
||||
<div class="time-unit">
|
||||
<span class="time-number" id="seconds">00</span>
|
||||
<span class="time-label" data-i18n="payment.seconds">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="selector-section">
|
||||
<div class="selector-content">
|
||||
<div class="selector-container">
|
||||
<div class="coin-select" id="currency-select">
|
||||
<span data-i18n="payment.selectCurrency">请选择币种</span><svg xmlns="http://www.w3.org/2000/svg"
|
||||
width="24" height="24" fill="none">
|
||||
<path fill="currentColor" fill-rule="evenodd"
|
||||
d="M5.232 9.36a1 1 0 0 1 1.408-.128L12 13.698l5.36-4.466a1 1 0 0 1 1.28 1.536l-6 5a1 1 0 0 1-1.28 0l-6-5a1 1 0 0 1-.128-1.408"
|
||||
clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="coin-select" id="network-select">
|
||||
<span data-i18n="payment.selectNetwork">请选择网络</span><svg xmlns="http://www.w3.org/2000/svg" width="24"
|
||||
height="24" fill="none">
|
||||
<path fill="currentColor" fill-rule="evenodd"
|
||||
d="M5.232 9.36a1 1 0 0 1 1.408-.128L12 13.698l5.36-4.466a1 1 0 0 1 1.28 1.536l-6 5a1 1 0 0 1-1.28 0l-6-5a1 1 0 0 1-.128-1.408"
|
||||
clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="pay-button" disabled>
|
||||
<p data-i18n="payment.payNow">立即支付</p>
|
||||
</button>
|
||||
</div>
|
||||
<div class="instructions">
|
||||
<h4 data-i18n="payment.instructionsTitle">📋 转账说明</h4>
|
||||
<ol>
|
||||
<li data-i18n="payment.cashierInstr1">请选择您喜欢的付款方式进行转账</li>
|
||||
<li data-i18n="payment.instruction2">转账完成后系统会自动确认到账</li>
|
||||
<li data-i18n="payment.instruction3">转账金额必须与显示金额完全一致</li>
|
||||
<li data-i18n="payment.instruction4">如果有其它疑问,请联系客服处理</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="footer-info">
|
||||
<div class="project-info">
|
||||
<span class="powered-by" data-i18n="payment.poweredBy">Powered by</span>
|
||||
<a href="https://github.com/v03413/BEpusdt" target="_blank" class="project-link">
|
||||
<strong>BEpusdt</strong>
|
||||
</a>
|
||||
<span class="open-source" data-i18n="payment.github">Github</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
Payment.init({
|
||||
expire: "{{.expire}}",
|
||||
money: "{{.money}}",
|
||||
fiat: "{{.fiat}}",
|
||||
name: "{{.name}}",
|
||||
trade_id: "{{.trade_id}}",
|
||||
order_id: "{{.order_id}}",
|
||||
return_url: "{{.return_url}}",
|
||||
network: {{.network}},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>USDT・Aptos 一款更好用的个人USDT收款网关 BEpusdt</title>
|
||||
<title>USDT・X Layer 一款更好用的个人USDT收款网关 BEpusdt</title>
|
||||
<link rel="shortcut icon" href="/payment/assets/img/tether.svg">
|
||||
<link rel="stylesheet" href="/payment/assets/css/core.min.css">
|
||||
<script src="/payment/assets/js/jquery.min.js"></script>
|
||||
@@ -14,97 +14,103 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="payment-container" data-token="USDT" data-network="X Layer" data-network-name="X Layer" data-warning-token="OKB">
|
||||
<div class="language-switcher">
|
||||
<select id="languageSwitcher" onchange="changeLanguage(this.value)">
|
||||
<option value="zh">中文</option>
|
||||
<option value="en">English</option>
|
||||
</select>
|
||||
<div class="payment-container" data-token="USDT" data-network="X Layer" data-network-name="X Layer"
|
||||
data-warning-token="OKB">
|
||||
<div class="language-switcher">
|
||||
<select id="languageSwitcher" onchange="changeLanguage(this.value)">
|
||||
<option value="zh">中文</option>
|
||||
<option value="en">English</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="crypto-icon">USDT</div>
|
||||
<h1 class="payment-title" data-i18n="payment.title">USDT 支付</h1>
|
||||
<p class="payment-subtitle">
|
||||
<span class="status-indicator"></span>
|
||||
<span data-i18n="payment.subtitle">请使用 <strong>X Layer</strong> 网络进行转账</span>
|
||||
<span class="network-badge" data-i18n="payment.networkBadge">X Layer</span>
|
||||
</p>
|
||||
|
||||
<div class="order-info">
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.paymentAmount">付款数额:</span>
|
||||
<span class="order-value amount-value" id="payAmount" onclick="copyAmount()"
|
||||
data-i18n="[title]payment.clickToCopy" title="点击复制金额">{{.amount}} USDT</span>
|
||||
</div>
|
||||
|
||||
<div class="crypto-icon">USDT</div>
|
||||
<h1 class="payment-title" data-i18n="payment.title">USDT 支付</h1>
|
||||
<p class="payment-subtitle">
|
||||
<span class="status-indicator"></span>
|
||||
<span data-i18n="payment.subtitle">请使用 <strong>Aptos</strong> 网络进行转账</span>
|
||||
<span class="network-badge" data-i18n="payment.networkBadge">Aptos</span>
|
||||
</p>
|
||||
|
||||
<div class="order-info">
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.paymentAmount">付款数额:</span>
|
||||
<span class="order-value amount-value" id="payAmount" onclick="copyAmount()" data-i18n="[title]payment.clickToCopy" title="点击复制金额">{{.amount}} USDT</span>
|
||||
</div>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.merchantOrder">商户订单:</span>
|
||||
<span class="order-value">{{.order_id}}</span>
|
||||
</div>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.orderAmount">订单金额:</span>
|
||||
<span class="order-value">
|
||||
<span class="fiat-amount"><span data-i18n="payment.amountPrefix">约</span> {{.money}} {{.fiat}}</span>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.merchantOrder">商户订单:</span>
|
||||
<span class="order-value">{{.order_id}}</span>
|
||||
</div>
|
||||
<div class="order-item">
|
||||
<span class="order-label" data-i18n="payment.orderAmount">订单金额:</span>
|
||||
<span class="order-value">
|
||||
<span class="fiat-amount"><span
|
||||
data-i18n="payment.amountPrefix">约</span> {{.money}} {{.fiat}}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="countdown-banner">
|
||||
<div class="countdown-content">
|
||||
<div class="countdown-info">
|
||||
<div class="countdown-title" data-i18n="payment.countdownTitle">⏰ 支付倒计时</div>
|
||||
<div class="countdown-subtitle" data-i18n="payment.countdownSubtitle">请在指定时间内完成转账,超时勿付请重新下单</div>
|
||||
</div>
|
||||
<div class="countdown-timer" id="countdown">
|
||||
<div class="time-unit">
|
||||
<span class="time-number" id="minutes">15</span>
|
||||
<span class="time-label" data-i18n="payment.minutes">分</span>
|
||||
</div>
|
||||
<span class="time-separator">:</span>
|
||||
<div class="time-unit">
|
||||
<span class="time-number" id="seconds">00</span>
|
||||
<span class="time-label" data-i18n="payment.seconds">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="countdown-banner">
|
||||
<div class="countdown-content">
|
||||
<div class="countdown-info">
|
||||
<div class="countdown-title" data-i18n="payment.countdownTitle">⏰ 支付倒计时</div>
|
||||
<div class="countdown-subtitle" data-i18n="payment.countdownSubtitle">
|
||||
请在指定时间内完成转账,超时勿付请重新下单
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="qr-section">
|
||||
<div class="qr-code" id="qrcode"></div>
|
||||
<div class="address-section">
|
||||
<div class="address-label" data-i18n="payment.addressLabel">收款地址 (X Layer 网络)</div>
|
||||
<div class="address-text" id="walletAddress">{{.address}}</div>
|
||||
<button class="copy-btn" onclick="copyAddress()" data-i18n="payment.copyAddress">复制地址</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="instructions">
|
||||
<h4 data-i18n="payment.instructionsTitle">📋 转账说明</h4>
|
||||
<ol>
|
||||
<li data-i18n="[html]payment.instruction1">必须使用 <strong>X Layer 网络</strong> 进行转账,请勿转入 OKB!</li>
|
||||
<li data-i18n="payment.instruction2">转账完成后系统会自动确认到账</li>
|
||||
<li data-i18n="payment.instruction3">转账金额必须与显示金额完全一致</li>
|
||||
<li data-i18n="payment.instruction4">如果有其它疑问,请联系客服处理</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="footer-info">
|
||||
<div class="project-info">
|
||||
<span class="powered-by" data-i18n="payment.poweredBy">Powered by</span>
|
||||
<a href="https://github.com/v03413/BEpusdt" target="_blank" class="project-link">
|
||||
<strong>BEpusdt</strong>
|
||||
</a>
|
||||
<span class="open-source" data-i18n="payment.github">Github</span>
|
||||
<div class="countdown-timer" id="countdown">
|
||||
<div class="time-unit">
|
||||
<span class="time-number" id="minutes">15</span>
|
||||
<span class="time-label" data-i18n="payment.minutes">分</span>
|
||||
</div>
|
||||
<span class="time-separator">:</span>
|
||||
<div class="time-unit">
|
||||
<span class="time-number" id="seconds">00</span>
|
||||
<span class="time-label" data-i18n="payment.seconds">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="qr-section">
|
||||
<div class="qr-code" id="qrcode"></div>
|
||||
<div class="address-section">
|
||||
<div class="address-label" data-i18n="payment.addressLabel">收款地址 (X Layer 网络)</div>
|
||||
<div class="address-text" id="walletAddress">{{.address}}</div>
|
||||
<button class="copy-btn" onclick="copyAddress()" data-i18n="payment.copyAddress">复制地址</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="instructions">
|
||||
<h4 data-i18n="payment.instructionsTitle">📋 转账说明</h4>
|
||||
<ol>
|
||||
<li data-i18n="[html]payment.instruction1">必须使用 <strong>X Layer 网络</strong> 进行转账,请勿转入 OKB!
|
||||
</li>
|
||||
<li data-i18n="payment.instruction2">转账完成后系统会自动确认到账</li>
|
||||
<li data-i18n="payment.instruction3">转账金额必须与显示金额完全一致</li>
|
||||
<li data-i18n="payment.instruction4">如果有其它疑问,请联系客服处理</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="footer-info">
|
||||
<div class="project-info">
|
||||
<span class="powered-by" data-i18n="payment.poweredBy">Powered by</span>
|
||||
<a href="https://github.com/v03413/BEpusdt" target="_blank" class="project-link">
|
||||
<strong>BEpusdt</strong>
|
||||
</a>
|
||||
<span class="open-source" data-i18n="payment.github">Github</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
Payment.init({
|
||||
expire: "{{.expire}}",
|
||||
address: "{{.address}}",
|
||||
amount: "{{.amount}}",
|
||||
trade_id: "{{.trade_id}}",
|
||||
return_url: "{{.return_url}}"
|
||||
});
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
Payment.init({
|
||||
expire: "{{.expire}}",
|
||||
address: "{{.address}}",
|
||||
amount: "{{.amount}}",
|
||||
trade_id: "{{.trade_id}}",
|
||||
return_url: "{{.return_url}}"
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import axios from "@/api";
|
||||
|
||||
export const createOrderApi = (data: any) => {
|
||||
return axios({
|
||||
url: "/api/order/create",
|
||||
method: "post",
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const listAPI = (data: any) => {
|
||||
return axios({
|
||||
url: "/api/order/list",
|
||||
|
||||
@@ -36,6 +36,7 @@ export default {
|
||||
["rate-syntax"]: "汇率配置",
|
||||
["system-base"]: "基本设置",
|
||||
["system-rpc"]: "区块节点",
|
||||
["create-order"]: "创建订单",
|
||||
["github-api-doc"]: "对接文档",
|
||||
["file"]: "文件管理",
|
||||
["document-library"]: "文件库",
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
<a-watermark :content="watermark" v-bind="watermarkConfig">
|
||||
<a-layout-content class="layout-main-content">
|
||||
<Tabs v-if="isTabs" />
|
||||
<router-view v-slot="{ Component, route }">
|
||||
<s-main-transition>
|
||||
<keep-alive :include="cacheRoutes">
|
||||
<component :is="createComponentWrapper(Component, route)" :key="route.fullPath" v-if="refreshPage" />
|
||||
</keep-alive>
|
||||
</s-main-transition>
|
||||
<router-view v-slot="{ Component }">
|
||||
<keep-alive :include="cacheRoutes">
|
||||
<component :is="Component" v-if="refreshPage" />
|
||||
</keep-alive>
|
||||
</router-view>
|
||||
</a-layout-content>
|
||||
</a-watermark>
|
||||
@@ -23,19 +21,6 @@ let { refreshPage, isTabs, watermark, watermarkStyle, watermarkRotate, watermark
|
||||
const routerStore = useRouteConfigStore();
|
||||
const { cacheRoutes } = storeToRefs(routerStore);
|
||||
|
||||
// 组件包装器
|
||||
const wrapperMap = new Map();
|
||||
const createComponentWrapper = (component: any, route: any) => {
|
||||
if (!component) return;
|
||||
const wrapperName = route.fullPath;
|
||||
let wrapper = wrapperMap.get(wrapperName);
|
||||
if (!wrapper) {
|
||||
wrapper = { name: wrapperName, render: () => h(component) };
|
||||
wrapperMap.set(wrapperName, wrapper);
|
||||
}
|
||||
return h(wrapper);
|
||||
};
|
||||
|
||||
// 水印配置
|
||||
const watermarkConfig = computed(() => {
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
<template>
|
||||
<div class="snow-page">
|
||||
<a-spin :loading="loading" style="display: block">
|
||||
<div class="snow-inner container">
|
||||
<a-row justify="center">
|
||||
<a-col :xs="22" :sm="18" :md="16" :lg="16" :xl="12" :xxl="12">
|
||||
<a-steps :current="currentStep" line-less>
|
||||
<a-step description="创建订单">基本信息</a-step>
|
||||
<a-step description="创建成功">完成创建</a-step>
|
||||
</a-steps>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row justify="center" class="margin-top">
|
||||
<a-col :xs="18" :sm="12" :md="12" :lg="12" :xl="8" :xxl="8">
|
||||
<a-form ref="formRef" auto-label-width :layout="formLayout" :model="form" :rules="rules" @submit="handleSubmit">
|
||||
<div v-if="currentStep == 1">
|
||||
<a-form-item
|
||||
field="name"
|
||||
label="收款项目"
|
||||
:validate-trigger="['change', 'input']"
|
||||
>
|
||||
<a-input :style="{ width: '100%' }" v-model="form.name" placeholder="请输入收款项目" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
field="order_id"
|
||||
label="订单号"
|
||||
:validate-trigger="['change', 'input']"
|
||||
>
|
||||
<a-input :style="{ width: '100%' }" v-model="form.order_id" placeholder="请输入订单号" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
field="amount"
|
||||
label="订单金额"
|
||||
:validate-trigger="['change', 'input']"
|
||||
>
|
||||
<a-input-number :style="{ width: '100%' }" v-model="form.amount" placeholder="请输入订单金额" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="trade_fiat" label="法币币种" :rules="[{ required: true, message: '法币币种不能为空' }]">
|
||||
<a-select v-model="form.trade_fiat" placeholder="请选择" allow-clear>
|
||||
<a-option v-for="(_, key) in userInfoStore.trade_fiat" :key="key" :value="key">{{ key }}</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="trade_crypto" label="限定加密货币(留空不限制)">
|
||||
<a-select v-model="form.trade_crypto" placeholder="请选择" multiple>
|
||||
<a-option v-for="(_, key) in userInfoStore.trade_crypto" :key="key" :value="key">{{ key }}</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="timeout" label="订单有效期(小时)">
|
||||
<a-slider v-model="form.timeout" :max="3" />
|
||||
</a-form-item>
|
||||
</div>
|
||||
|
||||
<div v-if="currentStep == 2">
|
||||
<a-result :status="resultStatus" :title="resultTitle">
|
||||
<template #subtitle> {{ resultSubtitle }} </template>
|
||||
<template #extra>
|
||||
<a-space direction="vertical" size="large">
|
||||
<div v-if="resultStatus === 'success'">订单链接:<a :href="paymentUrl" class="link" target="_blank">{{ paymentUrl }}</a></div>
|
||||
<a-space>
|
||||
<a-button type="primary" v-if="resultStatus === 'success'" @click="copyLink">复制订单链接</a-button>
|
||||
<a-button @click="resetForm">再次创建</a-button>
|
||||
</a-space>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-result>
|
||||
</div>
|
||||
<a-form-item v-if="currentStep != 2">
|
||||
<a-space>
|
||||
<a-button @click="onLastStep" v-if="currentStep != 1">上一步</a-button>
|
||||
<a-button html-type="submit" type="primary">下一步</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row v-if="currentStep == 2">
|
||||
<a-col :span="16" :offset="4">
|
||||
<a-typography style="padding: 24px; background: var(--color-fill-2)">
|
||||
<a-typography-paragraph>提示</a-typography-paragraph>
|
||||
<ul>
|
||||
<li>您可以将该链接发给客户让其支付</li>
|
||||
<li>该订单将在您设置的有效期内有效</li>
|
||||
</ul>
|
||||
</a-typography>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</a-spin>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from "vue";
|
||||
import { useUserInfoStore } from "@/store/modules/user-info";
|
||||
import { createOrderApi } from "@/api/modules/order";
|
||||
import { Message } from "@arco-design/web-vue";
|
||||
|
||||
import dayjs from "dayjs";
|
||||
|
||||
const copyLink = async () => {
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(paymentUrl.value);
|
||||
Message.success("复制成功");
|
||||
} else {
|
||||
// Fallback for non-secure contexts or older browsers
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = paymentUrl.value;
|
||||
textArea.style.position = "fixed";
|
||||
textArea.style.left = "-9999px";
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
Message.success("复制成功");
|
||||
} catch (err) {
|
||||
console.error('Fallback: Oops, unable to copy', err);
|
||||
Message.error("复制失败");
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
Message.error("复制失败");
|
||||
}
|
||||
};
|
||||
|
||||
const loading = ref(false);
|
||||
const currentStep = ref(1);
|
||||
const userInfoStore = useUserInfoStore();
|
||||
|
||||
const formRef = ref();
|
||||
const formLayout = ref("vertical");
|
||||
const rules = {
|
||||
name: [
|
||||
{ required: true, message: '收款项目不能为空' },
|
||||
{ minLength: 3, message: '必须大于 3 个字符' }
|
||||
],
|
||||
order_id: [{ required: true, message: '订单号不能为空' }],
|
||||
amount: [
|
||||
{ required: true, message: '订单金额不能为空' },
|
||||
{ type: 'number', min: 1, max: 99999999, message: '订单金额必须在 1 到 99999999 之间' }
|
||||
],
|
||||
trade_fiat: [{ required: true, message: '法币币种不能为空' }],
|
||||
timeout: [{ type: 'number', min: 1, message: '最小为1小时' }]
|
||||
};
|
||||
|
||||
const form = reactive({
|
||||
name: "",
|
||||
order_id: "",
|
||||
amount: 0,
|
||||
trade_fiat: undefined,
|
||||
trade_crypto: [],
|
||||
timeout: 1
|
||||
});
|
||||
|
||||
const generateOrderId = () => {
|
||||
return "PAY" + dayjs().format("YYYYMMDDHHmmss");
|
||||
};
|
||||
|
||||
const initForm = async () => {
|
||||
form.name = "";
|
||||
form.order_id = generateOrderId();
|
||||
|
||||
form.amount = 0;
|
||||
form.trade_fiat = undefined;
|
||||
form.trade_crypto = [];
|
||||
form.timeout = 1;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initForm();
|
||||
});
|
||||
|
||||
const resultStatus = ref("success");
|
||||
const resultTitle = ref("创建成功");
|
||||
const resultSubtitle = ref("订单创建成功");
|
||||
const paymentUrl = ref("");
|
||||
|
||||
const handleSubmit = async ({ errors, values }: ArcoDesign.ArcoSubmit) => {
|
||||
if (errors) return;
|
||||
if (currentStep.value == 2) return;
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const payload = {
|
||||
...values,
|
||||
fiat: form.trade_fiat,
|
||||
currencies: Array.isArray(form.trade_crypto) ? form.trade_crypto.join(",") : "",
|
||||
timeout: form.timeout * 3600
|
||||
};
|
||||
|
||||
const res = await createOrderApi(payload);
|
||||
if (res.code === 200) {
|
||||
resultStatus.value = "success";
|
||||
resultTitle.value = "创建成功";
|
||||
resultSubtitle.value = "订单创建成功";
|
||||
paymentUrl.value = res.data.payment_url;
|
||||
currentStep.value += 1;
|
||||
} else {
|
||||
resultStatus.value = "error";
|
||||
resultTitle.value = "订单创建失败";
|
||||
resultSubtitle.value = res.data.message || "未知错误";
|
||||
paymentUrl.value = "";
|
||||
currentStep.value += 1;
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
resultStatus.value = "error";
|
||||
resultTitle.value = "订单创建失败";
|
||||
resultSubtitle.value = err.message || "请求失败";
|
||||
paymentUrl.value = "";
|
||||
currentStep.value += 1;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onLastStep = () => {
|
||||
if (currentStep.value == 1) return;
|
||||
currentStep.value -= 1;
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
currentStep.value = 1;
|
||||
initForm();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.container {
|
||||
padding: 60px 0;
|
||||
}
|
||||
.margin-top {
|
||||
margin-top: 60px;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #409eff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
color: #66b1ff;
|
||||
}
|
||||
</style>
|
||||
@@ -10,13 +10,22 @@
|
||||
<!-- 功能操作按钮 -->
|
||||
<template #footer>
|
||||
<a-space>
|
||||
<a-button
|
||||
v-if="detailData.status === 2 && detailData.notify_state === 0"
|
||||
type="primary"
|
||||
status="warning"
|
||||
@click="handleManualNotify"
|
||||
>
|
||||
<template #icon><icon-notification /></template>
|
||||
回调
|
||||
</a-button>
|
||||
<a-popconfirm content="确定删除该订单吗?删除后将无法恢复!" type="error" @ok="handleDelete">
|
||||
<a-button type="primary" status="danger">
|
||||
<template #icon><icon-delete /></template>
|
||||
删除订单
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button @click="onClose">关闭</a-button>
|
||||
<a-button @click="onClose">关闭窗口</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
@@ -250,7 +259,8 @@
|
||||
<script setup lang="ts">
|
||||
import { getCryptoColor } from "@/views/rate/common";
|
||||
import { delOrderApi } from "@/api/modules/order/index";
|
||||
import { Notification } from "@arco-design/web-vue";
|
||||
import { Notification, Modal } from "@arco-design/web-vue";
|
||||
import { manualNotifyAPI } from "@/api/modules/order/index";
|
||||
|
||||
const props = defineProps({
|
||||
visible: Boolean,
|
||||
@@ -298,6 +308,27 @@ const handleDelete = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleManualNotify = () => {
|
||||
Modal.confirm({
|
||||
title: "确认手动回调",
|
||||
content: `确定要手动触发订单 ${props.detailData.order_id} 的回调吗?系统将立即向商户发送回调通知。`,
|
||||
okText: "确认回调",
|
||||
cancelText: "取消",
|
||||
onOk: () => {
|
||||
return manualNotifyAPI({ id: props.detailData.id })
|
||||
.then(result => {
|
||||
Notification.success(result.msg || "回调成功");
|
||||
emits("refresh");
|
||||
onClose();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("回调失败:", error);
|
||||
emits("refresh");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const statusMap: Record<number, { color: string; text: string }> = {
|
||||
1: { color: "blue", text: "等待支付" },
|
||||
2: { color: "green", text: "交易成功" },
|
||||
|
||||
@@ -1,201 +1,184 @@
|
||||
<template>
|
||||
<div class="order">
|
||||
<div class="snow-page">
|
||||
<div class="snow-inner">
|
||||
<a-form ref="formRef" :model="formData.form" auto-label-width>
|
||||
<a-row :gutter="16">
|
||||
<div class="snow-page">
|
||||
<div class="snow-inner">
|
||||
<a-form ref="formRef" :model="formData.form" auto-label-width>
|
||||
<a-row :gutter="16">
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="order_id" label="商户订单">
|
||||
<a-input v-model="formData.form.order_id" placeholder="请输入商户订单" allow-clear />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="trade_type" label="交易类型">
|
||||
<a-select v-model="formData.form.trade_type" placeholder="请选择交易类型" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="status" label="订单状态">
|
||||
<a-select v-model="formData.form.status" placeholder="请选择订单状态" allow-clear>
|
||||
<a-option v-for="item in statusOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" class="btn-col">
|
||||
<a-form-item label=" " style="margin-bottom: 0">
|
||||
<a-space>
|
||||
<a-button type="primary" @click="getOrderList">
|
||||
<template #icon><icon-search /></template>
|
||||
查询
|
||||
</a-button>
|
||||
<a-button @click="onReset">
|
||||
<template #icon><icon-refresh /></template>
|
||||
重置
|
||||
</a-button>
|
||||
<a-popconfirm :content="batchDelConfirm" type="warning" @ok="onBatchDelete">
|
||||
<a-button v-show="selectedKeys.length > 0" type="primary" status="danger">
|
||||
<template #icon><icon-delete /></template>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button type="text" @click="formData.search = !formData.search">
|
||||
{{ formData.search ? "收起" : "展开" }}
|
||||
<icon-down :class="{ 'rotate-icon': formData.search }" />
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
|
||||
<template v-if="formData.search">
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="order_id" label="商户订单">
|
||||
<a-input v-model="formData.form.order_id" placeholder="请输入商户订单" allow-clear />
|
||||
<a-form-item field="trade_id" label="交易ID">
|
||||
<a-input v-model="formData.form.trade_id" placeholder="请输入交易ID" allow-clear />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="trade_type" label="交易类型">
|
||||
<a-select v-model="formData.form.trade_type" placeholder="请选择交易类型" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
<a-form-item field="address" label="钱包地址">
|
||||
<a-input v-model="formData.form.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="status" label="订单状态">
|
||||
<a-select v-model="formData.form.status" placeholder="请选择订单状态" allow-clear>
|
||||
<a-option v-for="item in statusOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
<a-form-item field="createTime" label="创建时间">
|
||||
<a-range-picker v-model="formData.form.createTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6" class="btn-col">
|
||||
<a-form-item label=" " style="margin-bottom: 0">
|
||||
<a-space>
|
||||
<a-button type="primary" @click="getOrderList">
|
||||
<template #icon><icon-search /></template>
|
||||
查询
|
||||
</a-button>
|
||||
<a-button @click="onReset">
|
||||
<template #icon><icon-refresh /></template>
|
||||
重置
|
||||
</a-button>
|
||||
<a-popconfirm :content="batchDelConfirm" type="warning" @ok="onBatchDelete">
|
||||
<a-button v-show="selectedKeys.length > 0" type="primary" status="danger">
|
||||
<template #icon><icon-delete /></template>
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button type="text" @click="formData.search = !formData.search">
|
||||
{{ formData.search ? "收起" : "展开" }}
|
||||
<icon-down :class="{ 'rotate-icon': formData.search }" />
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
|
||||
<template v-if="formData.search">
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="trade_id" label="交易ID">
|
||||
<a-input v-model="formData.form.trade_id" placeholder="请输入交易ID" allow-clear />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="address" label="钱包地址">
|
||||
<a-input v-model="formData.form.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="12" :md="12" :lg="8" :xl="6">
|
||||
<a-form-item field="createTime" label="创建时间">
|
||||
<a-range-picker v-model="formData.form.createTime" show-time format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</template>
|
||||
</a-row>
|
||||
</a-form>
|
||||
|
||||
<a-table
|
||||
row-key="id"
|
||||
size="small"
|
||||
:bordered="{ cell: true }"
|
||||
:scroll="{ x: 'max-content', y: '60vh' }"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
v-model:selectedKeys="selectedKeys"
|
||||
:row-selection="orderSelection"
|
||||
:pagination="pagination"
|
||||
@page-change="pageChange"
|
||||
@page-size-change="pageSizeChange"
|
||||
>
|
||||
<template #wallet="{ record }">
|
||||
<a-tooltip :content="record.address" position="top">
|
||||
<span class="wallet-name">
|
||||
{{ record.wallet?.name || `⁉ ${record.address?.slice(-8) || "-"}` }}
|
||||
</span>
|
||||
</a-tooltip>
|
||||
</template>
|
||||
</a-row>
|
||||
</a-form>
|
||||
|
||||
<template #amount="{ record }">
|
||||
<span>
|
||||
{{ record.amount }}
|
||||
<a-tag size="mini" :color="getCryptoColor(record.crypto)" bordered style="margin-left: 4px">{{
|
||||
record.crypto
|
||||
}}</a-tag>
|
||||
<a-table
|
||||
row-key="id"
|
||||
size="small"
|
||||
:bordered="{ cell: true }"
|
||||
:scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
v-model:selectedKeys="selectedKeys"
|
||||
:row-selection="orderSelection"
|
||||
:pagination="pagination"
|
||||
@page-change="pageChange"
|
||||
@page-size-change="pageSizeChange"
|
||||
>
|
||||
<template #wallet="{ record }">
|
||||
<a-tooltip :content="record.address" position="top">
|
||||
<span class="wallet-name">
|
||||
{{ record.wallet?.name || record.channel?.name || (record.address ? `${record.address.slice(-8)}` : "--") }}
|
||||
</span>
|
||||
</template>
|
||||
</a-tooltip>
|
||||
</template>
|
||||
|
||||
<template #money="{ record }">
|
||||
<span>
|
||||
{{ record.money }}
|
||||
<a-tag size="mini" color="arcoblue" style="margin-left: 4px">{{ record.fiat }}</a-tag>
|
||||
</span>
|
||||
</template>
|
||||
<template #amount="{ record }">
|
||||
<span>
|
||||
{{ record.amount }}
|
||||
<a-tag size="mini" :color="getCryptoColor(record.crypto)" bordered style="margin-left: 4px">{{
|
||||
record.crypto
|
||||
}}</a-tag>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #status="{ record }">
|
||||
<a-tag size="small" :color="getStatusColor(record.status)">
|
||||
{{ getStatusText(record.status) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template #money="{ record }">
|
||||
<span>
|
||||
{{ record.money }}
|
||||
<a-tag size="mini" color="arcoblue" style="margin-left: 4px">{{ record.fiat }}</a-tag>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #notify_state="{ record }">
|
||||
<a-tag size="small" :color="record.status === 2 ? (record.notify_state === 1 ? 'blue' : 'red') : 'gray'">
|
||||
{{ record.status === 2 ? (record.notify_state === 1 ? "成功" : "失败") : "-" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template #status="{ record }">
|
||||
<a-tag size="small" :color="getStatusColor(record.status)">
|
||||
{{ getStatusText(record.status) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<!-- 不常用的操作优先放置在详情页,尽量保持第一视角的干净整洁 -->
|
||||
<template #optional="{ record }">
|
||||
<a-space>
|
||||
<a-button size="mini" type="primary" @click="showDetail(record)">详情</a-button>
|
||||
<a-button
|
||||
size="mini"
|
||||
type="primary"
|
||||
status="warning"
|
||||
:disabled="record.status === 2"
|
||||
@click="showPaidModal(record)"
|
||||
>
|
||||
补单
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="record.status === 2 && record.notify_state === 0"
|
||||
size="mini"
|
||||
type="primary"
|
||||
status="danger"
|
||||
@click="handleManualNotify(record)"
|
||||
>
|
||||
手动回调
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
<template #notify_state="{ record }">
|
||||
<a-tag size="small" :color="record.status === 2 ? (record.notify_state === 1 ? 'blue' : 'red') : 'gray'">
|
||||
{{ record.status === 2 ? (record.notify_state === 1 ? "成功" : "失败") : "-" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<!-- 不常用的操作优先放置在详情页,尽量保持第一视角的干净整洁 -->
|
||||
<template #optional="{ record }">
|
||||
<a-space>
|
||||
<a-button size="mini" type="primary" @click="showDetail(record)">详情</a-button>
|
||||
<a-button size="mini" type="primary" status="warning" :disabled="record.status === 2" @click="showPaidModal(record)">
|
||||
补单
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
|
||||
<DetailModal :visible="detailVisible" :detailData="detailData" @close="closeDetail" />
|
||||
|
||||
<!-- 补单弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="paidModalVisible"
|
||||
title="确认补单操作"
|
||||
@ok="confirmPaid"
|
||||
@cancel="closePaidModal"
|
||||
ok-text="确认补单"
|
||||
cancel-text="取消"
|
||||
width="500px"
|
||||
:mask-closable="false"
|
||||
>
|
||||
<div class="paid-modal-content">
|
||||
<a-alert type="warning" style="margin-bottom: 20px">
|
||||
<template #icon>
|
||||
<icon-exclamation-circle-fill />
|
||||
</template>
|
||||
<div style="font-weight: 500">注意</div>
|
||||
<div style="font-size: 13px; margin-top: 4px; color: #666">
|
||||
补单操作将强制标记订单为已支付,即使用户实际未付款、谨慎操作!
|
||||
</div>
|
||||
</a-alert>
|
||||
|
||||
<a-form :model="paidForm" layout="vertical">
|
||||
<a-form-item field="ref_hash" label="交易哈希" :rules="[{ maxLength: 200, message: '哈希值不能超过200个字符' }]">
|
||||
<a-input v-model="paidForm.ref_hash" placeholder="请输入区块链交易哈希值(可选)" allow-clear>
|
||||
<template #prefix>
|
||||
<icon-link />
|
||||
</template>
|
||||
</a-input>
|
||||
<template #extra>
|
||||
<div style="font-size: 12px; color: #86909c; margin-top: 4px">如有实际交易,建议填写对应的区块链交易哈希值</div>
|
||||
</template>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
</a-modal>
|
||||
</div>
|
||||
|
||||
<DetailModal :visible="detailVisible" :detailData="detailData" @close="closeDetail" />
|
||||
|
||||
<!-- 补单弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="paidModalVisible"
|
||||
title="确认补单操作"
|
||||
@ok="confirmPaid"
|
||||
@cancel="closePaidModal"
|
||||
ok-text="确认补单"
|
||||
cancel-text="取消"
|
||||
width="500px"
|
||||
:mask-closable="false"
|
||||
>
|
||||
<div class="paid-modal-content">
|
||||
<a-alert type="warning" style="margin-bottom: 20px">
|
||||
<template #icon>
|
||||
<icon-exclamation-circle-fill />
|
||||
</template>
|
||||
<div style="font-weight: 500">注意</div>
|
||||
<div style="font-size: 13px; margin-top: 4px; color: #666">
|
||||
补单操作将强制标记订单为已支付,即使用户实际未付款、谨慎操作!
|
||||
</div>
|
||||
</a-alert>
|
||||
|
||||
<a-form :model="paidForm" layout="vertical">
|
||||
<a-form-item field="ref_hash" label="交易哈希" :rules="[{ maxLength: 200, message: '哈希值不能超过200个字符' }]">
|
||||
<a-input v-model="paidForm.ref_hash" placeholder="请输入区块链交易哈希值(可选)" allow-clear>
|
||||
<template #prefix>
|
||||
<icon-link />
|
||||
</template>
|
||||
</a-input>
|
||||
<template #extra>
|
||||
<div style="font-size: 12px; color: #86909c; margin-top: 4px">如有实际交易,建议填写对应的区块链交易哈希值</div>
|
||||
</template>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { listAPI, paidAPI, manualNotifyAPI, delOrderApi } from "@/api/modules/order/index";
|
||||
import { listAPI, paidAPI, delOrderApi } from "@/api/modules/order/index";
|
||||
import { List, FormData, Pagination } from "./config";
|
||||
import { Notification, Modal } from "@arco-design/web-vue";
|
||||
import { Notification } from "@arco-design/web-vue";
|
||||
import { useUserInfoStore } from "@/store/modules/user-info";
|
||||
import DetailModal from "./detail.vue";
|
||||
import { useOrderDetail } from "./detail";
|
||||
@@ -244,7 +227,7 @@ const pagination = ref<Pagination>({
|
||||
|
||||
const columns = [
|
||||
{ title: "ID", align: "center", dataIndex: "id", width: 80 },
|
||||
{ title: "商户订单", align: "center", dataIndex: "order_id", width: 200, ellipsis: true, tooltip: true },
|
||||
{ title: "商户订单", align: "center", dataIndex: "order_id", width: 220, ellipsis: true, tooltip: true },
|
||||
{ title: "交易类型", align: "center", dataIndex: "trade_type", width: 120 },
|
||||
{ title: "交易数额", align: "center", dataIndex: "amount", slotName: "amount", width: 150 },
|
||||
{ title: "交易金额", align: "center", dataIndex: "money", slotName: "money", width: 150 },
|
||||
@@ -367,51 +350,11 @@ const onBatchDelete = async () => {
|
||||
Notification.error(error);
|
||||
}
|
||||
};
|
||||
const handleManualNotify = (record: List) => {
|
||||
Modal.confirm({
|
||||
title: "确认手动回调",
|
||||
content: `确定要手动触发订单 ${record.order_id} 的回调吗?系统将立即向商户发送回调通知。`,
|
||||
okText: "确认回调",
|
||||
cancelText: "取消",
|
||||
onOk: async () => {
|
||||
try {
|
||||
await manualNotifyAPI({ id: record.id });
|
||||
Notification.success("回调已触发,请稍后查看回调状态");
|
||||
getOrderList();
|
||||
} catch (error) {
|
||||
Notification.error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
getOrderList();
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.order {
|
||||
height: 100%;
|
||||
|
||||
.snow-page {
|
||||
height: 100%;
|
||||
|
||||
.snow-inner {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.arco-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.arco-table-container {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-col {
|
||||
.arco-form-item {
|
||||
margin-bottom: 0;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<a-space size="medium">
|
||||
<a-button type="primary" @click="showSyncModal">
|
||||
<template #icon>
|
||||
<icon-clock-circle />
|
||||
<icon-settings />
|
||||
</template>
|
||||
同步频率
|
||||
同步配置
|
||||
</a-button>
|
||||
<a-button type="primary" @click="showAtomModal" :status="'danger'">
|
||||
<template #icon>
|
||||
@@ -120,11 +120,11 @@
|
||||
<!-- 同步频率设置模态框 -->
|
||||
<a-modal
|
||||
v-model:visible="syncModalVisible"
|
||||
title="设置同步频率"
|
||||
title="汇率同步配置"
|
||||
@ok="handleSyncSubmit"
|
||||
@cancel="handleSyncCancel"
|
||||
:ok-loading="syncLoading"
|
||||
width="400px"
|
||||
width="480px"
|
||||
class="sync-modal"
|
||||
>
|
||||
<a-form ref="syncFormRef" :model="syncForm" layout="vertical">
|
||||
@@ -139,10 +139,26 @@
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="API 接口">
|
||||
<a-select v-model="syncForm.apiUrl" placeholder="请选择 API 接口" style="width: 100%">
|
||||
<a-option v-for="option in apiUrlOptions" :key="option.value" :value="option.value" :label="option.label">
|
||||
{{ option.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="API Key">
|
||||
<a-input v-model="syncForm.apiKey" placeholder="请输入 API Key(可选)" allow-clear style="width: 100%" />
|
||||
</a-form-item>
|
||||
|
||||
<div class="sync-tip">
|
||||
<a-typography-text type="secondary">
|
||||
<icon-info-circle style="margin-right: 4px" />
|
||||
推荐60分钟,范围:10-1440分钟
|
||||
同步频率:10-1440分钟,推荐60分钟<br />
|
||||
官方接口:免费但有速率限制,配置 <a href="https://www.coingecko.com/" target="_blank">API Key</a> 可解除限制<br />
|
||||
开源接口:作者提供的免费缓存接口(落后官方接口3分钟),无速率限制<br />
|
||||
<b style="color: red">官方接口特指 CoinGecko,是全球最大的独立加密货币数据聚合平台之一</b>
|
||||
<hr />
|
||||
</a-typography-text>
|
||||
</div>
|
||||
</a-form>
|
||||
@@ -235,7 +251,7 @@ import { ref, reactive } from "vue";
|
||||
import { Message } from "@arco-design/web-vue";
|
||||
import { IconInfoCircle } from "@arco-design/web-vue/es/icon";
|
||||
import { getSyntaxListAPI, setSyntaxAPI } from "@/api/modules/rate/index";
|
||||
import { setConfAPI, getConfAPI, getsConfAPI, setsConfAPI } from "@/api/modules/conf/index";
|
||||
import { getsConfAPI, setsConfAPI } from "@/api/modules/conf/index";
|
||||
import { List, EditForm } from "./syntax";
|
||||
import { getFiatFlag, getCryptoColor } from "@/views/rate/common";
|
||||
|
||||
@@ -470,27 +486,53 @@ const syncLoading = ref<boolean>(false);
|
||||
const syncFormRef = ref();
|
||||
|
||||
const syncForm = reactive({
|
||||
minutes: 60 // 默认60分钟
|
||||
minutes: 60,
|
||||
apiUrl: "https://api.coingecko.com", // 默认官方接口
|
||||
apiKey: ""
|
||||
});
|
||||
|
||||
// API 接口选项
|
||||
const apiUrlOptions = [
|
||||
{
|
||||
label: "官方接口 免费额度存在速率限制",
|
||||
value: "https://api.coingecko.com"
|
||||
},
|
||||
{
|
||||
label: "开源免费 作者自建 没有速率限制",
|
||||
value: "https://api-coingecko-com.bepusdt.online"
|
||||
}
|
||||
];
|
||||
|
||||
// 显示同步频率模态框
|
||||
const showSyncModal = async () => {
|
||||
try {
|
||||
const res = await getConfAPI({
|
||||
key: "rate_sync_interval"
|
||||
const res = await getsConfAPI({
|
||||
keys: ["rate_sync_interval", "rate_sync_coingecko_api_url", "rate_sync_coingecko_api_key"]
|
||||
});
|
||||
|
||||
if (res.data && res.data.value) {
|
||||
const seconds = parseInt(res.data.value);
|
||||
const minutes = Math.round(seconds / 60);
|
||||
syncForm.minutes = minutes;
|
||||
if (res.data) {
|
||||
// 设置同步频率
|
||||
if (res.data.rate_sync_interval) {
|
||||
const seconds = parseInt(res.data.rate_sync_interval);
|
||||
const minutes = Math.round(seconds / 60);
|
||||
syncForm.minutes = minutes;
|
||||
} else {
|
||||
syncForm.minutes = 60;
|
||||
}
|
||||
|
||||
syncForm.apiUrl = res.data.rate_sync_coingecko_api_url || "https://api.coingecko.com";
|
||||
syncForm.apiKey = res.data.rate_sync_coingecko_api_key || "";
|
||||
} else {
|
||||
syncForm.minutes = 60;
|
||||
syncForm.apiUrl = "https://api.coingecko.com";
|
||||
syncForm.apiKey = "";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取同步频率配置失败:", error);
|
||||
syncForm.minutes = 60;
|
||||
Message.warning("获取当前配置失败,使用默认值60分钟");
|
||||
syncForm.apiUrl = "https://api.coingecko.com";
|
||||
syncForm.apiKey = "";
|
||||
Message.warning("获取当前配置失败,使用默认值");
|
||||
}
|
||||
|
||||
syncModalVisible.value = true;
|
||||
@@ -503,18 +545,24 @@ const handleSyncSubmit = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!syncForm.apiUrl) {
|
||||
Message.error("请选择 API 接口");
|
||||
return;
|
||||
}
|
||||
|
||||
syncLoading.value = true;
|
||||
const seconds = syncForm.minutes * 60;
|
||||
|
||||
await setConfAPI({
|
||||
key: "rate_sync_interval",
|
||||
value: seconds.toString()
|
||||
});
|
||||
await setsConfAPI([
|
||||
{ key: "rate_sync_interval", value: seconds.toString() },
|
||||
{ key: "rate_sync_coingecko_api_url", value: syncForm.apiUrl },
|
||||
{ key: "rate_sync_coingecko_api_key", value: syncForm.apiKey }
|
||||
]);
|
||||
|
||||
Message.success(`同步频率已设置为 ${syncForm.minutes} 分钟`);
|
||||
Message.success("汇率同步配置已保存");
|
||||
syncModalVisible.value = false;
|
||||
} catch (error) {
|
||||
console.error("设置同步频率失败:", error);
|
||||
console.error("设置同步配置失败:", error);
|
||||
Message.error("设置失败");
|
||||
} finally {
|
||||
syncLoading.value = false;
|
||||
@@ -525,6 +573,8 @@ const handleSyncCancel = () => {
|
||||
syncModalVisible.value = false;
|
||||
syncFormRef.value?.resetFields();
|
||||
syncForm.minutes = 60;
|
||||
syncForm.apiUrl = "https://api.coingecko.com";
|
||||
syncForm.apiKey = "";
|
||||
};
|
||||
|
||||
// 支付颗粒度相关状态
|
||||
@@ -658,12 +708,19 @@ getCommonTableList();
|
||||
}
|
||||
|
||||
.sync-tip {
|
||||
padding: 8px 12px;
|
||||
padding: 6px 10px;
|
||||
background: #f6f8fa;
|
||||
border: 1px solid #e1e4e8;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-size: 11px;
|
||||
line-height: 1.4;
|
||||
margin-top: 8px;
|
||||
|
||||
hr {
|
||||
margin: 6px 0 0 0;
|
||||
border: none;
|
||||
border-top: 1px solid #e1e4e8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ const getConf = async () => {
|
||||
"admin_username",
|
||||
"admin_secure",
|
||||
"block_height_max_diff",
|
||||
"block_offset_confirm",
|
||||
"admin_login_at",
|
||||
"admin_login_ip",
|
||||
"notify_max_retry",
|
||||
|
||||
@@ -11,6 +11,17 @@
|
||||
<a-input v-model="form.block_height_max_diff" placeholder="推荐 1000" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
field="block_offset_confirm"
|
||||
label="区块偏移确认"
|
||||
extra="启用后可进一步提高交易的安全性,但会增加交易确认的等待时间"
|
||||
>
|
||||
<a-select v-model="form.block_offset_confirm" placeholder="请选择">
|
||||
<a-option value="0">关闭</a-option>
|
||||
<a-option value="1">开启</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item
|
||||
field="notify_max_retry"
|
||||
label="回调最大重试"
|
||||
@@ -72,6 +83,7 @@ const data = defineModel() as any;
|
||||
const form = ref({
|
||||
payment_timeout: "",
|
||||
block_height_max_diff: "",
|
||||
block_offset_confirm: "0",
|
||||
notify_max_retry: "",
|
||||
payment_max_amount: "",
|
||||
payment_min_amount: "",
|
||||
@@ -86,6 +98,12 @@ const rules = {
|
||||
message: "区块高度最大差值不能为空"
|
||||
}
|
||||
],
|
||||
block_offset_confirm: [
|
||||
{
|
||||
required: true,
|
||||
message: "区块偏移确认不能为空"
|
||||
}
|
||||
],
|
||||
notify_max_retry: [
|
||||
{
|
||||
required: true,
|
||||
@@ -133,6 +151,7 @@ const onSubmit = async ({ errors }: ArcoDesign.ArcoSubmit) => {
|
||||
|
||||
await setsConfAPI([
|
||||
{ key: "block_height_max_diff", value: form.value.block_height_max_diff },
|
||||
{ key: "block_offset_confirm", value: form.value.block_offset_confirm },
|
||||
{ key: "notify_max_retry", value: form.value.notify_max_retry },
|
||||
{ key: "payment_max_amount", value: form.value.payment_max_amount },
|
||||
{ key: "payment_min_amount", value: form.value.payment_min_amount },
|
||||
@@ -149,6 +168,7 @@ watch(
|
||||
() => data.value,
|
||||
() => {
|
||||
form.value.block_height_max_diff = data.value.block_height_max_diff;
|
||||
form.value.block_offset_confirm = data.value.block_offset_confirm || "0";
|
||||
form.value.notify_max_retry = data.value.notify_max_retry;
|
||||
form.value.payment_max_amount = data.value.payment_max_amount;
|
||||
form.value.payment_min_amount = data.value.payment_min_amount;
|
||||
|
||||
@@ -98,7 +98,11 @@
|
||||
</div>
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a href="https://github.com/v03413/BEpusdt/" target="_blank" class="help-link">
|
||||
<a
|
||||
href="https://github.com/v03413/BEpusdt/blob/main/docs/tron-grid/readme.md"
|
||||
target="_blank"
|
||||
class="help-link"
|
||||
>
|
||||
<icon-question-circle />
|
||||
获取方法
|
||||
</a>
|
||||
|
||||
@@ -1,276 +1,274 @@
|
||||
<template>
|
||||
<div class="wallet">
|
||||
<div class="snow-page">
|
||||
<div class="snow-inner">
|
||||
<a-form ref="formRef" auto-label-width :model="formData.form">
|
||||
<a-row :gutter="16">
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="6">
|
||||
<a-input v-model="formData.form.name" placeholder="请输入名称" allow-clear />
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="6">
|
||||
<a-input v-model="formData.form.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="6">
|
||||
<a-select v-model="formData.form.trade_type" placeholder="请选择交易类型" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="3">
|
||||
<a-space class="search-btn">
|
||||
<a-button type="primary" @click="getCommonTableList">
|
||||
<template #icon><icon-search /></template>
|
||||
查询
|
||||
</a-button>
|
||||
<a-button @click="onReset">
|
||||
<template #icon><icon-refresh /></template>
|
||||
重置
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="3">
|
||||
<a-button type="primary" status="success" @click="onAdd">
|
||||
<template #icon><icon-plus /></template>
|
||||
新增钱包
|
||||
<div class="snow-page">
|
||||
<div class="snow-inner">
|
||||
<a-form ref="formRef" auto-label-width :model="formData.form">
|
||||
<a-row :gutter="16">
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="6">
|
||||
<a-input v-model="formData.form.name" placeholder="请输入名称" allow-clear />
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="6">
|
||||
<a-input v-model="formData.form.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="6">
|
||||
<a-select v-model="formData.form.trade_type" placeholder="请选择交易类型" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="3">
|
||||
<a-space class="search-btn">
|
||||
<a-button type="primary" @click="getCommonTableList">
|
||||
<template #icon><icon-search /></template>
|
||||
查询
|
||||
</a-button>
|
||||
<a-button @click="onReset">
|
||||
<template #icon><icon-refresh /></template>
|
||||
重置
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
|
||||
<a-table
|
||||
row-key="key"
|
||||
size="small"
|
||||
:bordered="{ cell: true }"
|
||||
:scroll="{ x: 'max-content', y: '60vh' }"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
v-model:selectedKeys="selectedKeys"
|
||||
:pagination="pagination"
|
||||
@page-change="pageChange"
|
||||
@page-size-change="pageSizeChange"
|
||||
>
|
||||
<template #address="{ record }">
|
||||
<div class="address-cell">
|
||||
<a-typography-text copyable class="address-text">
|
||||
{{ record.address }}
|
||||
</a-typography-text>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #status="{ record }">
|
||||
<a-tag size="small" :color="record.status === 1 ? 'green' : 'red'">
|
||||
{{ record.status === 1 ? "启用" : "停用" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template #other_notify="{ record }">
|
||||
<a-tag size="small" :color="record.other_notify === 1 ? 'arcoblue' : 'gray'">
|
||||
{{ record.other_notify === 1 ? "开启" : "关闭" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template #optional="{ record }">
|
||||
<a-space>
|
||||
<a-button size="mini" type="primary" @click="showDetail(record)">详情</a-button>
|
||||
<a-button size="mini" @click="onMod(record)">修改</a-button>
|
||||
<a-popconfirm content="确定删除这条数据吗?" type="warning" @ok="onDelete(record)">
|
||||
<a-button size="mini" type="primary" status="danger">删除</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 新增钱包对话框 -->
|
||||
<a-modal width="40%" v-model:visible="open" @close="afterClose" @ok="addWallet" @cancel="afterClose">
|
||||
<template #title>{{ title }}</template>
|
||||
<a-form ref="formRef" auto-label-width :rules="rules" :model="addFrom">
|
||||
<a-form-item field="name" label="钱包名称" validate-trigger="blur">
|
||||
<a-input v-model="addFrom.name" placeholder="请输入钱包名称" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="address" label="钱包地址" validate-trigger="blur">
|
||||
<a-input v-model="addFrom.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="trade_type" label="交易类型" :rules="[{ required: true, message: '交易类型不能为空' }]">
|
||||
<a-select v-model="addFrom.trade_type" placeholder="请选择" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="other_notify" label="其他通知">
|
||||
<a-select v-model="addFrom.other_notify" placeholder="请选择" allow-clear>
|
||||
<a-option :value="0">关闭</a-option>
|
||||
<a-option :value="1">启用</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="remark" label="备注信息" validate-trigger="blur">
|
||||
<a-textarea v-model="addFrom.remark" placeholder="请输入备注信息" allow-clear />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="6" :xxl="3">
|
||||
<a-button type="primary" status="success" @click="onAdd">
|
||||
<template #icon><icon-plus /></template>
|
||||
新增钱包
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改钱包对话框 -->
|
||||
<a-modal width="40%" v-model:visible="modOpen" @close="afterModClose" @ok="modWallet" @cancel="afterModClose">
|
||||
<template #title>{{ modTitle }}</template>
|
||||
<a-form ref="modFormRef" auto-label-width :rules="rules" :model="modFrom">
|
||||
<a-form-item field="name" label="钱包名称" validate-trigger="blur">
|
||||
<a-input v-model="modFrom.name" placeholder="请输入钱包名称" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="address" label="钱包地址" validate-trigger="blur">
|
||||
<a-input v-model="modFrom.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="trade_type" label="交易类型" :rules="[{ required: true, message: '交易类型不能为空' }]">
|
||||
<a-select v-model="modFrom.trade_type" placeholder="请选择" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="status" label="收款状态">
|
||||
<a-select v-model="modFrom.status" placeholder="请选择" allow-clear>
|
||||
<a-option :value="1">启用</a-option>
|
||||
<a-option :value="0">停用</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="other_notify" label="其他通知">
|
||||
<a-select v-model="modFrom.other_notify" placeholder="请选择" allow-clear>
|
||||
<a-option :value="0">关闭</a-option>
|
||||
<a-option :value="1">开启</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="remark" label="备注信息" validate-trigger="blur">
|
||||
<a-textarea v-model="modFrom.remark" placeholder="请输入备注信息" allow-clear />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 详情对话框 -->
|
||||
<a-modal
|
||||
width="680px"
|
||||
v-model:visible="detailVisible"
|
||||
@close="closeDetail"
|
||||
@cancel="closeDetail"
|
||||
:footer="false"
|
||||
unmount-on-close
|
||||
>
|
||||
<template #title>
|
||||
<div class="detail-modal-title">
|
||||
<icon-star />
|
||||
<span>钱包详情信息</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="detail-content">
|
||||
<a-card class="detail-card" title="基础信息" :bordered="false">
|
||||
<template #extra>
|
||||
<a-tag size="medium" :color="detailData.status === 1 ? 'green' : 'red'" class="status-tag">
|
||||
<icon-check-circle v-if="detailData.status === 1" />
|
||||
<icon-close-circle v-else />
|
||||
{{ detailData.status === 1 ? "启用中" : "已停用" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-idcard />
|
||||
<span>钱包ID</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.id }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-user />
|
||||
<span>钱包名称</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.name }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="24">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-location />
|
||||
<span>钱包地址</span>
|
||||
</div>
|
||||
<div class="detail-value address-value">
|
||||
<a-typography-text copyable>{{ detailData.address }}</a-typography-text>
|
||||
</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-swap />
|
||||
<span>交易类型</span>
|
||||
</div>
|
||||
<div class="detail-value">
|
||||
<a-tag color="blue">{{ detailData.trade_type }}</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-notification />
|
||||
<span>监控状态</span>
|
||||
</div>
|
||||
<div class="detail-value">
|
||||
<a-tag :color="detailData.other_notify === 1 ? 'arcoblue' : 'gray'">
|
||||
<icon-eye v-if="detailData.other_notify === 1" />
|
||||
<icon-eye-invisible v-else />
|
||||
{{ detailData.other_notify === 1 ? "已开启" : "已关闭" }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
|
||||
<a-card class="detail-card" title="备注信息" :bordered="false" v-if="detailData.remark">
|
||||
<div class="remark-content">
|
||||
<icon-message />
|
||||
<span>{{ detailData.remark }}</span>
|
||||
<a-table
|
||||
row-key="key"
|
||||
size="small"
|
||||
:bordered="{ cell: true }"
|
||||
:scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data="data"
|
||||
v-model:selectedKeys="selectedKeys"
|
||||
:pagination="pagination"
|
||||
@page-change="pageChange"
|
||||
@page-size-change="pageSizeChange"
|
||||
>
|
||||
<template #address="{ record }">
|
||||
<div class="address-cell">
|
||||
<a-typography-text copyable class="address-text">
|
||||
{{ record.address }}
|
||||
</a-typography-text>
|
||||
</div>
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
<a-card class="detail-card" title="时间信息" :bordered="false" v-if="detailData.created_at || detailData.updated_at">
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12" v-if="detailData.created_at">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-plus-circle />
|
||||
<span>创建时间</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.created_at }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="12" v-if="detailData.updated_at">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-edit />
|
||||
<span>更新时间</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.updated_at }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
</div>
|
||||
</a-modal>
|
||||
<template #status="{ record }">
|
||||
<a-tag size="small" :color="record.status === 1 ? 'green' : 'red'">
|
||||
{{ record.status === 1 ? "启用" : "停用" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template #other_notify="{ record }">
|
||||
<a-tag size="small" :color="record.other_notify === 1 ? 'arcoblue' : 'gray'">
|
||||
{{ record.other_notify === 1 ? "开启" : "关闭" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<template #optional="{ record }">
|
||||
<a-space>
|
||||
<a-button size="mini" type="primary" @click="showDetail(record)">详情</a-button>
|
||||
<a-button size="mini" @click="onMod(record)">修改</a-button>
|
||||
<a-popconfirm content="确定删除这条数据吗?" type="warning" @ok="onDelete(record)">
|
||||
<a-button size="mini" type="primary" status="danger">删除</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</a-table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 新增钱包对话框 -->
|
||||
<a-modal width="40%" v-model:visible="open" @close="afterClose" @ok="addWallet" @cancel="afterClose">
|
||||
<template #title>{{ title }}</template>
|
||||
<a-form ref="formRef" auto-label-width :rules="rules" :model="addFrom">
|
||||
<a-form-item field="name" label="钱包名称" validate-trigger="blur">
|
||||
<a-input v-model="addFrom.name" placeholder="请输入钱包名称" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="address" label="钱包地址" validate-trigger="blur">
|
||||
<a-input v-model="addFrom.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="trade_type" label="交易类型" :rules="[{ required: true, message: '交易类型不能为空' }]">
|
||||
<a-select v-model="addFrom.trade_type" placeholder="请选择" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="other_notify" label="其他通知">
|
||||
<a-select v-model="addFrom.other_notify" placeholder="请选择" allow-clear>
|
||||
<a-option :value="0">关闭</a-option>
|
||||
<a-option :value="1">启用</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="remark" label="备注信息" validate-trigger="blur">
|
||||
<a-textarea v-model="addFrom.remark" placeholder="请输入备注信息" allow-clear />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 修改钱包对话框 -->
|
||||
<a-modal width="40%" v-model:visible="modOpen" @close="afterModClose" @ok="modWallet" @cancel="afterModClose">
|
||||
<template #title>{{ modTitle }}</template>
|
||||
<a-form ref="modFormRef" auto-label-width :rules="rules" :model="modFrom">
|
||||
<a-form-item field="name" label="钱包名称" validate-trigger="blur">
|
||||
<a-input v-model="modFrom.name" placeholder="请输入钱包名称" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="address" label="钱包地址" validate-trigger="blur">
|
||||
<a-input v-model="modFrom.address" placeholder="请输入钱包地址" allow-clear />
|
||||
</a-form-item>
|
||||
<a-form-item field="trade_type" label="交易类型" :rules="[{ required: true, message: '交易类型不能为空' }]">
|
||||
<a-select v-model="modFrom.trade_type" placeholder="请选择" allow-clear allow-search>
|
||||
<a-option v-for="item in tradeTypeOptions" :key="item.value" :value="item.value">
|
||||
{{ item.label }}
|
||||
</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="status" label="收款状态">
|
||||
<a-select v-model="modFrom.status" placeholder="请选择" allow-clear>
|
||||
<a-option :value="1">启用</a-option>
|
||||
<a-option :value="0">停用</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="other_notify" label="其他通知">
|
||||
<a-select v-model="modFrom.other_notify" placeholder="请选择" allow-clear>
|
||||
<a-option :value="0">关闭</a-option>
|
||||
<a-option :value="1">开启</a-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item field="remark" label="备注信息" validate-trigger="blur">
|
||||
<a-textarea v-model="modFrom.remark" placeholder="请输入备注信息" allow-clear />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 详情对话框 -->
|
||||
<a-modal
|
||||
width="680px"
|
||||
v-model:visible="detailVisible"
|
||||
@close="closeDetail"
|
||||
@cancel="closeDetail"
|
||||
:footer="false"
|
||||
unmount-on-close
|
||||
>
|
||||
<template #title>
|
||||
<div class="detail-modal-title">
|
||||
<icon-star />
|
||||
<span>钱包详情信息</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="detail-content">
|
||||
<a-card class="detail-card" title="基础信息" :bordered="false">
|
||||
<template #extra>
|
||||
<a-tag size="medium" :color="detailData.status === 1 ? 'green' : 'red'" class="status-tag">
|
||||
<icon-check-circle v-if="detailData.status === 1" />
|
||||
<icon-close-circle v-else />
|
||||
{{ detailData.status === 1 ? "启用中" : "已停用" }}
|
||||
</a-tag>
|
||||
</template>
|
||||
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-idcard />
|
||||
<span>钱包ID</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.id }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-user />
|
||||
<span>钱包名称</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.name }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="24">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-location />
|
||||
<span>钱包地址</span>
|
||||
</div>
|
||||
<div class="detail-value address-value">
|
||||
<a-typography-text copyable>{{ detailData.address }}</a-typography-text>
|
||||
</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-swap />
|
||||
<span>交易类型</span>
|
||||
</div>
|
||||
<div class="detail-value">
|
||||
<a-tag color="blue">{{ detailData.trade_type }}</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-notification />
|
||||
<span>监控状态</span>
|
||||
</div>
|
||||
<div class="detail-value">
|
||||
<a-tag :color="detailData.other_notify === 1 ? 'arcoblue' : 'gray'">
|
||||
<icon-eye v-if="detailData.other_notify === 1" />
|
||||
<icon-eye-invisible v-else />
|
||||
{{ detailData.other_notify === 1 ? "已开启" : "已关闭" }}
|
||||
</a-tag>
|
||||
</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
|
||||
<a-card class="detail-card" title="备注信息" :bordered="false" v-if="detailData.remark">
|
||||
<div class="remark-content">
|
||||
<icon-message />
|
||||
<span>{{ detailData.remark }}</span>
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<a-card class="detail-card" title="时间信息" :bordered="false" v-if="detailData.created_at || detailData.updated_at">
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12" v-if="detailData.created_at">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-plus-circle />
|
||||
<span>创建时间</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.created_at }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
<a-col :span="12" v-if="detailData.updated_at">
|
||||
<div class="detail-item">
|
||||
<div class="detail-label">
|
||||
<icon-edit />
|
||||
<span>更新时间</span>
|
||||
</div>
|
||||
<div class="detail-value">{{ detailData.updated_at }}</div>
|
||||
</div>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
</div>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -437,7 +435,11 @@ const addWallet = async () => {
|
||||
if (state) return;
|
||||
|
||||
try {
|
||||
await addWalletAPI(addFrom.value);
|
||||
const submitData = {
|
||||
...addFrom.value,
|
||||
other_notify: addFrom.value.other_notify ?? 0
|
||||
};
|
||||
await addWalletAPI(submitData);
|
||||
open.value = false;
|
||||
getCommonTableList();
|
||||
Notification.success("添加成功");
|
||||
@@ -464,25 +466,6 @@ getCommonTableList();
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wallet {
|
||||
height: 100%;
|
||||
|
||||
.snow-page {
|
||||
height: 100%;
|
||||
|
||||
.snow-inner {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.arco-table-container {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||