userInfo()->lockForUpdate()->first(); if ($userInfo === null) { throw new BizException('系统错误'); } // 变更前余额 $beforeBalance = $userInfo->quota_v1; $_changeBalance = abs($changeBalance); if ($changeBalance > 0) { // 收入 $user->userInfo()->increment('quota_v1', $_changeBalance); } else { // 支出 if ($userInfo->quota_v1 < $_changeBalance) { throw new BizException('老配额不足'); } $user->userInfo()->decrement('quota_v1', $_changeBalance); } $user->walletLogs()->create([ 'loggable_id' => $loggable?->id, 'loggable_type' => $loggable?->getMorphClass(), 'before_balance' => $beforeBalance, 'change_balance' => $changeBalance, 'action' => $action, 'remarks' => $remarks, ]); } }