发布推送
This commit is contained in:
45
app/Cache/Base/TableBaseCache.php
Normal file
45
app/Cache/Base/TableBaseCache.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Cache\Base;
|
||||
|
||||
use App\Models\Follow\FollowModel;
|
||||
|
||||
//用户缓存用户基础信息(等于数据表)primary_key为主键
|
||||
abstract class TableBaseCache extends BaseCache
|
||||
{
|
||||
public string $table_class;
|
||||
public string $primary_key_column = 'uid';
|
||||
public array $get_columns = ['*'];
|
||||
public array $get_exclude_columns = [];
|
||||
|
||||
function loadTable(): array|null
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
function loadData(): array|null
|
||||
{
|
||||
//默认获取表数据方式
|
||||
if (!empty($table_class)) {
|
||||
$oTable = new $this->table_class();
|
||||
//排除不需要的字段
|
||||
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;
|
||||
$aData = $oData->toArray();
|
||||
//排除不需要的字段
|
||||
if (!empty($this->get_exclude_columns) && $this->get_columns == ['*'] && !empty($aData)) {
|
||||
foreach ($this->get_exclude_columns as $sColumn) {
|
||||
unset($aData[$sColumn]);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($aData)) return null;
|
||||
return $aData;
|
||||
} else {
|
||||
return $this->loadTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user