first commit

This commit is contained in:
liu
2026-07-13 15:23:29 +08:00
commit 50885a98c8
473 changed files with 33772 additions and 0 deletions
@@ -0,0 +1,40 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* 首页轮播图模型
*/
class SysCarouselModel extends Model
{
protected $table = 'sys_carousel';
protected $casts = [
'status' => 'int',
'sort' => 'int',
'image_id' => 'array',
];
protected $fillable = [
'title',
'image_id',
'link',
'status',
'sort',
];
protected $with = ['image'];
/**
* 关联图片
* @return HasOne
*/
public function image(): HasOne
{
return $this->hasOne(SysFileModel::class, 'id', 'image_id');
}
}
@@ -0,0 +1,38 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 字典数据模型
*/
class SysDictItemModel extends Model
{
protected $table = 'sys_dict_item';
protected $fillable = [
'dict_id',
'label',
'value',
'color',
'status',
'sort',
];
protected $casts = [
'dict_id' => 'integer',
'status' => 'integer',
'sort' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* 字典项关联字典表
*/
public function dict(): BelongsTo
{
return $this->belongsTo(SysDictModel::class, 'dict_id', 'id');
}
}
@@ -0,0 +1,70 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* 字典类型模型
*/
class SysDictModel extends Model
{
protected $table = 'sys_dict';
protected $fillable = [
'name',
'code',
'describe',
'status',
'sort',
];
protected $casts = [
'status' => 'integer',
'sort' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* 关联字典子项
*/
public function dictItems(): HasMany
{
return $this->hasMany(SysDictItemModel::class, 'dict_id', 'id')
->orderBy('sort')
->orderBy('id');
}
/**
* 获取所有字典及其子项
* @return array
*/
public static function getAllDictWithItems(): array
{
return static::with('dictItems')
->where('status', 0)
->orderBy('sort')
->orderBy('id')
->get()
->map(function ($dict) {
return [
'id' => $dict->id,
'name' => $dict->name,
'code' => $dict->code,
'describe' => $dict->describe,
'status' => $dict->status,
'sort' => $dict->sort,
'dict_items' => $dict->dictItems->filter(fn($item) => $item->status === 0)->map(function ($item) {
return [
'id' => $item->id,
'label' => $item->label,
'value' => $item->value,
'color' => $item->color,
'sort' => $item->sort,
];
})->values()->toArray(),
];
})->toArray();
}
}
@@ -0,0 +1,62 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class FileGroup
*/
class SysFileGroupModel extends Model
{
protected $table = 'sys_file_group';
protected $primaryKey = 'id';
protected $casts = [
'sort' => 'int',
'parent_id' => 'int'
];
protected $fillable = [
'name',
'parent_id',
'sort',
'describe',
];
protected $appends = ['countFiles'];
/**
* 获取父级分组
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id', 'id');
}
/**
* 获取子级分组
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id', 'id');
}
/**
* 获取分组下的文件
*/
public function files(): HasMany
{
return $this->hasMany(SysFileModel::class, 'group_id', 'id');
}
/**
* 获取分组下的文件数量
*/
public function getCountFilesAttribute(): int
{
return $this->files()->count();
}
}
+109
View File
@@ -0,0 +1,109 @@
<?php
namespace Modules\SystemTool\Models;
use App\Models\UserModel;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;
use Modules\SystemTool\Enum\FileType;
use Modules\SystemUser\Models\SysUserModel;
/**
* Class File
*/
class SysFileModel extends Model
{
use SoftDeletes;
protected $table = 'sys_file';
protected $primaryKey = 'id';
protected $casts = [
'group_id' => 'int',
'channel' => 'int',
'file_type' => 'int',
'file_size' => 'int',
'uploader_id' => 'int',
];
protected $fillable = [
'group_id',
'disk',
'channel',
'file_type',
'file_name',
'file_path',
'file_size',
'file_ext',
'uploader_id',
];
protected $appends = ['preview_url', 'file_url'];
/**
* 获取文件所属分组
*/
public function group(): BelongsTo
{
return $this->belongsTo(SysFileGroupModel::class, 'group_id', 'id');
}
/**
* 获取上传者
* 根据channel字段判断是系统用户还是App用户
*/
public function uploader(): BelongsTo
{
// channel 10:系统用户 20:App用户端
if ($this->channel == 10) {
return $this->belongsTo(SysUserModel::class, 'uploader_id', 'id');
} else {
return $this->belongsTo(UserModel::class, 'uploader_id', 'id');
}
}
protected function previewUrl(): Attribute
{
return new Attribute(
get: function ($value, array $data) {
try {
// 图片类型:直接返回图片URL作为预览
if ($data['file_type'] === FileType::IMAGE->value) {
if($data['disk'] === 'local') {
return Storage::disk($data['disk'])->url($data['file_path']);
}
return Storage::disk($data['disk'])->temporaryUrl(
$data['file_path'], now()->plus(minutes: 5)
);
}
$fileType = FileType::tryFrom($data['file_type']);
// 其他类型:返回默认类型图标
$previewPath = $fileType?->previewPath() ?? FileType::ANNEX->previewPath();
return config('app.url') . '/' . $previewPath;
} catch (\Throwable $e) {
// 发生异常时返回默认图标
return config('app.url') . '/' . FileType::ANNEX->previewPath();
}
}
);
}
/**
* 获取文件访问URL
*/
protected function fileUrl(): Attribute
{
return new Attribute(
get: function ($value, array $data) {
try {
return Storage::disk($data['disk'])->url($data['file_path']);
} catch (\Throwable $e) {
return null;
}
}
);
}
}
@@ -0,0 +1,40 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* 首页宫格导航模型
*/
class SysGridNavModel extends Model
{
protected $table = 'sys_grid_nav';
protected $casts = [
'status' => 'int',
'sort' => 'int',
'image_id' => 'int',
];
protected $fillable = [
'title',
'image_id',
'link',
'status',
'sort',
];
protected $with = ['image'];
/**
* 关联图片
* @return HasOne
*/
public function image(): HasOne
{
return $this->hasOne(SysFileModel::class, 'id', 'image_id');
}
}
@@ -0,0 +1,29 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class SiteConfig Group
*/
class SysSiteConfigGroupModel extends Model
{
protected $table = 'sys_site_config_group';
protected $fillable = [
'title',
'key',
'remark',
];
/**
* 关联设置项目
* @return HasMany
*/
public function configs(): HasMany
{
return $this->hasMany(SysSiteConfigItemsModel::class ,'group_id', 'id');
}
}
@@ -0,0 +1,101 @@
<?php
namespace Modules\SystemTool\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\SystemTool\Enum\SiteConfigType;
/**
* Class Setting
*/
class SysSiteConfigItemsModel extends Model
{
protected $table = 'sys_site_config_items';
protected $casts = [
'group_id' => 'int',
'sort' => 'int',
];
protected $fillable = [
'key',
'title',
'describe',
'values',
'type',
'options',
'props',
'group_id',
'sort',
];
protected $appends = ['options_json', 'props_json'];
/**
* 关联设置
* @return BelongsTo
*/
public function group(): BelongsTo
{
return $this->belongsTo(SysSiteConfigGroupModel::class, 'id', 'group_id');
}
protected function values(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
$type_enum = SiteConfigType::tryFrom($attributes['type']);
if($type_enum) {
return $type_enum->castValue($value);
} else {
return $value;
}
},
);
}
public function getOptionsJsonAttribute(): string
{
if(empty($this->options)) {
return "{}";
}
$data = [];
$value = explode("\n", $this->options);
foreach ($value as $item) {
$item = explode('=',$item);
if(count($item) < 2) {
continue;
}
$data[] = [
'label' => $item[1],
'value' => $item[0]
];
}
return json_encode($data);
}
public function getPropsJsonAttribute(): string
{
if(empty($this->props)) {
return "{}";
}
$data = [];
$value = explode("\n",$this->props);
foreach ($value as $item) {
$item = explode('=',$item);
if(count($item) < 2) {
continue;
}
if($item[1] === 'false') {
$data[$item[0]] = false;
}elseif ($item[1] === 'true') {
$data[$item[0]] = true;
}else {
$data[$item[0]] = $item[1];
}
}
return json_encode($data);
}
}