add back to top

This commit is contained in:
xiaomlove
2022-04-04 17:26:26 +08:00
parent 9af8e5e442
commit 325c234442
38 changed files with 686 additions and 498 deletions

View File

@@ -21,6 +21,8 @@ class Attendance extends NexusModel
30 => 1000
];
const MAX_RETROACTIVE_DAYS = 30;
public function logs(): \Illuminate\Database\Eloquent\Relations\HasMany
{

View File

@@ -10,13 +10,16 @@ class BonusLogs extends NexusModel
protected $fillable = ['uid', 'business_type', 'old_total_value', 'value', 'new_total_value', 'comment'];
const DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN = 10000;
const DEFAULT_BONUS_BUY_ATTENDANCE_CARD = 1000;
const BUSINESS_TYPE_CANCEL_HIT_AND_RUN = 1;
const BUSINESS_TYPE_BUY_MEDAL = 2;
const BUSINESS_TYPE_BUY_ATTENDANCE_CARD = 3;
public static $businessTypes = [
public static array $businessTypes = [
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
self::BUSINESS_TYPE_BUY_MEDAL => ['text' => 'Buy medal'],
self::BUSINESS_TYPE_BUY_ATTENDANCE_CARD => ['text' => 'Buy attendance card'],
];
public static function getBonusForCancelHitAndRun()
@@ -25,5 +28,11 @@ class BonusLogs extends NexusModel
return $result ?? self::DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN;
}
public static function getBonusForBuyAttendanceCard()
{
$result = Setting::get('bonus.attendance_card');
return $result ?? self::DEFAULT_BONUS_BUY_ATTENDANCE_CARD;
}
}

View File

@@ -3,34 +3,41 @@
namespace App\Models;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Nexus\Database\NexusDB;
class Setting extends NexusModel
{
protected $fillable = ['name', 'value'];
public static function get($name = null)
public static function get($name = null, $default = null)
{
$settings = NexusDB::remember("nexus_settings_in_laravel", 10, function () {
$rows = self::query()->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;
}
}
Arr::set($result, $row->name, $value);
}
return $result;
return self::getFromDb();
});
if (is_null($name)) {
return $settings;
}
return Arr::get($settings, $name);
return Arr::get($settings, $name, $default);
}
public static function getFromDb($name = null, $default = null)
{
$rows = self::query()->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;
}
}
Arr::set($result, $row->name, $value);
}
if (is_null($name)) {
return $result;
}
return Arr::get($result, $name, $default);
}
}