2026-01-26 14:59:24 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Modules\Core\Services;
|
|
|
|
|
|
|
|
|
|
use App\Modules\Core\Contracts\CoreServiceInterface;
|
|
|
|
|
use App\Modules\Core\Models\User;
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
class CoreService implements CoreServiceInterface
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get multiple users by their IDs.
|
|
|
|
|
*
|
|
|
|
|
* @param array $ids
|
|
|
|
|
* @return Collection
|
|
|
|
|
*/
|
|
|
|
|
public function getUsersByIds(array $ids): Collection
|
|
|
|
|
{
|
|
|
|
|
return User::whereIn('id', $ids)->get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a specific user by ID.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return object|null
|
|
|
|
|
*/
|
|
|
|
|
public function getUser(int $id): ?object
|
|
|
|
|
{
|
|
|
|
|
return User::find($id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all users.
|
|
|
|
|
*
|
|
|
|
|
* @return Collection
|
|
|
|
|
*/
|
|
|
|
|
public function getAllUsers(): Collection
|
|
|
|
|
{
|
|
|
|
|
return User::all();
|
|
|
|
|
}
|
2026-01-27 08:59:45 +08:00
|
|
|
|
|
|
|
|
public function ensureSystemUserExists()
|
|
|
|
|
{
|
|
|
|
|
$user = User::first();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
$user = User::create([
|
|
|
|
|
'name' => '系統管理員',
|
|
|
|
|
'email' => 'admin@example.com',
|
|
|
|
|
'password' => bcrypt('password'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
return $user;
|
|
|
|
|
}
|
2026-01-26 14:59:24 +08:00
|
|
|
}
|