98 lines
4.1 KiB
PHP
98 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\User;
|
|
use App\Models\Administration;
|
|
use App\Models\AddCard;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MockDataSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Clear old data to avoid duplicates when running again
|
|
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
|
|
User::truncate();
|
|
Administration::truncate();
|
|
AddCard::truncate();
|
|
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
|
|
|
// The default password is now set to 1234@Dcba according to the design requirements
|
|
$password = md5('1234@Dcba');
|
|
$depts = config('constants.DEPARTMENTS');
|
|
|
|
// 1. CREATE USERS
|
|
// Admins
|
|
User::create([
|
|
'msnv' => 9999,
|
|
'name' => 'System Admin',
|
|
'mail' => 'admin@runsystem.net',
|
|
'pass' => $password,
|
|
'departments' => $depts[0],
|
|
'role' => config('constants.ROLE_ADMIN'),
|
|
'status' => config('constants.STATUS_ACTIVE'),
|
|
'card' => 0,
|
|
'flag_send' => config('constants.FLAG_SEND_ENABLED'),
|
|
'first_login' => config('constants.FIRST_LOGIN_FALSE'),
|
|
]);
|
|
|
|
User::create([
|
|
'msnv' => 9998,
|
|
'name' => 'Second Admin',
|
|
'mail' => 'admin2@runsystem.net',
|
|
'pass' => $password,
|
|
'departments' => $depts[0],
|
|
'role' => config('constants.ROLE_ADMIN'),
|
|
'status' => config('constants.STATUS_ACTIVE'),
|
|
'card' => 0,
|
|
'flag_send' => config('constants.FLAG_SEND_ENABLED'),
|
|
'first_login' => config('constants.FIRST_LOGIN_FALSE'),
|
|
]);
|
|
|
|
// Active Users (Initialize with specific users needed for logs/transactions)
|
|
$users = [
|
|
['msnv' => 1001, 'name' => 'Nguyễn Văn A', 'mail' => 'nguyenvana@runsystem.net', 'card' => 10, 'flag' => config('constants.FLAG_SEND_ENABLED'), 'first_login' => config('constants.FIRST_LOGIN_FALSE')],
|
|
['msnv' => 1002, 'name' => 'Trần Thị Ngọc', 'mail' => 'tranthingoc@runsystem.net', 'card' => 3, 'flag' => config('constants.FLAG_SEND_ENABLED'), 'first_login' => config('constants.FIRST_LOGIN_FALSE')],
|
|
['msnv' => 1003, 'name' => 'Lê Kim Thư', 'mail' => 'lekiemthu@runsystem.net', 'card' => 6, 'flag' => config('constants.FLAG_SEND_ENABLED'), 'first_login' => config('constants.FIRST_LOGIN_TRUE')], // First-time login
|
|
['msnv' => 1004, 'name' => 'Phòng Nhân Sự', 'mail' => 'phongnhansu@runsystem.net', 'card' => 0, 'flag' => config('constants.FLAG_SEND_DISABLED'), 'first_login' => config('constants.FIRST_LOGIN_FALSE')], // Disabled sending permission
|
|
['msnv' => 1005, 'name' => 'Bản Giang', 'mail' => 'bangiang@runsystem.net', 'card' => 36, 'flag' => config('constants.FLAG_SEND_ENABLED'), 'first_login' => config('constants.FIRST_LOGIN_FALSE')],
|
|
];
|
|
|
|
foreach ($users as $idx => $u) {
|
|
User::create([
|
|
'msnv' => $u['msnv'],
|
|
'name' => $u['name'],
|
|
'mail' => $u['mail'],
|
|
'pass' => $password,
|
|
'departments' => $depts[$idx % count($depts)],
|
|
'role' => config('constants.ROLE_MEMBER'),
|
|
'status' => config('constants.STATUS_ACTIVE'),
|
|
'card' => $u['card'],
|
|
'flag_send' => $u['flag'],
|
|
'first_login' => $u['first_login'],
|
|
]);
|
|
}
|
|
|
|
// Inactive User
|
|
User::create([
|
|
'msnv' => 9997,
|
|
'name' => 'Nghi Duy',
|
|
'mail' => 'nghiduy@runsystem.net',
|
|
'pass' => $password,
|
|
'departments' => $depts[1],
|
|
'role' => config('constants.ROLE_MEMBER'),
|
|
'status' => config('constants.STATUS_INACTIVE'),
|
|
'card' => 0,
|
|
'flag_send' => config('constants.FLAG_SEND_DISABLED'),
|
|
'first_login' => config('constants.FIRST_LOGIN_FALSE'),
|
|
]);
|
|
}
|
|
}
|