Changeset View
Changeset View
Standalone View
Standalone View
src/app/Wallet.php
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | class Wallet extends Model | ||||
public function credit(int $amount, string $description = ''): Wallet | public function credit(int $amount, string $description = ''): Wallet | ||||
{ | { | ||||
$this->balance += $amount; | $this->balance += $amount; | ||||
$this->save(); | $this->save(); | ||||
\App\Transaction::create( | \App\Transaction::create( | ||||
[ | [ | ||||
'user_email' => \App\Utils::userEmailOrNull(), | |||||
'object_id' => $this->id, | 'object_id' => $this->id, | ||||
'object_type' => \App\Wallet::class, | 'object_type' => \App\Wallet::class, | ||||
'type' => \App\Transaction::WALLET_CREDIT, | 'type' => \App\Transaction::WALLET_CREDIT, | ||||
'amount' => $amount, | 'amount' => $amount, | ||||
'description' => $description | 'description' => $description | ||||
] | ] | ||||
); | ); | ||||
Show All 15 Lines | public function debit(int $amount, array $eTIDs = []): Wallet | ||||
} | } | ||||
$this->balance -= $amount; | $this->balance -= $amount; | ||||
$this->save(); | $this->save(); | ||||
$transaction = \App\Transaction::create( | $transaction = \App\Transaction::create( | ||||
[ | [ | ||||
'user_email' => \App\Utils::userEmailOrNull(), | |||||
'object_id' => $this->id, | 'object_id' => $this->id, | ||||
'object_type' => \App\Wallet::class, | 'object_type' => \App\Wallet::class, | ||||
'type' => \App\Transaction::WALLET_DEBIT, | 'type' => \App\Transaction::WALLET_DEBIT, | ||||
'amount' => $amount | 'amount' => $amount | ||||
] | ] | ||||
); | ); | ||||
\App\Transaction::whereIn('id', $eTIDs)->update(['transaction_id' => $transaction->id]); | \App\Transaction::whereIn('id', $eTIDs)->update(['transaction_id' => $transaction->id]); | ||||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |