初始化本地仓库
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace resource\database\seeds;
|
||||
|
||||
use app\model\system\Admin;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AdminSeeder extends Seeder
|
||||
{
|
||||
private ?array $adminParams = null;
|
||||
|
||||
/**
|
||||
* 设置管理员参数
|
||||
*/
|
||||
public function setAdminParams(array $params): void
|
||||
{
|
||||
$this->adminParams = $params;
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
// 清空表
|
||||
Admin::truncate();
|
||||
|
||||
// 检查是否已存在管理员
|
||||
$existingAdmin = Admin::find(1);
|
||||
if ($existingAdmin) {
|
||||
// 更新现有管理员
|
||||
if ($this->adminParams) {
|
||||
$existingAdmin->user_name = $this->adminParams['username'];
|
||||
$existingAdmin->password = password_hash($this->adminParams['password'], PASSWORD_DEFAULT);
|
||||
$existingAdmin->real_name = '超级管理员';
|
||||
$existingAdmin->nick_name = '超级管理员';
|
||||
$existingAdmin->is_super = 1;
|
||||
$existingAdmin->enabled = 1;
|
||||
$existingAdmin->email = $this->adminParams['email'] ?? 'admin@example.com';
|
||||
$existingAdmin->save();
|
||||
}
|
||||
} else {
|
||||
// 创建新管理员
|
||||
$username = $this->adminParams['username'] ?? 'admin';
|
||||
$password = $this->adminParams['password'] ?? '123456';
|
||||
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
Admin::create([
|
||||
'id' => 1,
|
||||
'user_name' => $username,
|
||||
'real_name' => '超级管理员',
|
||||
'nick_name' => '超级管理员',
|
||||
'password' => $hashedPassword,
|
||||
'email' => 'admin@example.com',
|
||||
'avatar' => '',
|
||||
'is_super' => 1,
|
||||
'enabled' => 1,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* 系统配置种子
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace resource\database\seeds;
|
||||
|
||||
use app\model\system\Config;
|
||||
use core\uuid\Snowflake;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ConfigSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// 清空表
|
||||
Config::truncate();
|
||||
|
||||
$configs = include base_path('resource/data/config/config.php');
|
||||
|
||||
// 插入配置项
|
||||
foreach ($configs as $config) {
|
||||
Config::create([
|
||||
'id'=>Snowflake::generate(),
|
||||
'group_code' => $config['group_code'] ?? '',
|
||||
'code' => $config['code'] ?? '',
|
||||
'name' => $config['name'] ?? '',
|
||||
'content' => is_array($config['content'] ?? '') ? json_encode($config['content'], JSON_UNESCAPED_UNICODE) : ($config['content'] ?? ''),
|
||||
'is_sys' => $config['is_sys'] ?? 0,
|
||||
'enabled' => $config['enabled'] ?? 1,
|
||||
'created_at' => $config['created_at'] ?? time(),
|
||||
'updated_at' => $config['updated_at'] ?? time(),
|
||||
'deleted_at' => $config['deleted_at'] ?? null,
|
||||
'remark' => $config['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* 数据字典种子
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace resource\database\seeds;
|
||||
|
||||
use app\model\dict\Dict;
|
||||
use app\model\dict\DictItem;
|
||||
use core\uuid\Snowflake;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DictSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// 清空表
|
||||
DictItem::truncate();
|
||||
Dict::truncate();
|
||||
|
||||
$dict = include base_path('resource/data/dict/dict.php');
|
||||
|
||||
// 插入字典组
|
||||
foreach ($dict as $group) {
|
||||
$dictId=Snowflake::generate();
|
||||
Dict::create([
|
||||
'id' => $dictId,
|
||||
'group_code' => $group['group_code'] ?? '',
|
||||
'name' => $group['name'] ?? '',
|
||||
'code' => $group['code'] ?? '',
|
||||
'sort' => $group['sort'] ?? 0,
|
||||
'data_type' => $group['data_type'] ?? 0,
|
||||
'description' => $group['description'] ?? '',
|
||||
'enabled' => $group['enabled'] ?? 1,
|
||||
'created_by' => 1,
|
||||
'updated_by' => 1,
|
||||
]);
|
||||
|
||||
// 插入字典项
|
||||
if (!empty($group['items'])) {
|
||||
foreach ($group['items'] as $item) {
|
||||
DictItem::create([
|
||||
'id' => Snowflake::generate(),
|
||||
'dict_id' => $dictId,
|
||||
'label' => $item['label'] ?? '',
|
||||
'value' => $item['value'] ?? '',
|
||||
'code' => $item['code'] ?? '',
|
||||
'sort' => $item['sort'] ?? 0,
|
||||
'enabled' => $item['enabled'] ?? 1,
|
||||
'created_by' => 1,
|
||||
'updated_by' => 1,
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace resource\database\seeds;
|
||||
|
||||
use app\model\member\MemberLevel;
|
||||
use core\uuid\Snowflake;
|
||||
use Illuminate\Database\Seeder;
|
||||
use support\Db;
|
||||
|
||||
class MemberLevelSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$data = [
|
||||
[
|
||||
'name' => '黄金',
|
||||
'level' => 1,
|
||||
'min_points' => 0,
|
||||
'max_points' => 99,
|
||||
'discount' => 0.00,
|
||||
'icon' => 'ant-design:account-book-filled',
|
||||
'color' => null,
|
||||
'description' => '',
|
||||
'enabled' => 1,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
],
|
||||
[
|
||||
'name' => '铂金',
|
||||
'level' => 2,
|
||||
'min_points' => 100,
|
||||
'max_points' => 999,
|
||||
'discount' => 9.80,
|
||||
'icon' => 'ant-design:android-outlined',
|
||||
'color' => null,
|
||||
'description' => '',
|
||||
'enabled' => 1,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
],
|
||||
[
|
||||
'name' => '钻石',
|
||||
'level' => 3,
|
||||
'min_points' => 1000,
|
||||
'max_points' => 4999,
|
||||
'discount' => 9.00,
|
||||
'icon' => 'ant-design:ant-cloud-outlined',
|
||||
'color' => null,
|
||||
'description' => '',
|
||||
'enabled' => 1,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
],
|
||||
[
|
||||
'name' => '星耀',
|
||||
'level' => 4,
|
||||
'min_points' => 5000,
|
||||
'max_points' => 9999,
|
||||
'discount' => 8.00,
|
||||
'icon' => 'ant-design:ant-cloud-outlined',
|
||||
'color' => null,
|
||||
'description' => '',
|
||||
'enabled' => 1,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
],
|
||||
[
|
||||
'name' => '王者',
|
||||
'level' => 5,
|
||||
'min_points' => 10000,
|
||||
'max_points' => 9999999,
|
||||
'discount' => 7.00,
|
||||
'icon' => 'ant-design:ant-cloud-outlined',
|
||||
'color' => null,
|
||||
'description' => '',
|
||||
'enabled' => 1,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
],
|
||||
];
|
||||
|
||||
// 清空表数据
|
||||
Db::table('member_level')->truncate();
|
||||
// 插入数据
|
||||
foreach ($data as $item) {
|
||||
$item['id'] = Snowflake::generate();
|
||||
MemberLevel::create($item);
|
||||
}
|
||||
echo "Member level seed completed successfully!\n";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* 菜单数据种子
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace resource\database\seeds;
|
||||
|
||||
use app\model\system\Menu;
|
||||
use core\uuid\Snowflake;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
|
||||
class MenuSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// 清空表
|
||||
Menu::truncate();
|
||||
|
||||
$menus = include base_path('resource/data/menu/admin.php');
|
||||
|
||||
// 插入菜单数据
|
||||
foreach ($menus as $menu) {
|
||||
$this->insertMenu($menu, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归插入菜单
|
||||
*/
|
||||
private function insertMenu(array $menu, int|string $pid): void
|
||||
{
|
||||
$menuModel = new Menu();
|
||||
$menuModel->id = Snowflake::generate();
|
||||
$menuModel->pid = $pid;
|
||||
$menuModel->title = $menu['title'] ?? '';
|
||||
$menuModel->app = $menu['app'] ?? 'admin';
|
||||
$menuModel->code = $menu['code'] ?? '';
|
||||
$menuModel->icon = $menu['icon'] ?? '';
|
||||
$menuModel->sort = $menu['sort'] ?? 0;
|
||||
$menuModel->type = $menu['type'] ?? 1;
|
||||
$menuModel->is_show = $menu['is_show'] ?? 1;
|
||||
$menuModel->is_link = $menu['is_link'] ?? 0;
|
||||
$menuModel->is_cache = $menu['is_cache'] ?? 0;
|
||||
$menuModel->path = $menu['path'] ?? '';
|
||||
$menuModel->component = $menu['component'] ?? '';
|
||||
$menuModel->redirect = $menu['redirect'] ?? '';
|
||||
$menuModel->enabled = $menu['enabled'] ?? 1;
|
||||
$menuModel->save();
|
||||
|
||||
// 递归插入子菜单
|
||||
if (!empty($menu['children'])) {
|
||||
foreach ($menu['children'] as $child) {
|
||||
$this->insertMenu($child, $menuModel->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* 前端菜单种子
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace resource\database\seeds;
|
||||
|
||||
use app\model\web\Menu;
|
||||
use core\uuid\Snowflake;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class WebMenuSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// 清空表
|
||||
Menu::truncate();
|
||||
|
||||
$menus = include base_path('resource/data/menu/web.php');
|
||||
|
||||
// 插入菜单数据
|
||||
foreach ($menus as $menu) {
|
||||
$this->insertMenu($menu, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归插入菜单
|
||||
*/
|
||||
private function insertMenu(array $menu, int|string $pid): void
|
||||
{
|
||||
$menuModel = new Menu();
|
||||
$menuModel->id = Snowflake::generate();
|
||||
$menuModel->pid = $pid;
|
||||
$menuModel->app = $menu['app'] ?? 'web';
|
||||
$menuModel->category = $menu['category'] ?? 1;
|
||||
$menuModel->source = $menu['source'] ?? 'system';
|
||||
$menuModel->code = $menu['code'] ?? '';
|
||||
$menuModel->name = $menu['name'] ?? '';
|
||||
$menuModel->url = $menu['url'] ?? '';
|
||||
$menuModel->icon = $menu['icon'] ?? '';
|
||||
$menuModel->level = $menu['level'] ?? 1;
|
||||
$menuModel->type = $menu['type'] ?? 1;
|
||||
$menuModel->sort = $menu['sort'] ?? 0;
|
||||
$menuModel->target = $menu['target'] ?? 1;
|
||||
$menuModel->is_show = $menu['is_show'] ?? 1;
|
||||
$menuModel->enabled = $menu['enabled'] ?? 1;
|
||||
$menuModel->created_at = $menu['created_at'] ?? time();
|
||||
$menuModel->updated_at = $menu['updated_at'] ?? time();
|
||||
$menuModel->deleted_at = $menu['deleted_at'] ?? null;
|
||||
$menuModel->save();
|
||||
|
||||
// 递归插入子菜单
|
||||
if (!empty($menu['children'])) {
|
||||
foreach ($menu['children'] as $child) {
|
||||
$this->insertMenu($child, $menuModel->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user