🐛 修改余额

This commit is contained in:
sugarBecomer
2025-11-08 00:21:53 +08:00
parent 90bbc11712
commit 604245add2
@@ -12,6 +12,7 @@ import (
"likedream-goframe/internal/ent/sysrole" "likedream-goframe/internal/ent/sysrole"
"likedream-goframe/internal/ent/sysuser" "likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/framework/ent2" "likedream-goframe/internal/framework/ent2"
"likedream-goframe/internal/service/balance"
"likedream-goframe/internal/utils" "likedream-goframe/internal/utils"
"strings" "strings"
"time" "time"
@@ -132,22 +133,25 @@ func (s *UserInfoServiceV1) CardRecharge(ctx context.Context, req *v1.CardRechar
tx, err := db.Global.Tx(ctx) tx, err := db.Global.Tx(ctx)
utils.OkOrPanic(err) utils.OkOrPanic(err)
parent := user.QueryParent().WithAgent().FirstX(ctx) parent := user.QueryParent().WithAgent().FirstX(ctx)
// 返现20%
r, _ := decimal.NewFromString("0.2")
cashbackValue := decimal.NewFromUint64(card.Value).Mul(r)
if parent != nil { if parent != nil {
// 返现20%
r, _ := decimal.NewFromString("0.2")
cashbackValue := decimal.NewFromUint64(card.Value).Mul(r)
// 这里查询父级是否是代理,代理的话要x代理费率 // 这里查询父级是否是代理,代理的话要x代理费率
if parent.Edges.Agent != nil { if parent.Edges.Agent != nil {
cashbackValue = cashbackValue.Mul(parent.Edges.Agent.Rate) cashbackValue = cashbackValue.Mul(parent.Edges.Agent.Rate)
} }
tx.SysUser.UpdateOneID(user.Edges.Parent.ID).SetBalance(parent.Balance.Add(cashbackValue)).SetInviteCashback(parent.InviteCashback.Add(cashbackValue)).ExecX(ctx) tx.SysUser.UpdateOneID(user.Edges.Parent.ID).SetInviteCashback(parent.InviteCashback.Add(cashbackValue)).ExecX(ctx)
tx.SysCard.UpdateOneID(card.ID).SetStatus(syscard.StatusCashback).SetUsedID(user.ID).SetCashUserID(user.Edges.Parent.ID).SetCashValue(cashbackValue).ExecX(ctx) tx.SysCard.UpdateOneID(card.ID).SetStatus(syscard.StatusCashback).SetUsedID(user.ID).SetCashUserID(user.Edges.Parent.ID).SetCashValue(cashbackValue).ExecX(ctx)
} else { } else {
//tx.SysCard.UpdateOneID(card.ID).SetStatus(cst.CardStatusUsed).SetUsedID(user.ID).ExecX(ctx) //tx.SysCard.UpdateOneID(card.ID).SetStatus(cst.CardStatusUsed).SetUsedID(user.ID).ExecX(ctx)
tx.SysCard.UpdateOneID(card.ID).SetStatus(syscard.StatusUsed).SetUsedID(user.ID).ExecX(ctx) tx.SysCard.UpdateOneID(card.ID).SetStatus(syscard.StatusUsed).SetUsedID(user.ID).ExecX(ctx)
} }
tx.SysUser.UpdateOneID(user.ID).SetBalance(user.Balance.Add(decimal.NewFromUint64(card.Value))).ExecX(ctx)
err = tx.Commit() err = tx.Commit()
balance.BalanceService.ChangeUserBalance(ctx, user.ID, decimal.NewFromUint64(card.Value))
if parent != nil {
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, cashbackValue)
}
utils.OkOrPanic(err, func(err error) error { utils.OkOrPanic(err, func(err error) error {
return oops. return oops.
WithContext(ctx). WithContext(ctx).