chore: 初始开源发布
iotlcm-worker-svr:异步执行中枢(RabbitMQ 消费者 + 全量同步编排)。 - Go module:iotlcm-worker-svr → git.5iot.com/iotlcm-public/iotlcm-worker-svr(214 文件) - 凭据与内部标识脱敏:MySQL/Redis 凭据、私网与生产 IP、内网域名、 库名 xiujie_admin → iotlcm、哨兵名占位 - 159 处真实手机号 → 合法 11 位编造号(保留号段与后 4 位,维持互异, 不破坏「校验 MSISDN 格式」等测试断言) - 移除内部资产:CI 触发器、Jenkins 触发测试文档、预演门禁与镜像 digest 记录 - Dockerfile 改用公共基础镜像(golang:1.25-alpine → alpine:3.23), 移除写死的 git 凭据 - README 重写(架构/全量同步模型/配置/已知失败),补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 已知:3 个测试包在源仓同一提交上同样失败(client/upstream、 service/allocate、service/inbound),属既有缺陷,本仓未引入亦未修复。
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
)
|
||||
|
||||
type alipayConfig struct {
|
||||
AppID string `yaml:"appId"`
|
||||
PrivateKey string `yaml:"privateKey"`
|
||||
AlipayPublicKey string `yaml:"alipayPublicKey"`
|
||||
IsProduction bool `yaml:"isProduction"`
|
||||
}
|
||||
|
||||
type alipayTradeQueryer struct {
|
||||
once sync.Once
|
||||
client *alipay.Client
|
||||
clientErr error
|
||||
}
|
||||
|
||||
func newAlipayTradeQueryer() *alipayTradeQueryer {
|
||||
return &alipayTradeQueryer{}
|
||||
}
|
||||
|
||||
func (q *alipayTradeQueryer) Query(ctx context.Context, outTradeNo string) (*TradeQueryResult, error) {
|
||||
client, err := q.getClient(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rsp, err := q.tradeQueryWithRetry(ctx, client, alipay.TradeQuery{OutTradeNo: outTradeNo})
|
||||
if err != nil {
|
||||
if isAlipayTradeNotFound(err.Error()) {
|
||||
return &TradeQueryResult{OutTradeNo: outTradeNo, TradeStatus: string(alipay.TradeStatusWaitBuyerPay)}, nil
|
||||
}
|
||||
return nil, gerror.Wrap(err, "query Alipay trade failed")
|
||||
}
|
||||
if rsp == nil {
|
||||
return nil, gerror.New("Alipay trade query returned no result")
|
||||
}
|
||||
if rsp.IsFailure() {
|
||||
if isAlipayTradeNotFound(string(rsp.Code), rsp.SubCode, rsp.SubMsg) {
|
||||
return &TradeQueryResult{OutTradeNo: outTradeNo, TradeStatus: string(alipay.TradeStatusWaitBuyerPay)}, nil
|
||||
}
|
||||
return nil, gerror.Newf("Alipay trade query failed: code=%s, subCode=%s, subMsg=%s", rsp.Code, rsp.SubCode, rsp.SubMsg)
|
||||
}
|
||||
return &TradeQueryResult{
|
||||
OutTradeNo: rsp.OutTradeNo,
|
||||
TradeNo: rsp.TradeNo,
|
||||
TradeStatus: string(rsp.TradeStatus),
|
||||
TotalAmount: rsp.TotalAmount,
|
||||
BuyerLogonID: rsp.BuyerLogonId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (q *alipayTradeQueryer) getClient(ctx context.Context) (*alipay.Client, error) {
|
||||
q.once.Do(func() {
|
||||
cfg := alipayConfig{}
|
||||
if err := g.Cfg().MustGet(ctx, "alipay").Scan(&cfg); err != nil {
|
||||
q.clientErr = gerror.Wrap(err, "read Alipay config failed")
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(cfg.AppID) == "" || strings.TrimSpace(cfg.PrivateKey) == "" || strings.TrimSpace(cfg.AlipayPublicKey) == "" {
|
||||
q.clientErr = gerror.New("Alipay credentials are not configured")
|
||||
return
|
||||
}
|
||||
q.client, q.clientErr = alipay.New(cfg.AppID, cfg.PrivateKey, cfg.IsProduction, alipay.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}))
|
||||
if q.clientErr != nil {
|
||||
q.clientErr = gerror.Wrap(q.clientErr, "initialize Alipay client failed")
|
||||
return
|
||||
}
|
||||
if err := q.client.LoadAliPayPublicKey(cfg.AlipayPublicKey); err != nil {
|
||||
q.clientErr = gerror.Wrap(err, "load Alipay public key failed")
|
||||
}
|
||||
})
|
||||
if q.clientErr != nil {
|
||||
return nil, q.clientErr
|
||||
}
|
||||
return q.client, nil
|
||||
}
|
||||
|
||||
func (q *alipayTradeQueryer) tradeQueryWithRetry(ctx context.Context, client *alipay.Client, query alipay.TradeQuery) (*alipay.TradeQueryRsp, error) {
|
||||
var err error
|
||||
for attempt := 1; attempt <= 3; attempt++ {
|
||||
rsp, queryErr := client.TradeQuery(ctx, query)
|
||||
if queryErr == nil {
|
||||
return rsp, nil
|
||||
}
|
||||
err = queryErr
|
||||
if !isRetryableAlipayError(err) || attempt == 3 {
|
||||
return nil, err
|
||||
}
|
||||
if err = sleepWithContext(ctx, time.Duration(attempt)*300*time.Millisecond); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func isRetryableAlipayError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return true
|
||||
}
|
||||
msg := strings.ToLower(err.Error())
|
||||
for _, marker := range []string{"invalid character '<'", "unexpected end of json", "bad response", "eof", "timeout", "connection reset", "connection refused", "tls handshake", "temporary", "too many requests", "429", "500", "502", "503", "504"} {
|
||||
if strings.Contains(msg, marker) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isAlipayTradeNotFound(parts ...string) bool {
|
||||
msg := strings.ToLower(strings.Join(parts, " "))
|
||||
return strings.Contains(msg, "acq.trade_not_exist") || strings.Contains(msg, "trade_not_exist") || strings.Contains(msg, "transaction not exist") || strings.Contains(msg, "交易不存在") || strings.Contains(msg, "订单不存在")
|
||||
}
|
||||
|
||||
func sleepWithContext(ctx context.Context, delay time.Duration) error {
|
||||
timer := time.NewTimer(delay)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-timer.C:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
const (
|
||||
rechargeStatusPending = iota
|
||||
rechargeStatusPaid
|
||||
rechargeStatusExpired
|
||||
|
||||
rechargeChannelAlipay = 1
|
||||
)
|
||||
|
||||
type TradeQueryResult struct {
|
||||
OutTradeNo string
|
||||
TradeNo string
|
||||
TradeStatus string
|
||||
TotalAmount string
|
||||
BuyerLogonID string
|
||||
}
|
||||
|
||||
type TradeQueryer interface {
|
||||
Query(context.Context, string) (*TradeQueryResult, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
queryer TradeQueryer
|
||||
}
|
||||
|
||||
func New() *Service {
|
||||
return NewWithQuery(newAlipayTradeQueryer())
|
||||
}
|
||||
|
||||
func NewWithQuery(queryer TradeQueryer) *Service {
|
||||
return &Service{queryer: queryer}
|
||||
}
|
||||
|
||||
func (s *Service) CheckRechargeTimeout(ctx context.Context, outTradeNo string) error {
|
||||
outTradeNo = strings.TrimSpace(outTradeNo)
|
||||
if outTradeNo == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
detail := rechargeDetail{}
|
||||
if err := g.DB().Model("t_balance_detail").Ctx(ctx).
|
||||
Where("order_sn", outTradeNo).
|
||||
Where("transaction_channel", rechargeChannelAlipay).
|
||||
Scan(&detail); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
return gerror.Wrap(err, "query recharge detail failed")
|
||||
}
|
||||
if detail.ID == 0 || detail.TransactionStatus != rechargeStatusPending {
|
||||
return nil
|
||||
}
|
||||
if s.queryer == nil {
|
||||
return gerror.New("alipay trade queryer is not configured")
|
||||
}
|
||||
|
||||
result, err := s.queryer.Query(ctx, outTradeNo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result != nil && (result.TradeStatus == "TRADE_SUCCESS" || result.TradeStatus == "TRADE_FINISHED") {
|
||||
return s.creditRecharge(ctx, detail, result)
|
||||
}
|
||||
|
||||
_, err = g.DB().Model("t_balance_detail").Ctx(ctx).
|
||||
Where("id", detail.ID).
|
||||
Where("transaction_status", rechargeStatusPending).
|
||||
Data(g.Map{
|
||||
"transaction_status": rechargeStatusExpired,
|
||||
"remark": "Alipay recharge timed out without payment",
|
||||
"updated_at": gtime.Now(),
|
||||
}).
|
||||
Update()
|
||||
return gerror.Wrap(err, "expire recharge detail failed")
|
||||
}
|
||||
|
||||
func (s *Service) creditRecharge(ctx context.Context, initial rechargeDetail, result *TradeQueryResult) error {
|
||||
amount := gconv.Float64(strings.TrimSpace(result.TotalAmount))
|
||||
if amount <= 0 {
|
||||
return gerror.New("paid recharge has invalid amount")
|
||||
}
|
||||
|
||||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
detail := rechargeDetail{}
|
||||
detailModel := lockForUpdate(tx.Ctx(ctx).Model("t_balance_detail"))
|
||||
if err := detailModel.
|
||||
Where("id", initial.ID).
|
||||
Scan(&detail); err != nil {
|
||||
return gerror.Wrap(err, "lock recharge detail failed")
|
||||
}
|
||||
if detail.ID == 0 || detail.TransactionStatus == rechargeStatusPaid {
|
||||
return nil
|
||||
}
|
||||
if detail.TransactionStatus != rechargeStatusPending {
|
||||
return gerror.New("recharge order is closed")
|
||||
}
|
||||
if math.Abs(detail.Amount-amount) > 0.001 {
|
||||
return gerror.New("paid amount does not match recharge detail")
|
||||
}
|
||||
|
||||
account := agentBalance{}
|
||||
accountModel := lockForUpdate(tx.Ctx(ctx).Model("t_agent_balance"))
|
||||
if err := accountModel.
|
||||
Where("dept_id", detail.DeptID).
|
||||
Where("tenant_id", detail.TenantID).
|
||||
Scan(&account); err != nil {
|
||||
return gerror.Wrap(err, "lock agent balance failed")
|
||||
}
|
||||
now := gtime.Now()
|
||||
if account.ID == 0 {
|
||||
id, err := tx.Ctx(ctx).Model("t_agent_balance").Data(g.Map{
|
||||
"dept_id": detail.DeptID,
|
||||
"balance": 0,
|
||||
"withdraw_amount": 0,
|
||||
"withdraw_amount_status": 1,
|
||||
"invoice_amount": 0,
|
||||
"can_invoice_amount": 0,
|
||||
"credit_limit": 0,
|
||||
"used_credit": 0,
|
||||
"pending_repayment": 0,
|
||||
"status": 0,
|
||||
"tenant_id": detail.TenantID,
|
||||
"created_dept": detail.CreatedDept,
|
||||
"created_by": detail.CreatedBy,
|
||||
"created_at": now,
|
||||
}).InsertAndGetId()
|
||||
if err != nil {
|
||||
return gerror.Wrap(err, "initialize agent balance failed")
|
||||
}
|
||||
account = agentBalance{ID: id}
|
||||
}
|
||||
|
||||
before := account.Balance
|
||||
after := before + detail.Amount
|
||||
if _, err := tx.Ctx(ctx).Model("t_agent_balance").Where("id", account.ID).Data(g.Map{
|
||||
"balance": after,
|
||||
"updated_by": detail.CreatedBy,
|
||||
"updated_at": now,
|
||||
}).Update(); err != nil {
|
||||
return gerror.Wrap(err, "update agent balance failed")
|
||||
}
|
||||
_, err := tx.Ctx(ctx).Model("t_balance_detail").Where("id", detail.ID).Data(g.Map{
|
||||
"transaction_status": rechargeStatusPaid,
|
||||
"transaction_time": now,
|
||||
"before_balance": before,
|
||||
"balance_after": after,
|
||||
"channel_serial_no": result.TradeNo,
|
||||
"remark": fmt.Sprintf("Alipay recharge, buyer: %s", result.BuyerLogonID),
|
||||
"updated_by": detail.CreatedBy,
|
||||
"updated_at": now,
|
||||
}).Update()
|
||||
return gerror.Wrap(err, "mark recharge paid failed")
|
||||
})
|
||||
}
|
||||
|
||||
type rechargeDetail struct {
|
||||
ID int64 `orm:"id"`
|
||||
DeptID int64 `orm:"dept_id"`
|
||||
TransactionStatus int `orm:"transaction_status"`
|
||||
Amount float64 `orm:"amount"`
|
||||
TenantID string `orm:"tenant_id"`
|
||||
CreatedDept int64 `orm:"created_dept"`
|
||||
CreatedBy int64 `orm:"created_by"`
|
||||
}
|
||||
|
||||
type agentBalance struct {
|
||||
ID int64 `orm:"id"`
|
||||
Balance float64 `orm:"balance"`
|
||||
}
|
||||
|
||||
func lockForUpdate(model *gdb.Model) *gdb.Model {
|
||||
if g.DB().GetConfig().Type == "sqlite" {
|
||||
return model
|
||||
}
|
||||
return model.LockUpdate()
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type tradeQueryerStub struct {
|
||||
result *TradeQueryResult
|
||||
err error
|
||||
calls int
|
||||
}
|
||||
|
||||
func (s *tradeQueryerStub) Query(_ context.Context, _ string) (*TradeQueryResult, error) {
|
||||
s.calls++
|
||||
return s.result, s.err
|
||||
}
|
||||
|
||||
func TestCheckRechargeTimeout(t *testing.T) {
|
||||
g.Log().SetWriter(io.Discard)
|
||||
ctx := context.Background()
|
||||
if err := gdb.SetConfig(gdb.Config{
|
||||
"default": gdb.ConfigGroup{{Type: "sqlite", Name: filepath.Join(t.TempDir(), "balance.db")}},
|
||||
}); err != nil {
|
||||
t.Fatalf("configure test database: %v", err)
|
||||
}
|
||||
defer g.DB().Close(ctx)
|
||||
createBalanceTables(t, ctx)
|
||||
|
||||
t.Run("paid recharge is credited exactly once", func(t *testing.T) {
|
||||
insertRechargeDetail(t, ctx, "BAL-PAID", 10)
|
||||
insertAgentBalance(t, ctx, 11, "tenant-1", 5)
|
||||
queryer := &tradeQueryerStub{result: &TradeQueryResult{TradeStatus: "TRADE_SUCCESS", TotalAmount: "10.00", TradeNo: "ALI-1"}}
|
||||
service := NewWithQuery(queryer)
|
||||
|
||||
if err := service.CheckRechargeTimeout(ctx, "BAL-PAID"); err != nil {
|
||||
t.Fatalf("first check failed: %v", err)
|
||||
}
|
||||
if status := rechargeStatus(t, ctx, "BAL-PAID"); status != rechargeStatusPaid {
|
||||
t.Fatalf("expected paid status, got %d", status)
|
||||
}
|
||||
if balance := agentBalanceValue(t, ctx, 11, "tenant-1"); balance != 15 {
|
||||
t.Fatalf("expected balance 15, got %v", balance)
|
||||
}
|
||||
if err := service.CheckRechargeTimeout(ctx, "BAL-PAID"); err != nil {
|
||||
t.Fatalf("duplicate check failed: %v", err)
|
||||
}
|
||||
if queryer.calls != 1 {
|
||||
t.Fatalf("expected one Alipay query, got %d", queryer.calls)
|
||||
}
|
||||
if balance := agentBalanceValue(t, ctx, 11, "tenant-1"); balance != 15 {
|
||||
t.Fatalf("duplicate message changed balance to %v", balance)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unpaid recharge is expired", func(t *testing.T) {
|
||||
insertRechargeDetail(t, ctx, "BAL-EXPIRED", 10)
|
||||
service := NewWithQuery(&tradeQueryerStub{result: &TradeQueryResult{TradeStatus: "WAIT_BUYER_PAY"}})
|
||||
if err := service.CheckRechargeTimeout(ctx, "BAL-EXPIRED"); err != nil {
|
||||
t.Fatalf("timeout check failed: %v", err)
|
||||
}
|
||||
if status := rechargeStatus(t, ctx, "BAL-EXPIRED"); status != rechargeStatusExpired {
|
||||
t.Fatalf("expected expired status, got %d", status)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("missing recharge is ignored", func(t *testing.T) {
|
||||
queryer := &tradeQueryerStub{err: errors.New("must not be called")}
|
||||
if err := NewWithQuery(queryer).CheckRechargeTimeout(ctx, "BAL-MISSING"); err != nil {
|
||||
t.Fatalf("missing recharge returned error: %v", err)
|
||||
}
|
||||
if queryer.calls != 0 {
|
||||
t.Fatalf("missing recharge queried Alipay %d times", queryer.calls)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("amount mismatch returns an error without crediting", func(t *testing.T) {
|
||||
insertRechargeDetail(t, ctx, "BAL-MISMATCH", 10)
|
||||
insertAgentBalance(t, ctx, 11, "tenant-1", 15)
|
||||
service := NewWithQuery(&tradeQueryerStub{result: &TradeQueryResult{TradeStatus: "TRADE_SUCCESS", TotalAmount: "9.00"}})
|
||||
if err := service.CheckRechargeTimeout(ctx, "BAL-MISMATCH"); err == nil {
|
||||
t.Fatal("expected amount mismatch error")
|
||||
}
|
||||
if status := rechargeStatus(t, ctx, "BAL-MISMATCH"); status != rechargeStatusPending {
|
||||
t.Fatalf("mismatch changed status to %d", status)
|
||||
}
|
||||
if balance := agentBalanceValue(t, ctx, 11, "tenant-1"); balance != 15 {
|
||||
t.Fatalf("mismatch changed balance to %v", balance)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Alipay failure is returned for delayed retry", func(t *testing.T) {
|
||||
insertRechargeDetail(t, ctx, "BAL-RETRY", 10)
|
||||
service := NewWithQuery(&tradeQueryerStub{err: errors.New("Alipay unavailable")})
|
||||
if err := service.CheckRechargeTimeout(ctx, "BAL-RETRY"); err == nil {
|
||||
t.Fatal("expected query error")
|
||||
}
|
||||
if status := rechargeStatus(t, ctx, "BAL-RETRY"); status != rechargeStatusPending {
|
||||
t.Fatalf("retryable failure changed status to %d", status)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func createBalanceTables(t *testing.T, ctx context.Context) {
|
||||
t.Helper()
|
||||
statements := []string{
|
||||
`CREATE TABLE t_balance_detail (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
dept_id INTEGER NOT NULL,
|
||||
transaction_status INTEGER NOT NULL,
|
||||
transaction_channel INTEGER NOT NULL,
|
||||
amount REAL NOT NULL,
|
||||
order_sn TEXT NOT NULL,
|
||||
tenant_id TEXT NOT NULL,
|
||||
created_dept INTEGER NOT NULL,
|
||||
created_by INTEGER NOT NULL,
|
||||
transaction_time DATETIME,
|
||||
before_balance REAL,
|
||||
balance_after REAL,
|
||||
channel_serial_no TEXT,
|
||||
remark TEXT,
|
||||
updated_by INTEGER,
|
||||
updated_at DATETIME
|
||||
)`,
|
||||
`CREATE TABLE t_agent_balance (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
dept_id INTEGER NOT NULL,
|
||||
balance REAL NOT NULL,
|
||||
withdraw_amount REAL,
|
||||
withdraw_amount_status INTEGER,
|
||||
invoice_amount REAL,
|
||||
can_invoice_amount REAL,
|
||||
credit_limit REAL,
|
||||
used_credit REAL,
|
||||
pending_repayment REAL,
|
||||
status INTEGER,
|
||||
tenant_id TEXT NOT NULL,
|
||||
created_dept INTEGER,
|
||||
created_by INTEGER,
|
||||
created_at DATETIME,
|
||||
updated_by INTEGER,
|
||||
updated_at DATETIME
|
||||
)`,
|
||||
}
|
||||
for _, statement := range statements {
|
||||
if _, err := g.DB().Exec(ctx, statement); err != nil {
|
||||
t.Fatalf("create table: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func insertRechargeDetail(t *testing.T, ctx context.Context, orderSN string, amount float64) {
|
||||
t.Helper()
|
||||
if _, err := g.DB().Model("t_balance_detail").Ctx(ctx).Data(g.Map{
|
||||
"dept_id": 11,
|
||||
"transaction_status": rechargeStatusPending,
|
||||
"transaction_channel": rechargeChannelAlipay,
|
||||
"amount": amount,
|
||||
"order_sn": orderSN,
|
||||
"tenant_id": "tenant-1",
|
||||
"created_dept": 11,
|
||||
"created_by": 7,
|
||||
}).Insert(); err != nil {
|
||||
t.Fatalf("insert recharge detail: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func insertAgentBalance(t *testing.T, ctx context.Context, deptID int64, tenantID string, balance float64) {
|
||||
t.Helper()
|
||||
if _, err := g.DB().Model("t_agent_balance").Ctx(ctx).Data(g.Map{"dept_id": deptID, "tenant_id": tenantID, "balance": balance}).Insert(); err != nil {
|
||||
t.Fatalf("insert agent balance: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func rechargeStatus(t *testing.T, ctx context.Context, orderSN string) int {
|
||||
t.Helper()
|
||||
value, err := g.DB().Model("t_balance_detail").Ctx(ctx).Where("order_sn", orderSN).Value("transaction_status")
|
||||
if err != nil {
|
||||
t.Fatalf("get recharge status: %v", err)
|
||||
}
|
||||
return value.Int()
|
||||
}
|
||||
|
||||
func agentBalanceValue(t *testing.T, ctx context.Context, deptID int64, tenantID string) float64 {
|
||||
t.Helper()
|
||||
value, err := g.DB().Model("t_agent_balance").Ctx(ctx).Where("dept_id", deptID).Where("tenant_id", tenantID).Value("balance")
|
||||
if err != nil {
|
||||
t.Fatalf("get agent balance: %v", err)
|
||||
}
|
||||
return value.Float64()
|
||||
}
|
||||
Reference in New Issue
Block a user