2022-08-12 07:56:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2022-11-06 11:28:22 +00:00
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
2022-12-27 16:25:22 +00:00
|
|
|
use Database\Factories\UserFactory;
|
|
|
|
use Eloquent;
|
|
|
|
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
2022-11-06 11:28:22 +00:00
|
|
|
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
2022-12-27 16:25:22 +00:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2022-08-12 07:56:56 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2022-11-26 13:52:30 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2022-11-18 09:16:30 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2022-12-27 16:25:22 +00:00
|
|
|
use Illuminate\Notifications\DatabaseNotification;
|
|
|
|
use Illuminate\Notifications\DatabaseNotificationCollection;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2022-12-27 16:25:22 +00:00
|
|
|
use Illuminate\Support\Carbon;
|
2022-11-06 11:28:22 +00:00
|
|
|
use Laravel\Sanctum\HasApiTokens;
|
2022-08-12 07:56:56 +00:00
|
|
|
|
2022-11-20 03:40:20 +00:00
|
|
|
/**
|
|
|
|
* App\Models\User
|
|
|
|
*
|
2022-11-20 12:32:49 +00:00
|
|
|
* @property int
|
|
|
|
* $id
|
|
|
|
* @property string
|
|
|
|
* $name
|
|
|
|
* @property string
|
|
|
|
* $email
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property Carbon|null
|
2022-11-20 12:32:49 +00:00
|
|
|
* $email_verified_at
|
|
|
|
* @property string|null
|
|
|
|
* $password
|
|
|
|
* @property float
|
|
|
|
* $balance
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property Carbon|null
|
2022-11-20 12:32:49 +00:00
|
|
|
* $banned_at 封禁时间
|
|
|
|
* @property string|null
|
|
|
|
* $banned_reason
|
|
|
|
* @property string|null
|
|
|
|
* $remember_token
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property Carbon|null
|
2022-11-20 12:32:49 +00:00
|
|
|
* $created_at
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property Carbon|null
|
2022-11-20 12:32:49 +00:00
|
|
|
* $updated_at
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property-read Collection|Host[]
|
2022-11-20 12:32:49 +00:00
|
|
|
* $hosts
|
|
|
|
* @property-read int|null
|
|
|
|
* $hosts_count
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property-read DatabaseNotificationCollection|DatabaseNotification[]
|
2022-11-20 12:32:49 +00:00
|
|
|
* $notifications
|
|
|
|
* @property-read int|null
|
|
|
|
* $notifications_count
|
2022-12-27 16:25:22 +00:00
|
|
|
* @property-read Collection|PersonalAccessToken[]
|
2022-11-20 12:32:49 +00:00
|
|
|
* $tokens
|
|
|
|
* @property-read int|null
|
|
|
|
* $tokens_count
|
2022-12-27 16:25:22 +00:00
|
|
|
* @method static CachedBuilder|User all($columns = [])
|
|
|
|
* @method static CachedBuilder|User avg($column)
|
|
|
|
* @method static CachedBuilder|User cache(array $tags = [])
|
|
|
|
* @method static CachedBuilder|User cachedValue(array $arguments, string $cacheKey)
|
|
|
|
* @method static CachedBuilder|User count($columns = '*')
|
|
|
|
* @method static CachedBuilder|User disableCache()
|
|
|
|
* @method static CachedBuilder|User disableModelCaching()
|
|
|
|
* @method static CachedBuilder|User exists()
|
|
|
|
* @method static UserFactory factory(...$parameters)
|
|
|
|
* @method static CachedBuilder|User flushCache(array $tags = [])
|
2022-11-20 12:32:49 +00:00
|
|
|
* @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User
|
|
|
|
* getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance)
|
2022-12-27 16:25:22 +00:00
|
|
|
* @method static CachedBuilder|User inRandomOrder($seed = '')
|
|
|
|
* @method static CachedBuilder|User insert(array $values)
|
|
|
|
* @method static CachedBuilder|User isCachable()
|
|
|
|
* @method static CachedBuilder|User max($column)
|
|
|
|
* @method static CachedBuilder|User min($column)
|
|
|
|
* @method static CachedBuilder|User newModelQuery()
|
|
|
|
* @method static CachedBuilder|User newQuery()
|
|
|
|
* @method static CachedBuilder|User query()
|
|
|
|
* @method static CachedBuilder|User sum($column)
|
|
|
|
* @method static CachedBuilder|User truncate()
|
|
|
|
* @method static CachedBuilder|User whereBalance($value)
|
|
|
|
* @method static CachedBuilder|User whereBannedAt($value)
|
|
|
|
* @method static CachedBuilder|User whereBannedReason($value)
|
|
|
|
* @method static CachedBuilder|User whereCreatedAt($value)
|
|
|
|
* @method static CachedBuilder|User whereEmail($value)
|
|
|
|
* @method static CachedBuilder|User whereEmailVerifiedAt($value)
|
|
|
|
* @method static CachedBuilder|User whereId($value)
|
|
|
|
* @method static CachedBuilder|User whereName($value)
|
|
|
|
* @method static CachedBuilder|User wherePassword($value)
|
|
|
|
* @method static CachedBuilder|User whereRememberToken($value)
|
|
|
|
* @method static CachedBuilder|User whereUpdatedAt($value)
|
|
|
|
* @method static CachedBuilder|User withCacheCooldownSeconds(?int $seconds = null)
|
|
|
|
* @mixin Eloquent
|
2022-11-20 03:40:20 +00:00
|
|
|
*/
|
2022-11-06 11:28:22 +00:00
|
|
|
class User extends Authenticatable
|
2022-08-12 07:56:56 +00:00
|
|
|
{
|
2022-11-06 11:28:22 +00:00
|
|
|
use HasApiTokens, HasFactory, Notifiable, Cachable;
|
2022-08-12 07:56:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
2022-11-06 11:28:22 +00:00
|
|
|
* @var array<int, string>
|
2022-08-12 07:56:56 +00:00
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2023-01-03 06:37:15 +00:00
|
|
|
'uuid',
|
2022-08-12 07:56:56 +00:00
|
|
|
'name',
|
|
|
|
'email',
|
|
|
|
'password',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2022-11-06 11:28:22 +00:00
|
|
|
* The attributes that should be hidden for serialization.
|
2022-08-12 07:56:56 +00:00
|
|
|
*
|
2022-11-06 11:28:22 +00:00
|
|
|
* @var array<int, string>
|
2022-08-12 07:56:56 +00:00
|
|
|
*/
|
|
|
|
protected $hidden = [
|
2022-11-06 11:28:22 +00:00
|
|
|
'password',
|
|
|
|
'remember_token',
|
2022-08-12 07:56:56 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'email_verified_at' => 'datetime',
|
2022-11-30 12:26:35 +00:00
|
|
|
'balance' => 'decimal:2',
|
2022-09-13 11:24:01 +00:00
|
|
|
'banned_at' => 'datetime',
|
2022-12-30 13:32:04 +00:00
|
|
|
'birthday_at' => 'date',
|
2022-08-12 07:56:56 +00:00
|
|
|
];
|
2022-08-30 09:20:45 +00:00
|
|
|
|
2022-11-19 04:38:26 +00:00
|
|
|
public function hosts(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(Host::class);
|
|
|
|
}
|
|
|
|
|
2022-11-26 13:52:30 +00:00
|
|
|
public function user_group(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(UserGroup::class);
|
|
|
|
}
|
|
|
|
|
2022-12-30 11:36:57 +00:00
|
|
|
public function scopeBirthday()
|
|
|
|
{
|
2023-01-02 14:26:44 +00:00
|
|
|
return $this->select(['id', 'name', 'birthday_at', 'email_md5', 'created_at'])->whereMonth('birthday_at', now()->month)
|
2022-12-30 11:36:57 +00:00
|
|
|
->whereDay('birthday_at', now()->day);
|
|
|
|
}
|
2023-01-03 06:37:15 +00:00
|
|
|
|
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::creating(function (self $user) {
|
|
|
|
$user->email_md5 = md5($user->email);
|
|
|
|
});
|
|
|
|
|
|
|
|
static::updating(function ($model) {
|
|
|
|
if ($model->isDirty('banned_at')) {
|
|
|
|
if ($model->banned_at) {
|
|
|
|
$model->tokens()->delete();
|
|
|
|
$model->hosts()->update(['status' => 'suspended', 'suspended_at' => now()]);
|
|
|
|
} else {
|
|
|
|
$model->hosts()->update(['status' => 'stopped']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-08-12 07:56:56 +00:00
|
|
|
}
|