新增订单待支付与支付确认后端流程
This commit is contained in:
@@ -57,6 +57,24 @@ func (r *Repository) Ledger(userID uint64) ([]LedgerDTO, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (r *Repository) Recharge(userID uint64, amount float64) (*AccountDTO, error) {
|
||||
err := r.db.Transaction(func(tx *gorm.DB) error {
|
||||
return AppendEntries(tx, Entry{
|
||||
UserID: userID,
|
||||
Direction: "in",
|
||||
Amount: amount,
|
||||
BalanceType: "available",
|
||||
BizType: "dev_recharge",
|
||||
BizNo: "DEV",
|
||||
Remark: "开发环境充值",
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.Account(userID)
|
||||
}
|
||||
|
||||
func (r *Repository) AdminLedger(query AdminLedgerQuery) ([]AdminLedgerDTO, error) {
|
||||
limit := query.Limit
|
||||
if limit <= 0 || limit > 500 {
|
||||
@@ -146,6 +164,9 @@ func applyEntry(account *model.WalletAccount, entry Entry) (float64, error) {
|
||||
if entry.Direction == "in" {
|
||||
account.AvailableBalance += entry.Amount
|
||||
} else {
|
||||
if account.AvailableBalance < entry.Amount {
|
||||
return 0, ErrInsufficientBalance
|
||||
}
|
||||
account.AvailableBalance -= entry.Amount
|
||||
}
|
||||
return account.AvailableBalance, nil
|
||||
@@ -153,6 +174,9 @@ func applyEntry(account *model.WalletAccount, entry Entry) (float64, error) {
|
||||
if entry.Direction == "in" {
|
||||
account.FrozenBalance += entry.Amount
|
||||
} else {
|
||||
if account.FrozenBalance < entry.Amount {
|
||||
return 0, ErrInsufficientBalance
|
||||
}
|
||||
account.FrozenBalance -= entry.Amount
|
||||
}
|
||||
return account.FrozenBalance, nil
|
||||
|
||||
Reference in New Issue
Block a user