⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.1
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
muhasebe
/
modules
/
User
/
Traits
/
View File Name :
HasWallet.php
<?php namespace Modules\User\Traits; use Modules\User\Models\Wallet\Transaction; trait HasWallet { public function getBalanceAttribute() { return (int)$this->credit_balance; } public function getPendingBalanceAttribute() { return (int)$this->transactions()->where('status', 'pending')->sum('amount'); } public function withdraw($amount, $meta = [], $refId = null) { if ($this->balance < $amount) { throw new \Exception("BALANCE_NOT_ENOUGH"); } $data = [ 'user_id' => $this->id, 'amount' => $amount, 'type' => 'withdraw', 'meta' => $meta ]; if ($refId) { $data['ref_id'] = $refId; } $trans = new Transaction(); $trans->fillByAttr(array_keys($data), $data); $trans->save(); $this->credit_balance -= $amount; $this->save(); return $trans; } public function deposit($amount, $meta = [], $refId = null, $status = 'confirmed') { $data = [ 'user_id' => $this->id, 'amount' => $amount, 'type' => 'deposit', 'meta' => $meta, 'status' => $status ]; if ($refId) { $data['ref_id'] = $refId; } $trans = new Transaction(); $trans->fillByAttr(array_keys($data), $data); $trans->save(); $this->credit_balance += $amount; $this->save(); return $trans; } public function draftDeposit($amount, $paymentId) { $data = [ 'user_id' => $this->id, 'amount' => $amount, 'type' => 'deposit', 'status' => 'pending', 'payment_id' => $paymentId ]; $trans = new Transaction(); $trans->fillByAttr(array_keys($data), $data); $trans->save(); return $trans; } public function transactions() { return $this->hasMany(Transaction::class, 'user_id'); } }