增加 用户 UUID
修复 邮箱 md5 为 null 的问题
This commit is contained in:
parent
4fed8eb395
commit
796fd6fce2
@ -101,6 +101,7 @@ class User extends Authenticatable
|
|||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'uuid',
|
||||||
'name',
|
'name',
|
||||||
'email',
|
'email',
|
||||||
'password',
|
'password',
|
||||||
@ -123,29 +124,6 @@ class User extends Authenticatable
|
|||||||
'birthday_at' => 'date',
|
'birthday_at' => 'date',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected static function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
static::updating(function ($model) {
|
|
||||||
|
|
||||||
// balance 四舍五入
|
|
||||||
|
|
||||||
// if ($model->isDirty('balance')) {
|
|
||||||
// $model->balance = round($model->balance, 2, PHP_ROUND_HALF_DOWN);
|
|
||||||
// }
|
|
||||||
|
|
||||||
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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hosts(): HasMany
|
public function hosts(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Host::class);
|
return $this->hasMany(Host::class);
|
||||||
@ -161,4 +139,24 @@ public function scopeBirthday()
|
|||||||
return $this->select(['id', 'name', 'birthday_at', 'email_md5', 'created_at'])->whereMonth('birthday_at', now()->month)
|
return $this->select(['id', 'name', 'birthday_at', 'email_md5', 'created_at'])->whereMonth('birthday_at', now()->month)
|
||||||
->whereDay('birthday_at', now()->day);
|
->whereDay('birthday_at', now()->day);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->uuid()->unique()->after('id')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
$count = User::count();
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
User::chunk(100, function ($users) use (&$i, $count) {
|
||||||
|
foreach ($users as $user) {
|
||||||
|
echo sprintf('Updating %d/%d', ++$i, $count) . PHP_EOL;
|
||||||
|
|
||||||
|
$user->email_md5 = md5($user->email);
|
||||||
|
$user->uuid = Str::uuid();
|
||||||
|
$user->saveQuietly();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('uuid');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user