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

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

34
web/domains/bill/bill.go Normal file
View File

@@ -0,0 +1,34 @@
package bill
import (
"github.com/shopspring/decimal"
m "platform/web/models"
)
func NewForRecharge(uid int32, billNo string, info string, amount decimal.Decimal, trade *m.Trade) *m.Bill {
return &m.Bill{
UserID: uid,
BillNo: billNo,
TradeID: &trade.ID,
Type: int32(TypeRecharge),
Info: &info,
Amount: amount,
}
}
func NewForConsume(uid int32, billNo string, info string, amount decimal.Decimal, resource *m.Resource, trade ...*m.Trade) *m.Bill {
var bill = &m.Bill{
UserID: uid,
BillNo: billNo,
ResourceID: &resource.ID,
Type: int32(TypeConsume),
Info: &info,
Amount: amount,
}
if len(trade) > 0 {
bill.TradeID = &trade[0].ID
}
return bill
}

View File

@@ -1,5 +1,10 @@
package trade
import (
"github.com/shopspring/decimal"
m "platform/web/models"
)
type Type int32
const (
@@ -39,3 +44,16 @@ const (
StatusSuccess // 已支付
StatusCanceled // 已取消
) // 已退款
type ProductInfo interface {
GetType() Type
GetSubject() string
GetAmount() decimal.Decimal
Serialize() (string, error)
Deserialize(str string) error
}
type CompleteEvent interface {
Check(t Type) (ProductInfo, bool)
OnTradeComplete(info ProductInfo, trade *m.Trade) error
}