48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
namespace App\Models\Wallet\Wallet;
|
|
|
|
use App\Models\Wallet\Base\WalletBaseModel;
|
|
use App\Tools\Math;
|
|
|
|
class WalletCurrencyModel extends WalletBaseModel
|
|
{
|
|
protected $table = 'wallet_currency';
|
|
protected $primaryKey = 'id';
|
|
protected $fillable = [
|
|
'id',
|
|
'type',
|
|
'name',
|
|
'code',
|
|
'token',
|
|
'transfer_rate',
|
|
'desc',
|
|
'created_at',
|
|
];
|
|
|
|
const TYPE_CASH = 1;
|
|
const TYPE_CRYPTO_COIN = 2;
|
|
const TYPE = [
|
|
self::TYPE_CASH => '现金',
|
|
self::TYPE_CRYPTO_COIN => '加密货币',
|
|
];
|
|
const CODE_USDT_TRC20 = 'USDT_TRC20';
|
|
|
|
function findByCode($code,$columns = ['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
|
{
|
|
return $this->newQuery()->where('code',$code)->first($columns);
|
|
}
|
|
|
|
function findByToken($token,$columns = ['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
|
{
|
|
return $this->newQuery()->where('token',$token)->first($columns);
|
|
}
|
|
|
|
function computeTransferRate($amount,$rate): string
|
|
{
|
|
if(empty($amount)) return 0;
|
|
if(empty($rate)) return 0;
|
|
return Math::bcMul(abs($amount),$rate,Math::SCALE_4);
|
|
}
|
|
|
|
}
|