first commit
This commit is contained in:
60
app/Models/Auth/Admin.php
Normal file
60
app/Models/Auth/Admin.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Traits\ModelTrait;
|
||||
|
||||
class Admin extends Authenticatable implements JWTSubject {
|
||||
use Notifiable, ModelTrait;
|
||||
|
||||
protected $table = 'auth_admins';
|
||||
protected $primaryKey = 'uid';
|
||||
protected $fillable = ['username', 'nickname', 'email', 'mobile', 'password', 'department_id', 'status', 'last_login_at', 'last_login_ip'];
|
||||
protected $hidden = ['password', 'deleted_at'];
|
||||
protected $with = ['department', 'roles'];
|
||||
|
||||
// Rest omitted for brevity
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier() {
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function password() : Attribute {
|
||||
return new Attribute(
|
||||
set: fn ($value) => Hash::make($value),
|
||||
);
|
||||
}
|
||||
|
||||
public function department(){
|
||||
return $this->belongsTo(Department::class, 'department_id', 'id');
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Role::class, 'auth_admins_roles', 'uid', 'role_id');
|
||||
}
|
||||
}
|
||||
27
app/Models/Auth/Department.php
Normal file
27
app/Models/Auth/Department.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
class Department extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_departments';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'parent_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function members(){
|
||||
return $this->hasMany(Admin::class, 'department_id', 'uid');
|
||||
}
|
||||
}
|
||||
39
app/Models/Auth/Permission.php
Normal file
39
app/Models/Auth/Permission.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Permission extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_permissions';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'hiddenBreadcrumb', 'hidden', 'affix', 'color', 'fullpage', 'icon', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function meta() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => [
|
||||
'id' => $data['id'],
|
||||
'parent_id' => $data['parent_id'],
|
||||
'title' => $data['title'],
|
||||
'hiddenBreadcrumb' => $data['hiddenBreadcrumb'],
|
||||
'hidden' => $data['hidden'],
|
||||
'affix' => $data['affix'],
|
||||
'color' => $data['color'],
|
||||
'fullpage' => $data['fullpage'],
|
||||
'icon' => isset($data['icon']) && $data['icon'] ? $data['icon'] : 'el-icon-document',
|
||||
// 'icon' => isset($data['icon']) && $data['icon'] ? $data['icon'] : 'AIconFileTextOutlined',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Role::class, 'auth_roles_permissions', 'permission_id', 'role_id');
|
||||
}
|
||||
}
|
||||
23
app/Models/Auth/Role.php
Normal file
23
app/Models/Auth/Role.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
class Role extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'auth_roles';
|
||||
protected $fillable = ['title', 'name', 'data_range', 'sort', 'status', 'description'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function admins(){
|
||||
return $this->belongsToMany(Admin::class, 'auth_admins_roles', 'role_id', 'uid');
|
||||
}
|
||||
public function permissions(){
|
||||
return $this->belongsToMany(Permission::class, 'auth_roles_permissions', 'role_id', 'permission_id');
|
||||
}
|
||||
}
|
||||
46
app/Models/BaseModel.php
Normal file
46
app/Models/BaseModel.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class BaseModel extends Model {
|
||||
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
protected function serializeDate($data){
|
||||
return $data->timezone('Asia/Shanghai')->format('Y-m-d H:i:s');
|
||||
}
|
||||
/**
|
||||
* 过滤移除非当前表的字段参数
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setFilterFields(array $params) : array {
|
||||
$fields = Schema::getColumnListing($this->getTable());
|
||||
foreach ($params as $key => $param) {
|
||||
if ( !in_array($key, $fields) ) unset($params[$key]);
|
||||
}
|
||||
// 同时过滤时间戳字段【时间戳只允许自动更改,不允许手动设置】
|
||||
if ( $this->timestamps === true && isset($params[self::CREATED_AT]) ) unset($params[self::CREATED_AT]);
|
||||
if ( $this->timestamps === true && isset($params[self::UPDATED_AT]) ) unset($params[self::UPDATED_AT]);
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
16
app/Models/System/Area.php
Normal file
16
app/Models/System/Area.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
class Area extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_areas';
|
||||
protected $fillable = ['title', 'parent_id', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
}
|
||||
39
app/Models/System/Client.php
Normal file
39
app/Models/System/Client.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Client extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_client';
|
||||
protected $fillable = ['title', 'app_id', 'secret', 'redirect', 'status'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'status' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function appId() : Attribute {
|
||||
return Attribute::make(
|
||||
set: function (mixed $value, array $data){
|
||||
return uniqid();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function secret() : Attribute {
|
||||
return Attribute::make(
|
||||
set: function (mixed $value, array $data){
|
||||
return md5(uniqid());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
27
app/Models/System/ClientMenu.php
Normal file
27
app/Models/System/ClientMenu.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class ClientMenu extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_client_menu';
|
||||
protected $with = ['client'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'status' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
public function client(){
|
||||
return $this->belongsTo(Client::class, 'client_id', 'id');
|
||||
}
|
||||
}
|
||||
45
app/Models/System/Config.php
Normal file
45
app/Models/System/Config.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Config extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_configs';
|
||||
protected $fillable = ['values', 'name', 'title', 'group', 'remark', 'type', 'status', 'sort'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'option' => 'json',
|
||||
];
|
||||
}
|
||||
|
||||
public function options(): Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => [
|
||||
'placeholder' => $data['title'],
|
||||
'options' => $data['option'] ? json_decode($data['option'], true) : [],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function label() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => $data['title'],
|
||||
);
|
||||
}
|
||||
|
||||
public function prop() : Attribute {
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => $data['title'],
|
||||
);
|
||||
}
|
||||
}
|
||||
24
app/Models/System/Crontab.php
Normal file
24
app/Models/System/Crontab.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Crontab extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_crontabs';
|
||||
protected $fillable = [];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'status' => 'integer',
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Models/System/Dict.php
Normal file
22
app/Models/System/Dict.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Dict extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_dicts';
|
||||
protected $fillable = ['title', 'values', 'group_id', 'group_name', 'sort', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function group(){
|
||||
return $this->belongsTo(DictGroup::class, 'group_id', 'id');
|
||||
}
|
||||
}
|
||||
25
app/Models/System/DictGroup.php
Normal file
25
app/Models/System/DictGroup.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
class DictGroup extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_dict_groups';
|
||||
protected $fillable = ['title', 'name', 'parent_id', 'sort', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
protected function casts(): array {
|
||||
return [
|
||||
'parent_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'sort' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
22
app/Models/System/Log.php
Normal file
22
app/Models/System/Log.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use App\Models\Auth\Admin;
|
||||
|
||||
class Log extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_logs';
|
||||
protected $fillable = ['title', 'name', 'url', 'method', 'client_ip', 'browser', 'user_id', 'data', 'remark', 'status'];
|
||||
protected $hidden = ['deleted_at'];
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(Admin::class, 'user_id', 'uid');
|
||||
}
|
||||
}
|
||||
13
app/Models/System/Modules.php
Normal file
13
app/Models/System/Modules.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
class Modules extends \App\Models\BaseModel {
|
||||
//
|
||||
}
|
||||
31
app/Models/System/Tasks.php
Normal file
31
app/Models/System/Tasks.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Auth\Admin;
|
||||
|
||||
class Tasks extends \App\Models\BaseModel {
|
||||
|
||||
protected $table = 'system_tasks';
|
||||
protected $fillable = [];
|
||||
protected $hidden = ['deleted_at'];
|
||||
protected $append = ['url'];
|
||||
|
||||
public function url(): Attribute{
|
||||
return Attribute::make(
|
||||
get: fn (mixed $value, array $data) => Storage::disk('public')->url($data['file']),
|
||||
);
|
||||
}
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(Admin::class, 'user_id', 'uid');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user