Compare commits

..
6 Commits
9 changed files with 61 additions and 28 deletions
+2
View File
@@ -19,6 +19,8 @@ body:
required: true
- label: 我明白任何人针对我提交的问题没有义务提供帮助,包括项目维护者。
required: true
- label: 我没有阅读这个清单,只是闭眼选中了所有的复选框,请关闭这个 Issue 。
required: true
- type: dropdown
attributes:
label: 问题类型
-1
View File
@@ -1,7 +1,6 @@
package conf
const (
Secret = "BEpusdt, a more user-friendly personal cryptocurrency payment gateway!"
AdminTokenK = "admin_token"
AdminSecureK = "admin_secure"
)
+4 -4
View File
@@ -65,7 +65,7 @@ func (Conf) Del(ctx *gin.Context) {
return
}
model.Db.Where("`k` = ?", req.Key).Delete(&model.Conf{})
model.Db.Where("k = ?", req.Key).Delete(&model.Conf{})
base.Ok(ctx, "删除成功")
}
@@ -79,7 +79,7 @@ func (Conf) Gets(ctx *gin.Context) {
}
var items = make([]model.Conf, 0)
model.Db.Where("`k` IN ?", req.Keys).Find(&items)
model.Db.Where("k IN ?", req.Keys).Find(&items)
var data = gin.H{}
for _, item := range items {
@@ -119,7 +119,7 @@ func (Conf) Sets(ctx *gin.Context) {
}
}
model.Db.Where("`k` IN ?", keys).Delete(&model.Conf{})
model.Db.Where("k IN ?", keys).Delete(&model.Conf{})
model.Db.Create(&data)
defer model.RefreshC()
@@ -136,7 +136,7 @@ func (Conf) Notifier(ctx *gin.Context) {
}
var keys = []string{string(model.NotifierChannel), string(model.NotifierParams)}
model.Db.Where("`k` IN ?", keys).Delete(&model.Conf{})
model.Db.Where("k IN ?", keys).Delete(&model.Conf{})
model.Db.Create(&[]model.Conf{
{K: model.NotifierChannel, V: req.Channel},
{K: model.NotifierParams, V: string(req.Params)},
+1
View File
@@ -124,6 +124,7 @@ func ConfInit() {
var data = map[ConfKey]string{
ApiAppUri: "",
ApiAuthToken: token,
AdminSecret: utils.StrSha256(hash),
AdminSecure: secure,
AdminUsername: username,
AdminPassword: string(encrypt),
+1
View File
@@ -31,6 +31,7 @@ const (
AdminUsername ConfKey = "admin_username"
AdminPassword ConfKey = "admin_password"
AdminSecure ConfKey = "admin_secure"
AdminSecret ConfKey = "admin_secret"
AdminLoginIP ConfKey = "admin_login_ip"
AdminLoginAt ConfKey = "admin_login_at"
+7 -13
View File
@@ -6,17 +6,18 @@ import (
"time"
)
var localLocation = time.Local
type Datetime time.Time
func (d *Datetime) MarshalJSON() ([]byte, error) {
tTime := time.Time(*d)
tTime := time.Time(*d).In(localLocation)
return []byte(fmt.Sprintf("\"%v\"", tTime.Format("2006-01-02 15:04:05"))), nil
}
func (d Datetime) Value() (driver.Value, error) {
var zeroTime time.Time
tlt := time.Time(d)
// 判断给定时间是否和默认零时间的时间戳相同
if tlt.UnixNano() == zeroTime.UnixNano() {
return nil, nil
}
@@ -26,34 +27,27 @@ func (d Datetime) Value() (driver.Value, error) {
func (d *Datetime) Scan(v interface{}) error {
if value, ok := v.(time.Time); ok {
*d = Datetime(value)
return nil
}
return fmt.Errorf("can not convert %v to timestamp", v)
}
func (d *Datetime) String() string {
return time.Time(*d).Format(time.DateTime)
return time.Time(*d).In(localLocation).Format(time.DateTime)
}
func (d *Datetime) Year() string {
return time.Time(*d).Format("2006")
return time.Time(*d).In(localLocation).Format("2006")
}
func (d *Datetime) Before(u time.Time) bool {
return time.Time(*d).Before(u)
}
func (d *Datetime) Time() time.Time {
return time.Time(*d)
return time.Time(*d).In(localLocation)
}
func (d *Datetime) Format(layout string) string {
return time.Time(*d).Format(layout)
return time.Time(*d).In(localLocation).Format(layout)
}
+11 -3
View File
@@ -34,6 +34,8 @@ type Trade struct {
Amount string
}
var buildMutex sync.Mutex
func BuildOrder(p OrderParams) (Order, error) {
var order Order
@@ -71,9 +73,15 @@ func BuildOrder(p OrderParams) (Order, error) {
return RebuildOrder(order, p)
}
var lock sync.Mutex
lock.Lock()
defer lock.Unlock()
buildMutex.Lock()
defer buildMutex.Unlock()
Db.Where("order_id = ?", p.OrderId).Order("id desc").Limit(1).Find(&order)
if order.Status == OrderStatusSuccess || order.Status == OrderStatusConfirming {
return order, nil
}
if order.Status == OrderStatusWaiting {
return RebuildOrder(order, p)
}
data, err := BuildTrade(p)
if err != nil {
+1 -2
View File
@@ -23,8 +23,7 @@ func Handler() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
engine = gin.New()
session := memstore.NewStore([]byte(conf.Secret))
session := memstore.NewStore([]byte(model.GetK(model.AdminSecret)))
session.Options(sessions.Options{
MaxAge: 86400,
HttpOnly: true,
+34 -5
View File
@@ -27,7 +27,7 @@ docker run -d --restart=unless-stopped -p 8080:8080 v03413/bepusdt:latest
- `v03413/bepusdt:latest` - 稳定发行版(推荐生产环境使用)
- `v03413/bepusdt:nightly` - 每日构建开发版(包含最新特性,适合测试环境)
## 数据持久化配置
## 数据持久化
### SQLite 数据库(默认)
@@ -47,18 +47,45 @@ docker run -d --restart=unless-stopped -p 8080:8080 -v [挂载路径]:/var/lib/b
docker run -d --restart=unless-stopped -p 8080:8080 -v /opt/bepusdt:/var/lib/bepusdt v03413/bepusdt:latest
```
### MySQL 数据库(可选)
<details>
<summary><strong>PostgreSQL 数据库(推荐)</strong></summary>
系统支持使用 MySQL 作为数据存储方案,适用于需要更强大数据库功能的场景。
系统支持使用 PostgreSQL 作为数据存储方案,适用于生产环境。这是目前推荐的数据库方案。
**前置准备:**
- MySQL 版本:5.7 或更高版本
- 需提前完成 MySQL 安装及安全配置
- PostgreSQL 版本:18 或更高版本
- 需提前完成 PostgreSQL 安装及安全配置
- 已创建专用数据库(如 `bepusdt`)
**部署命令:**
```bash
docker run -d \
--restart unless-stopped \
-p 8080:8080 \
-e POSTGRESQL_DSN=postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3 \
v03413/bepusdt:latest
```
**配置说明:**
- 将 `user` 替换为 PostgreSQL 用户名
- 将 `password` 替换为 PostgreSQL 密码
- 将 `localhost:5432` 替换为 PostgreSQL 服务器地址和端口
- 将 `bepusdt` 替换为实际数据库名称
</details>
<details>
<summary><strong>MySQL 数据库(已弃用)</strong></summary>
> **注意:** MySQL 支持将逐步弃用,建议使用 PostgreSQL 替代。
系统仍支持使用 MySQL 作为数据存储方案,但不再推荐用于新部署。
**部署命令:**
```bash
docker run -d \
--restart unless-stopped \
@@ -74,6 +101,8 @@ docker run -d \
- 将 `127.0.0.1:3306` 替换为 MySQL 服务器地址和端口
- 将 `bepusdt` 替换为实际数据库名称(如需要)
</details>
## 部署验证
### 查看容器日志