优化可提和余额变更
parent
f60c6f2ea0
commit
99c9b1f88e
|
|
@ -20,16 +20,21 @@ class BalanceService
|
|||
*/
|
||||
public function changeBalance(User $user, int $changeBalance, int $action, ?string $remarks = null, $loggable = null)
|
||||
{
|
||||
if ($changeBalance === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$balance = $user->balance()->lockForUpdate()->first();
|
||||
|
||||
if (is_null($balance)) {
|
||||
if ($balance === null) {
|
||||
if ($changeBalance < 0) {
|
||||
throw new BalanceNotEnoughException();
|
||||
} else {
|
||||
$user->balance()->create();
|
||||
|
||||
$balance = $user->balance()->lockForUpdate()->first();
|
||||
}
|
||||
|
||||
// 创建余额表
|
||||
$user->balance()->create();
|
||||
// 锁定余额表
|
||||
$balance = $user->balance()->lockForUpdate()->first();
|
||||
}
|
||||
|
||||
// 变更前余额
|
||||
|
|
|
|||
|
|
@ -20,16 +20,21 @@ class WalletService
|
|||
*/
|
||||
public function changeBalance(User $user, int $changeBalance, int $action, ?string $remarks = null, $loggable = null)
|
||||
{
|
||||
if ($changeBalance === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wallet = $user->wallet()->lockForUpdate()->first();
|
||||
|
||||
if (is_null($wallet)) {
|
||||
if ($wallet === null) {
|
||||
if ($changeBalance < 0) {
|
||||
throw new WalletNotEnoughException();
|
||||
} else {
|
||||
$user->wallet()->create();
|
||||
|
||||
$wallet = $user->wallet()->lockForUpdate()->first();
|
||||
}
|
||||
|
||||
// 创建可提表
|
||||
$user->wallet()->create();
|
||||
// 锁定可提表
|
||||
$wallet = $user->wallet()->lockForUpdate()->first();
|
||||
}
|
||||
|
||||
// 变更前余额
|
||||
|
|
|
|||
Loading…
Reference in New Issue