custom donation content

This commit is contained in:
xiaomlove
2022-05-06 22:25:00 +08:00
parent cc7b046926
commit 83c0a261db
9 changed files with 144 additions and 19 deletions

View File

@@ -9,6 +9,13 @@ class Setting extends NexusModel
{
protected $fillable = ['name', 'value'];
/**
* get setting autoload = yes with cache
*
* @param null $name
* @param null $default
* @return array|\ArrayAccess|false|int|mixed|string|null
*/
public static function get($name = null, $default = null)
{
$settings = NexusDB::remember("nexus_settings_in_laravel", 600, function () {
@@ -20,18 +27,19 @@ class Setting extends NexusModel
return Arr::get($settings, $name, $default);
}
public static function getFromDb($name = null, $default = null)
/**
* get setting autoload = yes without cache
*
* @param null $name
* @param null $default
* @return mixed
*/
public static function getFromDb($name = null, $default = null): mixed
{
$rows = self::query()->get(['name', 'value']);
$rows = self::query()->where('autoload', 'yes')->get(['name', 'value']);
$result = [];
foreach ($rows as $row) {
$value = $row->value;
if (!is_null($value)) {
$arr = json_decode($value, true);
if (is_array($arr)) {
$value = $arr;
}
}
$value = self::normalizeValue($row);
Arr::set($result, $row->name, $value);
}
if (is_null($name)) {
@@ -40,4 +48,42 @@ class Setting extends NexusModel
return Arr::get($result, $name, $default);
}
/**
* get from db by name, generally used for `autoload` = 'no'
*
* @param $name
* @param null $default
* @return mixed
*/
public static function getByName($name, $default = null): mixed
{
$result = self::query()->where('name', $name)->first();
if ($result) {
return self::normalizeValue($result);
}
return $default;
}
public static function getByWhereRaw($whereRaw): array
{
$result = [];
$list = self::query()->whereRaw($whereRaw)->get();
foreach ($list as $value) {
Arr::set($result, $value->name, self::normalizeValue($value));
}
return $result;
}
public static function normalizeValue(Setting $setting)
{
$value = $setting->value;
if (!is_null($value)) {
$arr = json_decode($value, true);
if (is_array($arr)) {
$value = $arr;
}
}
return $value;
}
}

View File

@@ -25,7 +25,7 @@ class ClaimRepository extends BaseRepository
public function store($uid, $torrentId)
{
$isEnabled = Claim::getConfigIsEnabled();
if ($isEnabled) {
if (!$isEnabled) {
throw new \RuntimeException(nexus_trans("torrent.claim_disabled"));
}
$exists = Claim::query()->where('uid', $uid)->where('torrent_id', $torrentId)->exists();