初始化项目
This commit is contained in:
53
app/Models/Auth/Department.php
Normal file
53
app/Models/Auth/Department.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'auth_departments';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'parent_id',
|
||||
'leader',
|
||||
'phone',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取子部门
|
||||
*/
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(Department::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父部门
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门下的用户
|
||||
*/
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'department_id');
|
||||
}
|
||||
}
|
||||
58
app/Models/Auth/Permission.php
Normal file
58
app/Models/Auth/Permission.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'auth_permissions';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'type',
|
||||
'parent_id',
|
||||
'route',
|
||||
'component',
|
||||
'meta',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'meta' => 'array',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联角色
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'auth_role_permission', 'permission_id', 'role_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子权限
|
||||
*/
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Permission::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父权限
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
45
app/Models/Auth/Role.php
Normal file
45
app/Models/Auth/Role.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'auth_roles';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'description',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联权限
|
||||
*/
|
||||
public function permissions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Permission::class, 'auth_role_permission', 'role_id', 'permission_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联用户
|
||||
*/
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'auth_user_role', 'role_id', 'user_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
109
app/Models/Auth/User.php
Normal file
109
app/Models/Auth/User.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'auth_users';
|
||||
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'password',
|
||||
'real_name',
|
||||
'email',
|
||||
'phone',
|
||||
'department_id',
|
||||
'avatar',
|
||||
'status',
|
||||
'last_login_at',
|
||||
'last_login_ip',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => 'integer',
|
||||
'department_id' => 'integer',
|
||||
'last_login_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联部门
|
||||
*/
|
||||
public function department(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联角色
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'auth_user_role', 'user_id', 'role_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的所有权限
|
||||
*/
|
||||
public function permissions()
|
||||
{
|
||||
return $this->roles()->with('permissions');
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否有指定权限
|
||||
*/
|
||||
public function hasPermission(string $permissionCode): bool
|
||||
{
|
||||
foreach ($this->roles as $role) {
|
||||
foreach ($role->permissions as $permission) {
|
||||
if ($permission->code === $permissionCode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否有指定角色
|
||||
*/
|
||||
public function hasRole(string $roleCode): bool
|
||||
{
|
||||
return $this->roles()->where('code', $roleCode)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 JWT 标识符
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 JWT 自定义声明
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
46
app/Models/System/City.php
Normal file
46
app/Models/System/City.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class City extends Model
|
||||
{
|
||||
protected $table = 'system_cities';
|
||||
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'name',
|
||||
'code',
|
||||
'pinyin',
|
||||
'pinyin_short',
|
||||
'level',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'level' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(City::class, 'parent_id')->orderBy('sort');
|
||||
}
|
||||
|
||||
public function activeChildren(): HasMany
|
||||
{
|
||||
return $this->hasMany(City::class, 'parent_id')
|
||||
->where('status', true)
|
||||
->orderBy('sort');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(City::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
47
app/Models/System/Config.php
Normal file
47
app/Models/System/Config.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Config extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'system_configs';
|
||||
|
||||
protected $fillable = [
|
||||
'group',
|
||||
'key',
|
||||
'name',
|
||||
'type',
|
||||
'options',
|
||||
'value',
|
||||
'default_value',
|
||||
'description',
|
||||
'validation',
|
||||
'sort',
|
||||
'is_system',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'options' => 'array',
|
||||
'is_system' => 'boolean',
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
public function getOptionsAttribute($value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
return json_decode($value, true) ?? [];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function setOptionsAttribute($value)
|
||||
{
|
||||
$this->attributes['options'] = is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
}
|
||||
38
app/Models/System/Dictionary.php
Normal file
38
app/Models/System/Dictionary.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Dictionary extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'system_dictionaries';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'description',
|
||||
'status',
|
||||
'sort',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(DictionaryItem::class, 'dictionary_id')->orderBy('sort');
|
||||
}
|
||||
|
||||
public function activeItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(DictionaryItem::class, 'dictionary_id')
|
||||
->where('status', true)
|
||||
->orderBy('sort');
|
||||
}
|
||||
}
|
||||
32
app/Models/System/DictionaryItem.php
Normal file
32
app/Models/System/DictionaryItem.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DictionaryItem extends Model
|
||||
{
|
||||
protected $table = 'system_dictionary_items';
|
||||
|
||||
protected $fillable = [
|
||||
'dictionary_id',
|
||||
'label',
|
||||
'value',
|
||||
'color',
|
||||
'description',
|
||||
'is_default',
|
||||
'status',
|
||||
'sort',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_default' => 'boolean',
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
public function dictionary(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Dictionary::class, 'dictionary_id');
|
||||
}
|
||||
}
|
||||
39
app/Models/System/Log.php
Normal file
39
app/Models/System/Log.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
protected $table = 'system_logs';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'username',
|
||||
'module',
|
||||
'action',
|
||||
'method',
|
||||
'url',
|
||||
'ip',
|
||||
'user_agent',
|
||||
'params',
|
||||
'result',
|
||||
'status_code',
|
||||
'status',
|
||||
'error_message',
|
||||
'execution_time',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'params' => 'array',
|
||||
'execution_time' => 'integer',
|
||||
'status_code' => 'integer',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Auth\User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
42
app/Models/System/Task.php
Normal file
42
app/Models/System/Task.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Task extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'system_tasks';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'command',
|
||||
'description',
|
||||
'type',
|
||||
'expression',
|
||||
'timezone',
|
||||
'is_active',
|
||||
'run_in_background',
|
||||
'without_overlapping',
|
||||
'only_one',
|
||||
'last_run_at',
|
||||
'next_run_at',
|
||||
'last_output',
|
||||
'run_count',
|
||||
'failed_count',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'run_in_background' => 'boolean',
|
||||
'without_overlapping' => 'boolean',
|
||||
'only_one' => 'boolean',
|
||||
'last_run_at' => 'datetime',
|
||||
'next_run_at' => 'datetime',
|
||||
'run_count' => 'integer',
|
||||
'failed_count' => 'integer',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user