重构交易处理逻辑,合并充值与购买流程,优化交易状态管理;更新相关数据结构和接口

This commit is contained in:
2025-06-26 09:28:42 +08:00
parent 065a7c77c3
commit 7d0bd84649
18 changed files with 843 additions and 919 deletions

View File

@@ -2,15 +2,21 @@ package globals
import (
"github.com/go-redsync/redsync/v4/redis/goredis/v9"
"log/slog"
"net"
"platform/pkg/env"
"platform/web/core"
"github.com/go-redsync/redsync/v4"
"github.com/redis/go-redis/v9"
)
var Redis *redis.Client
var Redsync *redsync.Redsync
var Redsync *ExtendRedSync
type ExtendRedSync struct {
*redsync.Redsync
}
func initRedis() {
client := redis.NewClient(&redis.Options{
@@ -23,7 +29,7 @@ func initRedis() {
sync := redsync.New(pool)
Redis = client
Redsync = sync
Redsync = &ExtendRedSync{sync}
}
func ExitRedis() error {
@@ -32,3 +38,18 @@ func ExitRedis() error {
}
return nil
}
func (r *ExtendRedSync) WithLock(key string, callback func() error) error {
var mutex = Redsync.NewMutex(key)
var err = mutex.Lock()
if err != nil {
return core.NewServErr("服务繁忙,请稍后重试")
}
defer func(mutex *redsync.Mutex) {
if ok, err := mutex.Unlock(); err != nil {
slog.Error("解锁失败", slog.Bool("ok", ok), slog.Any("err", err))
}
}(mutex)
return callback()
}

View File

@@ -324,8 +324,10 @@ func (s *SftClient) sign(msg any) (*request, error) {
return nil, fmt.Errorf("格式化加密正文失败:%w", err)
}
pretty, _ := json.MarshalIndent(msg, "", " ")
println("content:\n" + string(pretty) + "\n\n")
if env.DebugHttpDump {
pretty, _ := json.MarshalIndent(msg, "", " ")
println("content:\n" + string(pretty) + "\n\n")
}
body := request{
AppId: s.appid,