开始增加支付-1
This commit is contained in:
@@ -81,6 +81,42 @@ func (r *Repository) Recharge(userID uint64, amount float64) (*AccountDTO, error
|
||||
return r.Account(userID)
|
||||
}
|
||||
|
||||
func (r *Repository) ConfirmRechargeFromChannel(userID uint64, bizNo string, amountCent int64) error {
|
||||
if userID == 0 || amountCent <= 0 || bizNo == "" {
|
||||
return ErrInvalidAmount
|
||||
}
|
||||
amount := roundWalletMoney(float64(amountCent) / 100)
|
||||
return r.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := ensureAccount(tx, userID); err != nil {
|
||||
return err
|
||||
}
|
||||
var account model.WalletAccount
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
Where("user_id = ?", userID).
|
||||
First(&account).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var existing int64
|
||||
if err := tx.Model(&model.WalletLedger{}).
|
||||
Where("user_id = ? AND biz_type = ? AND biz_no = ?", userID, "channel_recharge", bizNo).
|
||||
Count(&existing).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if existing > 0 {
|
||||
return nil
|
||||
}
|
||||
return AppendEntries(tx, Entry{
|
||||
UserID: userID,
|
||||
Direction: "in",
|
||||
Amount: amount,
|
||||
BalanceType: "available",
|
||||
BizType: "channel_recharge",
|
||||
BizNo: bizNo,
|
||||
Remark: "渠道充值入账",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Repository) AdminLedger(query AdminLedgerQuery) (*PaginatedResult, error) {
|
||||
db := r.db.Table("wallet_ledger AS wl").
|
||||
Select(`wl.id, wl.ledger_no, wl.user_id, COALESCE(u.phone, '') AS user_phone,
|
||||
|
||||
Reference in New Issue
Block a user