generated from panliang/owl-admin-starter
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Admin\Services\PartyUserService;
|
|
use App\Enums\CheckStatus;
|
|
use App\Models\PartyUser;
|
|
use App\Models\UserScore;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\UserScore>
|
|
*/
|
|
class UserScoreFactory extends Factory
|
|
{
|
|
protected $model = UserScore::class;
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$type = UserScore::getTypeList()->random();
|
|
$user = PartyUser::query()->inRandomOrder()->first();
|
|
$time = $this->faker->dateTimeBetween('-3 years', 'now');
|
|
return [
|
|
'type_id' => $type->id,
|
|
'cate_id' => $user->cate_id,
|
|
'user_id' => $user->id,
|
|
'title' => $this->faker->sentence,
|
|
'content' => $this->faker->paragraph,
|
|
'images' => ['https://via.placeholder.com/100x100.png', 'https://via.placeholder.com/100x100.png'],
|
|
'file' => 'https://via.placeholder.com/100x100.png',
|
|
'check_status' => CheckStatus::Success,
|
|
'check_user_id' => 1,
|
|
'check_at' => $time,
|
|
'score' => $this->faker->numberBetween(10, 100),
|
|
'created_at' => $time,
|
|
];
|
|
}
|
|
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (UserScore $userScore) {
|
|
PartyUserService::make()->incrementScore($userScore->user, $userScore->type->key, $userScore->score);
|
|
});
|
|
}
|
|
}
|