fix: buy history
This commit is contained in:
@@ -378,6 +378,31 @@ func (svc *Service) Checkout(ctx context.Context, tenantId, userId, mediaId int6
|
||||
return errors.Wrap(err, "update user balance")
|
||||
}
|
||||
|
||||
// add user balance
|
||||
tblUserBalances := table.UserBalanceHistories
|
||||
stmtUserBalances := tblUserBalances.
|
||||
INSERT(
|
||||
tblUserBalances.TenantID,
|
||||
tblUserBalances.UserID,
|
||||
tblUserBalances.Balance,
|
||||
tblUserBalances.Target,
|
||||
tblUserBalances.Type,
|
||||
).
|
||||
VALUES(
|
||||
Int(tenantId),
|
||||
Int(userId),
|
||||
Int(-media.Price),
|
||||
Json(pg.BalanceTarget{
|
||||
ID: media.ID,
|
||||
Name: table.Medias.TableName(),
|
||||
}.MustValue()),
|
||||
String(pg.BalanceTypeConsume.String()),
|
||||
)
|
||||
log.Debug(stmtUserBalances.DebugSql())
|
||||
if _, err := stmtUserBalances.ExecContext(ctx, tx); err != nil {
|
||||
return errors.Wrap(err, "insert user balance")
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return errors.Wrap(err, "commit transaction")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user