🐛 修改余额
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"likedream-goframe/internal/service/balance"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -132,22 +133,25 @@ func (s *UserInfoServiceV1) CardRecharge(ctx context.Context, req *v1.CardRechar
|
||||
tx, err := db.Global.Tx(ctx)
|
||||
utils.OkOrPanic(err)
|
||||
parent := user.QueryParent().WithAgent().FirstX(ctx)
|
||||
// 返现20%
|
||||
r, _ := decimal.NewFromString("0.2")
|
||||
cashbackValue := decimal.NewFromUint64(card.Value).Mul(r)
|
||||
if parent != nil {
|
||||
// 返现20%
|
||||
r, _ := decimal.NewFromString("0.2")
|
||||
cashbackValue := decimal.NewFromUint64(card.Value).Mul(r)
|
||||
// 这里查询父级是否是代理,代理的话要x代理费率
|
||||
if parent.Edges.Agent != nil {
|
||||
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)
|
||||
} else {
|
||||
//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.SysUser.UpdateOneID(user.ID).SetBalance(user.Balance.Add(decimal.NewFromUint64(card.Value))).ExecX(ctx)
|
||||
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 {
|
||||
return oops.
|
||||
WithContext(ctx).
|
||||
|
||||
Reference in New Issue
Block a user