/
home
/
pay
/
server_old
/
packages
/
rooyesh
/
wallet
/
src
/
interfaces
/
File Upload :
llllll
Current File: //home/pay/server_old/packages/rooyesh/wallet/src/interfaces/WalletInterface.php
<?php namespace Rooyesh\Wallet\interfaces; use Rooyesh\Wallet\models\Wallet; use Rooyesh\Wallet\models\Transaction; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class WalletInterface { public $wallet = null; public $owner_id = null; public $owner_type = null; public $fund_id = null; function __construct($owner_id, $owner_type, $fund_id=null) { $this->owner_id = $owner_id; $this->owner_type = $owner_type; if (wallet::where([ ['owner', '=', $owner_id], ['owner_type', '=', $owner_type], ['fund_id', '=', $fund_id], ])->count()) { $this->wallet = wallet::where([ ['owner', '=', $owner_id], ['owner_type', '=', $owner_type], ['fund_id', '=', $fund_id], ])->first(); $this->validate(); } else { $this->wallet = Wallet::create([ 'owner' => $owner_id, 'owner_type' => $owner_type, 'gold' => 0, 'cash' => 0, 'fund_id'=>$fund_id ]); $this->set_hash(); } } public function validate(): bool { // if ($this->wallet->hash !== $this->generate_hash()) { // throw new UnprocessableEntityHttpException('امکان شارز این کیف پول وجود ندارد'); // } return true; } private function generate_hash(): string { $last_transaction = Transaction::where('wallet', '=', $this->wallet->id)->orderBy('created_at', 'DESC')->first(); $last_transaction_hash = $last_transaction ? hash('sha256', $last_transaction->hash) : ''; return hash('sha256', hash('sha256', $this->wallet->gold) . hash('sha256', $this->wallet->cash) . hash('sha256', $this->wallet->owner) . $last_transaction_hash . "yhoenszeaf"); } public function set_hash(): bool { $this->wallet->hash = $this->generate_hash(); $this->wallet->save(); return true; } }
Copyright ©2k19 -
Hexid
|
Tex7ure