wallet tron transactions
This commit is contained in:
@ -30,12 +30,17 @@ abstract class BaseCache
|
||||
$sCacheKey = $this->getPrimaryKey();
|
||||
$aData = $this->loadData();
|
||||
if (empty($aData)) return false;
|
||||
return Cache::put($sCacheKey, serialize($aData), self::CACHE_TTL);
|
||||
return Cache::put($sCacheKey, $aData, self::CACHE_TTL);
|
||||
}
|
||||
|
||||
abstract function loadData(): array|null;
|
||||
abstract function loadData(): array|string|null;
|
||||
|
||||
function getCacheData($primary_key = null): array|null
|
||||
function get($key): array|string|null
|
||||
{
|
||||
return $this->getCacheData($key);
|
||||
}
|
||||
|
||||
function getCacheData($primary_key = null): array|string|null
|
||||
{
|
||||
if ($primary_key === null) $primary_key = $this->primary_key;
|
||||
if (empty($primary_key)) return [];
|
||||
@ -43,10 +48,10 @@ abstract class BaseCache
|
||||
$sData = Cache::get($sCacheKey);
|
||||
if (empty($sData)) {
|
||||
$this->primary_key = $primary_key;
|
||||
if($this->loadToCache()) $sData = Cache::get($sCacheKey);
|
||||
if ($this->loadToCache()) $sData = Cache::get($sCacheKey);
|
||||
}
|
||||
if (empty($sData)) return null;
|
||||
return unserialize($sData);
|
||||
return $sData;
|
||||
}
|
||||
|
||||
//根据primary_key获取缓存数据单个值,不指定key就默认获取所有
|
||||
@ -55,7 +60,7 @@ abstract class BaseCache
|
||||
if ($primary_key === null) $primary_key = $this->primary_key;
|
||||
if (empty($primary_key)) return false;
|
||||
$aData = $this->getCacheData($primary_key);
|
||||
if(empty($aData)) return null;
|
||||
if (empty($aData)) return null;
|
||||
if (empty($key)) return $aData;
|
||||
return $aData[$key] ?? '';
|
||||
}
|
||||
@ -68,4 +73,10 @@ abstract class BaseCache
|
||||
return Cache::forget($sCacheKey);
|
||||
}
|
||||
|
||||
function clearAll(): bool
|
||||
{
|
||||
if (empty($this->primary_prefix)) return false;
|
||||
return Cache::forget($this->primary_prefix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
42
app/Cache/Base/KeyBaseCache.php
Normal file
42
app/Cache/Base/KeyBaseCache.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Base;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
abstract class KeyBaseCache
|
||||
{
|
||||
protected string $prefix = 'Key:'; //缓存前缀
|
||||
const CACHE_TTL = 60 * 60 * 24 * 3; //缓存时间 3天
|
||||
|
||||
function getByKey($key): string|array|bool|null
|
||||
{
|
||||
return Cache::get($key);
|
||||
}
|
||||
|
||||
function setKey($key, $value): bool
|
||||
{
|
||||
return Cache::put($this->getKey($key), $value);
|
||||
}
|
||||
|
||||
function setKeyWithExp($key, $value, $exp = self::CACHE_TTL): bool
|
||||
{
|
||||
return Cache::put($this->getKey($key), $value, $exp);
|
||||
}
|
||||
|
||||
function getPrefix(): string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
function getKey($key): string
|
||||
{
|
||||
return $this->getPrefix().$key;
|
||||
}
|
||||
|
||||
function removeKey($key): bool
|
||||
{
|
||||
return Cache::forget($this->getKey($key));
|
||||
}
|
||||
|
||||
}
|
||||
59
app/Cache/Base/SetBaseCache.php
Normal file
59
app/Cache/Base/SetBaseCache.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Base;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
//无序集合缓存基类
|
||||
abstract class SetBaseCache
|
||||
{
|
||||
|
||||
protected $client;
|
||||
protected string $prefix = 'Set:'; //缓存前缀
|
||||
protected string $set_name = ''; //集合名
|
||||
const CACHE_TTL = 60 * 60 * 24 * 3; //缓存时间 3天
|
||||
|
||||
function getRedis()
|
||||
{
|
||||
if(!$this->client) $this->client = Redis::client();
|
||||
return $this->client ;
|
||||
}
|
||||
|
||||
function getAll(): bool
|
||||
{
|
||||
return $this->getRedis()->sMembers($this->getSetName());
|
||||
}
|
||||
|
||||
function checkKey($value): bool
|
||||
{
|
||||
return $this->getRedis()->sIsMember($this->getSetName(),$value);
|
||||
}
|
||||
|
||||
function setKey($value): bool
|
||||
{
|
||||
return $this->getRedis()->sAdd($this->getSetName(),$value);
|
||||
}
|
||||
|
||||
function removeKey($value): bool
|
||||
{
|
||||
return $this->getRedis()->sRem($this->getSetName(),$value);
|
||||
}
|
||||
|
||||
function getCount()
|
||||
{
|
||||
return $this->getRedis()->sCard($this->getSetName());
|
||||
}
|
||||
|
||||
function getPrefix(): string
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
function getSetName(): string
|
||||
{
|
||||
return $this->getPrefix().$this->set_name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -10,12 +10,12 @@ abstract class TableBaseCache extends BaseCache
|
||||
public array $get_columns = ['*'];
|
||||
public array $get_exclude_columns = [];
|
||||
|
||||
function loadTable(): array|null
|
||||
function loadTable(): array|string|null
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
function loadData(): array|null
|
||||
function loadData(): array|string|null
|
||||
{
|
||||
//默认获取表数据方式
|
||||
if (!empty($table_class)) {
|
||||
@ -23,7 +23,7 @@ abstract class TableBaseCache extends BaseCache
|
||||
//排除不需要的字段
|
||||
if (!empty($this->get_exclude_columns) && $this->get_columns != ['*']) $this->get_columns = array_diff($this->get_columns, $this->get_exclude_columns);
|
||||
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||
if($oData->isEmpty()) return null;
|
||||
if ($oData->isEmpty()) return null;
|
||||
$aData = $oData->toArray();
|
||||
//排除不需要的字段
|
||||
if (!empty($this->get_exclude_columns) && $this->get_columns == ['*'] && !empty($aData)) {
|
||||
|
||||
23
app/Cache/Key/TronKeyCache.php
Normal file
23
app/Cache/Key/TronKeyCache.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Key;
|
||||
|
||||
use App\Cache\Base\KeyBaseCache;
|
||||
|
||||
class TronKeyCache extends KeyBaseCache
|
||||
{
|
||||
protected string $prefix = 'WalletTronKeyCache:'; //缓存前缀
|
||||
|
||||
const NOW_BLOCK = 'nowBlock'; //当前区块
|
||||
|
||||
function setNowBlock(string $block): bool
|
||||
{
|
||||
return $this->setKey(self::NOW_BLOCK, $block);
|
||||
}
|
||||
|
||||
function getNowBlock(): bool|array|string|null
|
||||
{
|
||||
return $this->getByKey(self::NOW_BLOCK);
|
||||
}
|
||||
|
||||
}
|
||||
11
app/Cache/Set/TronWalletAddressSetCache.php
Normal file
11
app/Cache/Set/TronWalletAddressSetCache.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Set;
|
||||
|
||||
use App\Cache\Base\SetBaseCache;
|
||||
|
||||
class TronWalletAddressSetCache extends SetBaseCache
|
||||
{
|
||||
protected string $set_name = 'TronWalletAddressSetCache:'; //缓存前缀
|
||||
|
||||
}
|
||||
42
app/Cache/Table/Api/TableCustomerSettingCache.php
Normal file
42
app/Cache/Table/Api/TableCustomerSettingCache.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Table\Api;
|
||||
|
||||
use App\Cache\Base\TableBaseCache;
|
||||
use App\Models\Api\Other\CustomerSettingModel;
|
||||
|
||||
//用户缓存用户基础信息(结构自己组装不完全等于数据表)uid为主键
|
||||
class TableCustomerSettingCache extends TableBaseCache
|
||||
{
|
||||
|
||||
public string $table_class = CustomerSettingModel::class;
|
||||
public string $primary_prefix = 'TableCustomerSettingCache:'; //后面跟name
|
||||
|
||||
public string $primary_key_column = 'name';
|
||||
public array $get_columns = [
|
||||
'value',
|
||||
];
|
||||
|
||||
const NAME_WITHDRAW_FEE_AMOUNT = 'withdraw_fee_amount';
|
||||
|
||||
//只存值 key为name value为value
|
||||
function loadData(): array|string|null
|
||||
{
|
||||
$oTable = new $this->table_class();
|
||||
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||
if ($oData->isEmpty()) return null;
|
||||
$aData = $oData->toArray();
|
||||
|
||||
if (empty($aData)) return null;
|
||||
return $aData['value'];
|
||||
}
|
||||
|
||||
function getWithdrawFeeAmount(): string|null
|
||||
{
|
||||
$res = $this->get(self::NAME_WITHDRAW_FEE_AMOUNT);
|
||||
if (empty($res)) $res = 0;
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace App\Cache\Table;
|
||||
|
||||
namespace App\Cache\Table\Api;
|
||||
|
||||
use App\Cache\Base\TableBaseCache;
|
||||
use App\Models\Api\Customer\CustomerUserModel;
|
||||
@ -18,5 +19,4 @@ class TableCustomerUserCache extends TableBaseCache
|
||||
];
|
||||
|
||||
|
||||
|
||||
}
|
||||
41
app/Cache/Table/Wallet/TableWalletSettingCache.php
Normal file
41
app/Cache/Table/Wallet/TableWalletSettingCache.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace App\Cache\Table\Wallet;
|
||||
|
||||
use App\Cache\Base\TableBaseCache;
|
||||
use App\Models\Wallet\Other\WalletSettingModel;
|
||||
|
||||
//用户缓存用户基础信息(结构自己组装不完全等于数据表)uid为主键
|
||||
class TableWalletSettingCache extends TableBaseCache
|
||||
{
|
||||
|
||||
public string $table_class = WalletSettingModel::class;
|
||||
public string $primary_prefix = 'TableWalletSettingCache:'; //后面跟name
|
||||
|
||||
public string $primary_key_column = 'name';
|
||||
public array $get_columns = [
|
||||
'value',
|
||||
];
|
||||
|
||||
const NAME_WITHDRAW_FEE_AMOUNT = 'withdraw_fee_amount';
|
||||
|
||||
//只存值 key为name value为value
|
||||
function loadData(): array|string|null
|
||||
{
|
||||
$oTable = new $this->table_class();
|
||||
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||
if ($oData->isEmpty()) return null;
|
||||
$aData = $oData->toArray();
|
||||
|
||||
if (empty($aData)) return null;
|
||||
return $aData['value'];
|
||||
}
|
||||
|
||||
function getWithdrawFeeAmount(): string|null
|
||||
{
|
||||
$res = $this->get(self::NAME_WITHDRAW_FEE_AMOUNT);
|
||||
if (empty($res)) $res = 0;
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user