mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
medal management
This commit is contained in:
@@ -12,9 +12,11 @@ class BonusLogs extends NexusModel
|
||||
const DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN = 10000;
|
||||
|
||||
const BUSINESS_TYPE_CANCEL_HIT_AND_RUN = 1;
|
||||
const BUSINESS_TYPE_BUY_MEDAL = 2;
|
||||
|
||||
public static $businessTypes = [
|
||||
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
|
||||
self::BUSINESS_TYPE_BUY_MEDAL => ['text' => 'Buy medal'],
|
||||
];
|
||||
|
||||
public static function getBonusForCancelHitAndRun()
|
||||
|
||||
39
app/Models/Medal.php
Normal file
39
app/Models/Medal.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Medal extends NexusModel
|
||||
{
|
||||
const GET_TYPE_EXCHANGE = 1;
|
||||
|
||||
const GET_TYPE_GRANT = 2;
|
||||
|
||||
public static $getTypeText = [
|
||||
self::GET_TYPE_EXCHANGE => ['text' => 'Exchange'],
|
||||
self::GET_TYPE_GRANT => ['text' => 'Grant'],
|
||||
];
|
||||
|
||||
protected $fillable = ['name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
public function getGetTypeTextAttribute($value): string
|
||||
{
|
||||
return self::$getTypeText[$this->get_type]['text'] ?? '';
|
||||
}
|
||||
|
||||
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_medals', 'medal_id', 'uid')->withTimestamps();
|
||||
}
|
||||
|
||||
public function valid_users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->users()->where(function ($query) {
|
||||
$query->whereNull('user_medals.expire_at')->orWhere('user_medals.expire_at', '>=', Carbon::now());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Middleware\Locale;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@@ -263,6 +264,20 @@ class User extends Authenticatable
|
||||
return $this->hasMany(HitAndRun::class, 'uid');
|
||||
}
|
||||
|
||||
public function medals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Medal::class, 'user_medals', 'uid', 'medal_id')
|
||||
->withPivot(['id', 'expire_at'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function valid_medals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->medals()->where(function ($query) {
|
||||
$query->whereNull('user_medals.expire_at')->orWhere('user_medals.expire_at', '>=', Carbon::now());
|
||||
});
|
||||
}
|
||||
|
||||
public function getAvatarAttribute($value)
|
||||
{
|
||||
if ($value) {
|
||||
|
||||
8
app/Models/UserMedal.php
Normal file
8
app/Models/UserMedal.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserMedal extends NexusModel
|
||||
{
|
||||
protected $fillable = ['uid', 'medal_id', 'expire_at'];
|
||||
}
|
||||
Reference in New Issue
Block a user