初始化本地仓库
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\crontab;
|
||||
|
||||
use app\enum\system\TaskScheduleCycle;
|
||||
use core\base\BaseModel;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Crontab extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'sys_crontab';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $casts = [
|
||||
'cycle_rule' => 'array',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'biz_id',
|
||||
'title',
|
||||
'type',
|
||||
'task_cycle',
|
||||
'cycle_rule',
|
||||
'rule',
|
||||
'target',
|
||||
'running_times',
|
||||
'last_running_time',
|
||||
'enabled',
|
||||
'first_start',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'singleton',
|
||||
'remark',
|
||||
];
|
||||
|
||||
/**
|
||||
* 通过ID获取最后执行记录
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLogAttribute(): mixed
|
||||
{
|
||||
return CrontabLog::getModel()->where(['crontab_id' => $this->id])
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取器-创建时间
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreateTimeAttribute($value): string
|
||||
{
|
||||
return getDateText($value);
|
||||
return date('Y-m-d H:i:s', $value); // 将时间戳格式化为日期时间字符串
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取器-last_running_time
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getLastRunningTimeAttribute($value): bool|string
|
||||
{
|
||||
if (!$value) return '--';
|
||||
return getDateText($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取器-rule_name
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRuleNameAttribute($value): ?string
|
||||
{
|
||||
// 提前返回空规则
|
||||
if (empty($this->cycle_rule)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ruleArr = $this->cycle_rule;
|
||||
$weekMap = [0 => '周日', 1 => '周一', 2 => '周二', 3 => '周三', 4 => '周四', 5 => '周五', 6 => '周六'];
|
||||
|
||||
try {
|
||||
$taskCycle = TaskScheduleCycle::from($this->task_cycle ?? 1);
|
||||
} catch (InvalidArgumentException) {
|
||||
return '任务周期配置错误';
|
||||
}
|
||||
|
||||
// 公共时间组件生成器(带安全访问)
|
||||
$timeComponent = fn($key, $default = 0) => $ruleArr[$key] ?? $default;
|
||||
|
||||
// 基础时间格式
|
||||
$baseTimeFormat = function () use ($ruleArr, $timeComponent) {
|
||||
$hour = $timeComponent('hour');
|
||||
$minute = $timeComponent('minute');
|
||||
return $hour > 0 ? "{$hour}点{$minute}分" : "{$minute}分";
|
||||
};
|
||||
|
||||
return match ($taskCycle) {
|
||||
TaskScheduleCycle::DAILY => "每天{$baseTimeFormat()}",
|
||||
TaskScheduleCycle::HOURLY => "每小时第{$timeComponent('minute')}分",
|
||||
TaskScheduleCycle::N_HOURS => "{$timeComponent('hour')}小时第{$timeComponent('minute')}分",
|
||||
TaskScheduleCycle::N_MINUTES => "{$timeComponent('minute')}分",
|
||||
TaskScheduleCycle::N_SECONDS => "{$timeComponent('second')}秒",
|
||||
TaskScheduleCycle::WEEKLY => sprintf(
|
||||
"每%s%s",
|
||||
$weekMap[$timeComponent('week', 0)] ?? '未知星期',
|
||||
$baseTimeFormat()
|
||||
),
|
||||
TaskScheduleCycle::MONTHLY => sprintf(
|
||||
"每月%d号%s",
|
||||
$timeComponent('day', 1),
|
||||
$baseTimeFormat()
|
||||
),
|
||||
TaskScheduleCycle::YEARLY => sprintf(
|
||||
"每年%d月%d号%s",
|
||||
$timeComponent('month', 1),
|
||||
$timeComponent('day', 1),
|
||||
$baseTimeFormat()
|
||||
),
|
||||
default => '未知任务规则'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联执行志记录表
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function logs(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(CrontabLog::class, 'crontab_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\crontab;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
*定时任务日志
|
||||
*/
|
||||
class CrontabLog extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_crontab_log';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'crontab_id',
|
||||
'target',
|
||||
'log',
|
||||
'return_code',
|
||||
'running_time',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取 create_time 属性的访问器。
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreateTimeAttr($value): string
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value); // 将时间戳格式化为日期时间字符串
|
||||
}
|
||||
|
||||
public function getRunningTimeAttr($value): string
|
||||
{
|
||||
return number_format($value, 2) . 'ms'; // 将时间戳格式化为日期时间字符串
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\dict;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 字典模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Dict extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_dict';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'group_code',
|
||||
'name',
|
||||
'code',
|
||||
'sort',
|
||||
'data_type',
|
||||
'description',
|
||||
'enabled',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::deleting(function ($model) {
|
||||
//删除主模型关联删除字典数据
|
||||
$model->items()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ID-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeId($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('id', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典名称-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeName($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('name', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典代码-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeCode($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('code', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeEnable($query, $value)
|
||||
{
|
||||
if ($value !== '') {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('enable', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*/
|
||||
public function items(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(DictItem::class, 'dict_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\dict;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class DictItem extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_dict_item';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'dict_id',
|
||||
'label',
|
||||
'value',
|
||||
'code',
|
||||
'sort',
|
||||
'enabled',
|
||||
'color',
|
||||
'other_class',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'remark',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关键字搜索
|
||||
*/
|
||||
public function scopeKeywords($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$query->where('label|code', 'LIKE', "%$value%");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeStatus($query, $value)
|
||||
{
|
||||
if ($value !== '') {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('status', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典ID-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeDictId($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('dict_id', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字典标识-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeCode($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('code', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Value- 搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeValue($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$query->where('value', 'LIKE', "%$value%");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Label-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeLabel($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$query->where('label', 'LIKE', "%$value%");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取器-扩展属性
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed|object
|
||||
*/
|
||||
public function getExt($value): mixed
|
||||
{
|
||||
if (is_null($value) || $value === '') {
|
||||
return (object)[];
|
||||
}
|
||||
return json_decode($value, 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\gateway;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 限流模型
|
||||
*
|
||||
* 用于存储和管理速率限制规则,支持IP限流、用户限流等功能
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RateLimiter extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 数据表名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_rate_limiter';
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
/**
|
||||
* 可填充字段
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
"id", // 主键ID
|
||||
"name", // 规则名称
|
||||
"enabled", // 规则状态(0-禁用,1-启用)
|
||||
"priority", // 规则优先级(数字越小优先级越高)
|
||||
"match_type", // 匹配类型(exact-精确匹配,wildcard-通配符匹配,regex-正则表达式匹配)
|
||||
"conditions", // 附加条件
|
||||
"http_methods", // HTTP方法
|
||||
"path", // 限制路径
|
||||
"limit_type", // 限制类型(ip-IP限流,user-用户限流)
|
||||
"limit_value", // 限制值
|
||||
"period", // 统计周期(秒)
|
||||
"ttl", // 缓存时间(秒)
|
||||
"message", // 提示信息
|
||||
"created_by", // 创建人
|
||||
"updated_by", // 修改人
|
||||
"created_at", // 创建时间
|
||||
"updated_at", // 修改时间
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\gateway;
|
||||
|
||||
use core\base\BaseModel;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* 限访模型
|
||||
*
|
||||
* 用于存储和管理访问限制规则,支持IP黑名单、路径限制等功能
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RateRestrictions extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 数据表名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_rate_restrictions';
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['created_date', 'updated_date', 'start_date', 'end_date'];
|
||||
|
||||
/**
|
||||
* 可填充字段
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
"id", // 主键ID
|
||||
"name", // 规则名称
|
||||
"enabled", // 规则状态(0-禁用,1-启用)
|
||||
"priority", // 规则优先级(数字越小优先级越高)
|
||||
"match_type", // 匹配类型(exact-精确匹配,wildcard-通配符匹配,regex-正则表达式匹配)
|
||||
"methods", // 请求方法(GET,POST,PUT等,*表示所有方法)
|
||||
"path", // 限制路径
|
||||
"ip", // IP地址
|
||||
"message", // 提示信息
|
||||
"start_time", // 开始时间(Unix时间戳)
|
||||
"end_time", // 结束时间(Unix时间戳)
|
||||
"created_by", // 创建人
|
||||
"updated_by", // 修改人
|
||||
"created_at", // 创建时间
|
||||
"updated_at", // 修改时间
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加起始时间
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStartDateAttribute(): ?string
|
||||
{
|
||||
if ($this->getAttribute('start_time')) {
|
||||
try {
|
||||
$timestamp = $this->getRawOriginal('start_time');
|
||||
if (empty($timestamp)) {
|
||||
return null;
|
||||
}
|
||||
$carbonInstance = Carbon::createFromTimestamp($timestamp);
|
||||
return $carbonInstance->setTimezone(config('app.default_timezone'))->format('Y-m-d H:i:s');
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getEndDateAttribute(): ?string
|
||||
{
|
||||
if ($this->getAttribute('end_time')) {
|
||||
try {
|
||||
$timestamp = $this->getRawOriginal('end_time');
|
||||
if (empty($timestamp)) {
|
||||
return null;
|
||||
}
|
||||
$carbonInstance = Carbon::createFromTimestamp($timestamp);
|
||||
return $carbonInstance->setTimezone(config('app.default_timezone'))->format('Y-m-d H:i:s');
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
namespace app\model\generator;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 代码生成器-字段
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class GeneratorColumn extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'generate_column';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'table_id',
|
||||
'column_name',
|
||||
'column_comment',
|
||||
'column_type',
|
||||
'is_required',
|
||||
'is_pk',
|
||||
'is_insert',
|
||||
'is_update',
|
||||
'is_lists',
|
||||
'is_query',
|
||||
'is_search',
|
||||
'query_type',
|
||||
'view_type',
|
||||
'dict_type',
|
||||
'plugin',
|
||||
'model',
|
||||
'sort',
|
||||
'label_key',
|
||||
'value_key',
|
||||
'create_time',
|
||||
'update_time',
|
||||
'is_delete',
|
||||
'is_order',
|
||||
'validate_type',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
namespace app\model\generator;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 代码生成器-表
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class GeneratorTable extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'generate_table';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'table_name',
|
||||
'table_content',
|
||||
'module_name',
|
||||
'class_name',
|
||||
'edit_type',
|
||||
'plugin_name',
|
||||
'order_type',
|
||||
'parent_menu',
|
||||
'relations',
|
||||
'push_sync_count',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联字段
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany|\app\model\generator\GeneratorTable
|
||||
*/
|
||||
public function columns(): \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany|GeneratorTable
|
||||
{
|
||||
return $this->hasMany(GeneratorColumn::class, 'table_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\logs;
|
||||
|
||||
use app\model\system\Admin;
|
||||
use core\base\BaseModel;
|
||||
|
||||
class LoginLog extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_login_log';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'user_id',
|
||||
'ip',
|
||||
'ip_location',
|
||||
'os',
|
||||
'browser',
|
||||
'status',
|
||||
'message',
|
||||
'login_time',
|
||||
'key',
|
||||
'created_at',
|
||||
'expires_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'remark',
|
||||
];
|
||||
|
||||
protected $casts = [];
|
||||
|
||||
/**
|
||||
* 关联管理员
|
||||
*/
|
||||
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\logs;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
class OperateLog extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_operate_log';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'app',
|
||||
'ip',
|
||||
'ip_location',
|
||||
'browser',
|
||||
'os',
|
||||
'url',
|
||||
'class_name',
|
||||
'action',
|
||||
'method',
|
||||
'param',
|
||||
'result',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'user_name',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'param' => 'array',
|
||||
'result' => 'array',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\system\Sex;
|
||||
use core\base\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 会员模型
|
||||
*/
|
||||
class Member extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 启用软删除
|
||||
*/
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'username',
|
||||
'email',
|
||||
'phone',
|
||||
'password',
|
||||
'nickname',
|
||||
'avatar',
|
||||
'level_id',
|
||||
'points',
|
||||
'balance',
|
||||
'gender',
|
||||
'birthday',
|
||||
'last_login_time',
|
||||
'last_login_ip',
|
||||
'login_count',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'bio'
|
||||
];
|
||||
|
||||
/**
|
||||
* 隐藏字段
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'gender_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取性别文本
|
||||
*/
|
||||
public function getGenderTextAttribute(): string
|
||||
{
|
||||
return Sex::tryFrom($this->gender)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员等级
|
||||
*/
|
||||
public function level(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MemberLevel::class, 'level_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员标签
|
||||
*/
|
||||
public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(MemberTag::class, MemberTagRelation::class, 'member_id', 'tag_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联签到记录
|
||||
*/
|
||||
public function signRecords(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberSign::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联第三方登录
|
||||
*/
|
||||
public function thirdParties(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberThirdParty::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联收货地址
|
||||
*/
|
||||
public function addresses(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberAddress::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现账号
|
||||
*/
|
||||
public function withdrawAccounts(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberWithdrawAccount::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现记录
|
||||
*/
|
||||
public function withdraws(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberWithdraw::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联账单记录
|
||||
*/
|
||||
public function bills(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberBill::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联积分记录
|
||||
*/
|
||||
public function pointsRecords(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberPoints::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分组
|
||||
*/
|
||||
public function groups(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(MemberGroup::class, 'member_group_relation', 'member_id', 'group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置密码
|
||||
*/
|
||||
public function setPasswordAttribute($value): void
|
||||
{
|
||||
$this->attributes['password'] = password_hash($value, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置生日
|
||||
*/
|
||||
public function setBirthdayAttribute($value): void
|
||||
{
|
||||
if (empty($value)) {
|
||||
$this->attributes['birthday'] = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
$this->attributes['birthday'] = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$carbon = \Carbon\Carbon::parse($value);
|
||||
$this->attributes['birthday'] = $carbon->timestamp;
|
||||
} catch (\Exception $e) {
|
||||
$this->attributes['birthday'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取生日
|
||||
*/
|
||||
public function getBirthdayAttribute($value): ?string
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return \Carbon\Carbon::createFromTimestamp($value)->toIso8601String();
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
*/
|
||||
public function verifyPassword($password): bool
|
||||
{
|
||||
return password_verify($password, $this->password);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员收货地址模型
|
||||
*/
|
||||
class MemberAddress extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_address';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'name',
|
||||
'phone',
|
||||
'province',
|
||||
'city',
|
||||
'district',
|
||||
'address',
|
||||
'zipcode',
|
||||
'is_default',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'is_default_text',
|
||||
'enabled_text',
|
||||
'full_address',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取默认状态文本
|
||||
*/
|
||||
public function getIsDefaultTextAttribute(): string
|
||||
{
|
||||
return $this->is_default == 1 ? '默认' : '非默认';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整地址
|
||||
*/
|
||||
public function getFullAddressAttribute(): string
|
||||
{
|
||||
return implode('', [
|
||||
$this->province,
|
||||
$this->city,
|
||||
$this->district,
|
||||
$this->address,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
use app\enum\member\BillType;
|
||||
use app\enum\member\BillCategory;
|
||||
use app\enum\member\BillStatus;
|
||||
|
||||
/**
|
||||
* 会员账单模型
|
||||
*/
|
||||
class MemberBill extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_bill';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'type',
|
||||
'category',
|
||||
'amount',
|
||||
'balance',
|
||||
'description',
|
||||
'order_sn',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'type_text',
|
||||
'category_text',
|
||||
'status_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取类型文本
|
||||
*/
|
||||
public function getTypeTextAttribute(): string
|
||||
{
|
||||
return BillType::tryFrom($this->type)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类文本
|
||||
*/
|
||||
public function getCategoryTextAttribute(): string
|
||||
{
|
||||
return BillCategory::tryFrom($this->category)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
return BillStatus::tryFrom($this->status)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 会员等级模型
|
||||
*/
|
||||
class MemberLevel extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_level';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'level',
|
||||
'min_points',
|
||||
'max_points',
|
||||
'discount',
|
||||
'icon',
|
||||
'color',
|
||||
'description',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function members(): \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany|MemberLevel
|
||||
{
|
||||
return $this->hasMany(Member::class, 'level_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员积分模型
|
||||
*/
|
||||
class MemberPoints extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'member_points';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'points',
|
||||
'balance',
|
||||
'points_after',
|
||||
'type',
|
||||
'source',
|
||||
'remark',
|
||||
'operator',
|
||||
'order_id',
|
||||
'created_at',
|
||||
'create_time',
|
||||
];
|
||||
|
||||
/**
|
||||
* 主键类型
|
||||
*/
|
||||
protected $keyType = 'string';
|
||||
|
||||
/**
|
||||
* 是否自增
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected $casts = [
|
||||
'points' => 'integer',
|
||||
'balance' => 'integer',
|
||||
'points_after' => 'integer',
|
||||
'type' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联会员模型
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员签到模型
|
||||
*/
|
||||
class MemberSign extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_sign';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'sign_date',
|
||||
'points',
|
||||
'continuous_days',
|
||||
'device_ip',
|
||||
'device_ua',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\web\Menu;
|
||||
use core\base\BaseModel;
|
||||
use app\enum\common\EnabledStatus;
|
||||
|
||||
/**
|
||||
* 会员标签模型
|
||||
*/
|
||||
class MemberTag extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_tag';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'color',
|
||||
'description',
|
||||
'sort',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function members(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Member::class, 'member_tag_relation', 'tag_id', 'member_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联菜单权限
|
||||
*/
|
||||
public function permissions(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Menu::class, MemberTagPermission::class, 'tag_id', 'menu_id')->orderBy('sort');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 会员标签菜单关联中间模型(Pivot)
|
||||
*
|
||||
* 用于 MemberTag 和 Menu 之间的多对多关联
|
||||
*/
|
||||
class MemberTagPermission extends Pivot
|
||||
{
|
||||
/**
|
||||
* 关联的表名
|
||||
*/
|
||||
protected $table = 'member_tag_permission';
|
||||
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'tag_id',
|
||||
'menu_id',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 会员标签关系模型
|
||||
*/
|
||||
class MemberTagRelation extends Pivot
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_tag_relation';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'member_id',
|
||||
'tag_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联标签
|
||||
*/
|
||||
public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MemberTag::class, 'tag_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\member\ThirdPartyPlatform;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员第三方登录模型
|
||||
*
|
||||
* @property int|mixed $enabled*/
|
||||
class MemberThirdParty extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_third_party';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'platform',
|
||||
'openid',
|
||||
'unionid',
|
||||
'nickname',
|
||||
'avatar',
|
||||
'gender',
|
||||
'country',
|
||||
'province',
|
||||
'city',
|
||||
'access_token',
|
||||
'refresh_token',
|
||||
'enabled',
|
||||
'expires_at',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'platform_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取平台文本
|
||||
*/
|
||||
public function getPlatformTextAttribute(): string
|
||||
{
|
||||
return ThirdPartyPlatform::tryFrom($this->platform)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
use app\enum\member\WithdrawStatus;
|
||||
|
||||
/**
|
||||
* 会员提现模型
|
||||
*/
|
||||
class MemberWithdraw extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_withdraw';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'account_id',
|
||||
'amount',
|
||||
'fee',
|
||||
'actual_amount',
|
||||
'status',
|
||||
'bank_name',
|
||||
'bank_account',
|
||||
'bank_cardholder',
|
||||
'order_sn',
|
||||
'remark',
|
||||
'audit_remark',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'audit_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'status_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
return WithdrawStatus::tryFrom($this->status)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现账号
|
||||
*/
|
||||
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MemberWithdrawAccount::class, 'account_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\member\WithdrawAccountType;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员提现账号模型
|
||||
*/
|
||||
class MemberWithdrawAccount extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_withdraw_account';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'type',
|
||||
'bank_name',
|
||||
'account_name',
|
||||
'account_number',
|
||||
'branch_name',
|
||||
'is_default',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'type_text',
|
||||
'is_default_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取类型文本
|
||||
*/
|
||||
public function getTypeTextAttribute(): string
|
||||
{
|
||||
return WithdrawAccountType::tryFrom($this->type)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认状态文本
|
||||
*/
|
||||
public function getIsDefaultTextAttribute(): string
|
||||
{
|
||||
return $this->is_default == 1 ? '默认' : '非默认';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现记录
|
||||
*/
|
||||
public function withdraws(): MemberWithdrawAccount|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberWithdraw::class, 'account_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
namespace app\model\message;
|
||||
|
||||
use app\model\system\Admin;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 系统公告
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Message extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'sys_message';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'type',
|
||||
'title',
|
||||
'content',
|
||||
'sender_id',
|
||||
'receiver_id',
|
||||
'status',
|
||||
'priority',
|
||||
'channel',
|
||||
'related_id',
|
||||
'related_type',
|
||||
'action_url',
|
||||
'action_params',
|
||||
'message_uuid',
|
||||
'read_at',
|
||||
'created_at',
|
||||
'expired_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联发送用户
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function sender(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'sender_id')->select(['id', 'real_name', 'user_name', 'dept_id']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
namespace app\model\notice;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 系统公告
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Notice extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'sys_notice';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'message_id',
|
||||
'title',
|
||||
'type',
|
||||
'content',
|
||||
'enabled',
|
||||
'uuid',
|
||||
'created_dept',
|
||||
'created_by',
|
||||
'created_at',
|
||||
'updated_by',
|
||||
'updated_at',
|
||||
'remark',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\org;
|
||||
|
||||
use app\model\system\Admin;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 部门模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Dept extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_dept';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'pid',
|
||||
'level',
|
||||
'code',
|
||||
'name',
|
||||
'main_leader_id',
|
||||
'phone',
|
||||
'enabled',
|
||||
'sort',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'remark',
|
||||
];
|
||||
|
||||
/**
|
||||
* 部门名称-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeName($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$query->where('name', 'like', $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
public function scopePid($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (is_string($value)) {
|
||||
$value = array_map('trim', explode(',', $value));
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$query->whereIn('pid', $value);
|
||||
} else {
|
||||
$query->where('pid', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeStatus($query, $value)
|
||||
{
|
||||
if ($value !== '') {
|
||||
$query->where('status', $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function leader(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Admin::class, DeptLeader::class, 'dept_id', 'admin_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\org;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class DeptLeader extends Pivot
|
||||
{
|
||||
protected $table = 'sys_dept_leader';
|
||||
|
||||
// protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'dept_id',
|
||||
'admin_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\org;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 岗位模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Post extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_post';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'dept_id',
|
||||
'code',
|
||||
'name',
|
||||
'sort',
|
||||
'enabled',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'remark',
|
||||
];
|
||||
|
||||
public function dept(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Dept::class,'dept_id','id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\plugin;
|
||||
|
||||
use app\model\system\Admin;
|
||||
use core\base\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ApplicationAuth extends BaseModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'plugin_application_auth';
|
||||
|
||||
protected $appends = ['expired_date', 'created_date', 'updated_date', 'created_name', 'updated_name'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'access_key',
|
||||
'secret_key',
|
||||
'expired_at',
|
||||
'enabled',
|
||||
'description',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'expired_at' => 'integer',
|
||||
'enabled' => 'integer',
|
||||
'created_at' => 'integer',
|
||||
'updated_at' => 'integer',
|
||||
'deleted_at' => 'integer',
|
||||
];
|
||||
|
||||
public function createds(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'created_by')->select('id', 'real_name as created_name');
|
||||
}
|
||||
|
||||
public function updateds(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'updated_by')->select('id', 'real_name as updated_name');
|
||||
}
|
||||
|
||||
public function getExpiredDateAttribute(): ?string
|
||||
{
|
||||
$timestamp = $this->getRawOriginal('expired_at');
|
||||
if (empty($timestamp)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Carbon\Carbon::createFromTimestamp((int)$timestamp)
|
||||
->setTimezone(config('app.default_timezone'))
|
||||
->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function getCreatedNameAttribute(): string
|
||||
{
|
||||
return $this->createds?->created_name ?? '';
|
||||
}
|
||||
|
||||
public function getUpdatedNameAttribute(): string
|
||||
{
|
||||
return $this->updateds?->updated_name ?? '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
namespace app\model\plugin;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 系统插件
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Plugin extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'plugin';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
/**
|
||||
* 时间格式为Unix时间戳
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'title',
|
||||
'icon',
|
||||
'key',
|
||||
'desc',
|
||||
'status',
|
||||
'author',
|
||||
'version',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'installed_at',
|
||||
'cover',
|
||||
'type',
|
||||
'variables',
|
||||
'support_app',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: https://madong.tech
|
||||
*/
|
||||
|
||||
namespace app\model\plugin;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 系统插件日志
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class PluginLog extends BaseModel
|
||||
{
|
||||
protected $table = 'plugin_log';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'action',
|
||||
'key',
|
||||
'pre_upgrade_version',
|
||||
'post_upgrade_version',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\review;
|
||||
|
||||
use app\enum\review\ReviewStatus;
|
||||
use app\model\system\Admin;
|
||||
use core\base\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 通用审核模型
|
||||
*
|
||||
* 支持两种模式:
|
||||
* 1. 简单审核模式(flow_instance_id 为空):直接审核通过/拒绝
|
||||
* 2. 审批流模式(flow_instance_id 不为空):关联第三方审批流实例,由审批流模块处理
|
||||
*/
|
||||
class Review extends BaseModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* 重写 booted 方法,不添加数据权限全局作用域
|
||||
* Review 表不需要数据权限控制
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
// 不调用父类的 booted,避免添加 AccessPermissionScope
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据表名称
|
||||
*
|
||||
* 注意:表名不要包含前缀,前缀由数据库配置自动添加
|
||||
*/
|
||||
protected $table = 'sys_review';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'reviewable_type', // 关联模型类型
|
||||
'reviewable_id', // 关联模型ID
|
||||
'status', // 审核状态
|
||||
'reason', // 审核原因/备注
|
||||
'reviewer_id', // 审核人ID(简单模式)
|
||||
'reviewed_at', // 审核时间
|
||||
'flow_instance_id', // 审批流实例ID(审批流模式,关联第三方审批流)
|
||||
'extra_data', // 扩展数据(JSON格式)
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 字段类型转换
|
||||
*/
|
||||
protected $casts = [
|
||||
'extra_data' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* 隐藏字段
|
||||
*/
|
||||
protected $hidden = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'status_text',
|
||||
'is_workflow_mode',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取审核状态文本
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
return ReviewStatus::getLabel($this->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为审批流模式
|
||||
*/
|
||||
public function getIsWorkflowModeAttribute(): bool
|
||||
{
|
||||
return !empty($this->flow_instance_id);
|
||||
}
|
||||
|
||||
// ==================== 关联关系 ====================
|
||||
|
||||
/**
|
||||
* 多态关联 - 关联的审核对象
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||
*/
|
||||
public function reviewable(): \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联审核人
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function reviewer(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'reviewer_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联审批流实例(第三方模块)
|
||||
*
|
||||
* 注意:此方法需要在第三方审批流模块中实现具体的关联逻辑
|
||||
* 这里只是一个预留接口,返回动态关联
|
||||
*
|
||||
* 使用示例:
|
||||
* $review->flowInstance; // 获取审批流实例信息
|
||||
*/
|
||||
public function flowInstance(): mixed
|
||||
{
|
||||
// 预留接口,由第三方审批流模块实现
|
||||
// 可以通过服务容器动态获取审批流实例
|
||||
if (empty($this->flow_instance_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 示例:假设第三方审批流模块提供了一个 FlowInstance 模型
|
||||
// 使用时需要根据第三方模块的具体实现调整
|
||||
$flowModelClass = config('review.flow_model', null);
|
||||
if ($flowModelClass && class_exists($flowModelClass)) {
|
||||
return $this->belongsTo($flowModelClass, 'flow_instance_id', 'id');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 搜索器 - 按状态查询
|
||||
*/
|
||||
public function scopeStatus($query, $status)
|
||||
{
|
||||
if ($status !== '' && $status !== null) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索器 - 按审核类型查询
|
||||
*/
|
||||
public function scopeReviewableType($query, $type)
|
||||
{
|
||||
if (!empty($type)) {
|
||||
$query->where('reviewable_type', $type);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索器 - 按审批流实例ID查询
|
||||
*/
|
||||
public function scopeFlowInstanceId($query, $flowInstanceId)
|
||||
{
|
||||
if (!empty($flowInstanceId)) {
|
||||
$query->where('flow_instance_id', $flowInstanceId);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索器 - 按创建时间范围查询
|
||||
*/
|
||||
public function scopeCreateTimeRange($query, $range)
|
||||
{
|
||||
if (!empty($range) && is_array($range) && count($range) === 2) {
|
||||
$query->whereBetween('created_at', $range);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否为简单审核模式
|
||||
*/
|
||||
public function isSimpleMode(): bool
|
||||
{
|
||||
return empty($this->flow_instance_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为审批流模式
|
||||
*/
|
||||
public function isWorkflowMode(): bool
|
||||
{
|
||||
return !empty($this->flow_instance_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以审核
|
||||
*
|
||||
* 简单模式:检查是否待审核状态
|
||||
* 审批流模式:由第三方审批流模块判断(需要调用方自行处理)
|
||||
*/
|
||||
public function canReview(int $userId): bool
|
||||
{
|
||||
// 简单审核模式
|
||||
if ($this->isSimpleMode()) {
|
||||
return $this->status === ReviewStatus::PENDING->value;
|
||||
}
|
||||
|
||||
// 审批流模式 - 由第三方审批流模块判断
|
||||
// 这里返回 false,具体逻辑由调用方通过第三方接口判断
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取审批流实例信息(从第三方模块)
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getFlowInstanceInfo(): ?array
|
||||
{
|
||||
if (empty($this->flow_instance_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 预留接口,由第三方审批流模块实现
|
||||
// 示例:
|
||||
// $flowService = app(config('review.flow_service'));
|
||||
// return $flowService->getInstanceInfo($this->flow_instance_id);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use app\model\message\Message;
|
||||
use app\model\org\Dept;
|
||||
use app\model\org\Post;
|
||||
use core\base\BaseModel;
|
||||
use core\casbin\model\RuleModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 后台管理员-模型
|
||||
*/
|
||||
class Admin extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 启用软删除
|
||||
*/
|
||||
use SoftDeletes;
|
||||
|
||||
// 完整数据库表名称
|
||||
protected $table = 'sys_admin';
|
||||
// 主键
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $casts = [
|
||||
'backend_setting' => 'array',
|
||||
'id' => 'string',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'user_name',
|
||||
'real_name',
|
||||
'nick_name',
|
||||
'password',
|
||||
'is_super',
|
||||
'mobile_phone',
|
||||
'email',
|
||||
'avatar',
|
||||
'signed',
|
||||
'dashboard',
|
||||
'enabled',
|
||||
'login_ip',
|
||||
'login_time',
|
||||
'backend_setting',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'sex',
|
||||
'remark',
|
||||
'birthday',
|
||||
'tel',
|
||||
'is_locked',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否为超级管理员
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return (bool)$this->is_super;
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeUserName($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$query->where('user_name', 'like', $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户昵称-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeRealName($query, $value)
|
||||
{
|
||||
if ($value !== '') {
|
||||
$query->where('real_name', 'like', $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户参数-解析
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBackendSetting($value): mixed
|
||||
{
|
||||
return json_decode($value ?? '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户参数-转换
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function setBackendSettingAttr($value): bool|string
|
||||
{
|
||||
return json_encode($value, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联-主归属信息(1:1)
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function mainInfo(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(AdminMain::class, 'admin_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联-用户部门
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function depts(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Dept::class, AdminDept::class, 'admin_id', 'dept_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联-用户职位
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function posts(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Post::class, AdminPost::class, 'admin_id', 'post_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过中间表关联角色
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function roles(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, AdminRole::class, 'admin_id', 'role_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 管理消息-列表
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function message(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Message::class, 'receiver_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型-策略表
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class AdminCasbin extends Pivot
|
||||
{
|
||||
protected $table = 'sys_admin_casbin';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'admin_id',
|
||||
'admin_casbin_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class AdminDept extends Pivot
|
||||
{
|
||||
protected $table = 'sys_admin_dept';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'admin_id',
|
||||
'dept_id',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use app\model\org\Dept;
|
||||
use app\model\org\Post;
|
||||
use core\base\BaseModel;
|
||||
|
||||
class AdminMain extends BaseModel
|
||||
{
|
||||
protected $table = 'sys_admin_main';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'admin_id',
|
||||
'main_dept_id',
|
||||
'main_post_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
'admin_id' => 'string',
|
||||
'main_dept_id'=> 'string',
|
||||
'main_post_id' => 'string',
|
||||
];
|
||||
|
||||
public function admin(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'admin_id', 'id');
|
||||
}
|
||||
|
||||
public function mainDept(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Dept::class, 'main_dept_id', 'id');
|
||||
}
|
||||
|
||||
public function mainPost(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Post::class, 'main_post_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class AdminPost extends Pivot
|
||||
{
|
||||
protected $table = 'sys_admin_post';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'admin_id',
|
||||
'post_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 用户-关联角色模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class AdminRole extends Pivot
|
||||
{
|
||||
protected $table = 'sys_admin_role';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'admin_id',
|
||||
'role_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 配置模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Config extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_config';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected $casts = [
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'group_code',
|
||||
'code',
|
||||
'name',
|
||||
'content',
|
||||
'type',
|
||||
'is_sys',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
'deleted_at',
|
||||
'remark',
|
||||
];
|
||||
|
||||
/**
|
||||
* 分组代码-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeGroupCode($query, $value): void
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('group_code', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置名称-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeName($query, $value): void
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('name', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一编码-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeCode($query, $value): void
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('code', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeEnable($query, $value): void
|
||||
{
|
||||
if ($value !== '') {
|
||||
$queryMethod = is_array($value) ? 'whereIn' : 'where';
|
||||
$query->$queryMethod('enable', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use app\model\member\Member;
|
||||
use core\base\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 问题反馈
|
||||
*/
|
||||
class Feedback extends BaseModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'sys_feedback';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date', 'created_name', 'reply_date', 'reply_name'];
|
||||
|
||||
protected $hidden = ['createds', 'replyAdmin'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'type',
|
||||
'content',
|
||||
'contact',
|
||||
'images',
|
||||
'source',
|
||||
'created_by',
|
||||
'reply_content',
|
||||
'reply_by',
|
||||
'reply_at',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'images' => 'array',
|
||||
'created_at' => 'integer',
|
||||
'updated_at' => 'integer',
|
||||
'deleted_at' => 'integer',
|
||||
'created_by' => 'string',
|
||||
'reply_by' => 'string',
|
||||
'reply_at' => 'integer',
|
||||
];
|
||||
|
||||
public function getCreatedDateAttribute(): ?string
|
||||
{
|
||||
$timestamp = $this->getRawOriginal('created_at');
|
||||
return empty($timestamp)
|
||||
? null
|
||||
: \Carbon\Carbon::createFromTimestamp((int)$timestamp)
|
||||
->setTimezone(config('app.default_timezone'))
|
||||
->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function createds(): HasOne
|
||||
{
|
||||
return $this->hasOne(Member::class, 'id', 'created_by')
|
||||
->select(['id', 'nickname', 'username']);
|
||||
}
|
||||
|
||||
public function replyAdmin(): HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'reply_by')
|
||||
->select(['id', 'real_name', 'user_name', 'nick_name']);
|
||||
}
|
||||
|
||||
public function getReplyDateAttribute(): ?string
|
||||
{
|
||||
$timestamp = $this->getRawOriginal('reply_at');
|
||||
return empty($timestamp)
|
||||
? null
|
||||
: \Carbon\Carbon::createFromTimestamp((int)$timestamp)
|
||||
->setTimezone(config('app.default_timezone'))
|
||||
->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function getReplyNameAttribute(): ?string
|
||||
{
|
||||
if (empty($this->getRawOriginal('reply_by'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$admin = $this->relationLoaded('replyAdmin')
|
||||
? $this->getRelation('replyAdmin')
|
||||
: $this->replyAdmin()->first();
|
||||
return (string)($admin?->getRawOriginal('real_name') ?: $admin?->getRawOriginal('nick_name') ?: $admin?->getRawOriginal('user_name') ?: '管理员');
|
||||
}
|
||||
|
||||
public function getCreatedNameAttribute(): string
|
||||
{
|
||||
$member = $this->relationLoaded('createds')
|
||||
? $this->getRelation('createds')
|
||||
: $this->createds()->first();
|
||||
return (string)($member?->getRawOriginal('nickname') ?: $member?->getRawOriginal('username') ?: '匿名用户');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 全局菜单
|
||||
*
|
||||
* @property mixed $children
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Menu extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'sys_menu';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'pid',
|
||||
'app',
|
||||
'title',
|
||||
'code',
|
||||
'level',
|
||||
'type',
|
||||
'sort',
|
||||
'path',
|
||||
'component',
|
||||
'redirect',
|
||||
'icon',
|
||||
'is_show',
|
||||
'is_link',
|
||||
'link_url',
|
||||
'open_type',
|
||||
'is_cache',
|
||||
'is_sync',
|
||||
'is_affix',
|
||||
'variable',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
'deleted_at',
|
||||
'methods',
|
||||
'source',
|
||||
'platform',
|
||||
];
|
||||
|
||||
/**
|
||||
* 菜单meta属性
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMetaAttribute($data): array
|
||||
{
|
||||
// 1.构建mate数组
|
||||
$title = trans($data['title'], [], 'menu');
|
||||
$newData = [
|
||||
'icon' => $data['icon'] ?? '',
|
||||
'title' => $title,
|
||||
'menuVisibleWithForbidden' => true,
|
||||
'keepAlive' => true,
|
||||
];
|
||||
|
||||
// 2.添加fixed锁定菜单标记
|
||||
if (isset($data['is_affix']) && ($data['is_affix'] === 1 || $data['is_affix'] === '1')) {
|
||||
$newData['order'] = -1;
|
||||
$newData['affixTab'] = true;
|
||||
}
|
||||
|
||||
// 3.是否隐藏菜单
|
||||
if (isset($data['is_show']) && $data['is_show'] == 0) {
|
||||
$newData['hideInMenu'] = true;
|
||||
}
|
||||
|
||||
// 4.是否缓存
|
||||
if (isset($data['is_cache']) && (int)$data['is_cache'] == 1) {
|
||||
$newData['keepAlive'] = true;
|
||||
}
|
||||
|
||||
//5.是否外链在新窗口打开
|
||||
if (isset($data['open_type']) && $data['open_type'] == 1) {
|
||||
$newData['link'] = true;
|
||||
}
|
||||
// 更多参数可以在这边添加
|
||||
return $newData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Id搜索
|
||||
*/
|
||||
public function scopeId($query, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$query->whereIn('id', $value);
|
||||
} else {
|
||||
$query->where('id', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Type搜索
|
||||
*/
|
||||
public function scopeType($query, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$query->whereIn('type', $value);
|
||||
} else {
|
||||
$query->where('type', $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function scopeEnabled($query, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$query->whereIn('enabled', $value);
|
||||
} else {
|
||||
$query->where('enabled', $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义删除-支持模型事件
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function deleteWithAllChildren(): array|bool
|
||||
{
|
||||
$allIds = array_merge([$this->id], $this->getAllChildrenIds());
|
||||
|
||||
if (empty($allIds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$successIds = [];
|
||||
|
||||
// 分块处理以避免内存问题
|
||||
collect($allIds)->chunk(100)->each(function ($chunk) use (&$successIds) {
|
||||
$chunk->each(function ($id) use (&$successIds) {
|
||||
if ($model = self::find($id)) {
|
||||
if ($model->delete()) {
|
||||
// 触发模型事件
|
||||
$successIds[] = $id;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return !empty($successIds) ? $successIds : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子级ids
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllChildrenIds(): array
|
||||
{
|
||||
$childIds = $this->children()->pluck('id')->toArray(); // 获取直接子级的ID
|
||||
foreach ($this->children as $child) { // 遍历直接子级
|
||||
$childIds = array_merge($childIds, $child->getAllChildrenIds()); // 递归获取嵌套子级
|
||||
}
|
||||
return array_unique($childIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义子级关系
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function children(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'pid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过中间表获取角色
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function roles(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class, RoleMenu::class, 'menu_id', 'role_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use core\base\BaseModel;
|
||||
use core\context\TenantContext;
|
||||
|
||||
/**
|
||||
* 附件模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RecycleBin extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_recycle_bin';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date', 'operate_name'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'original_id',
|
||||
'data',
|
||||
'table_name',
|
||||
'table_prefix',
|
||||
'enabled',
|
||||
'ip',
|
||||
'operate_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'data' => 'array',
|
||||
|
||||
];
|
||||
|
||||
// // 1. 定义访问器/修改器
|
||||
// public function getDataAttribute($value)
|
||||
// {
|
||||
// return json_decode($value, true) ?? [];
|
||||
// }
|
||||
//
|
||||
// public function setDataAttribute($value)
|
||||
// {
|
||||
// $this->attributes['data'] = json_encode($value);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 动态数据库链接(主库)
|
||||
*
|
||||
* @return \app\common\model\system\SysRecycleBin
|
||||
*/
|
||||
public static function centralConnection(): RecycleBin
|
||||
{
|
||||
return (new static)->setConnection(config('database.default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义访问器
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getOperateNameAttribute(): mixed
|
||||
{
|
||||
return $this->operate ? $this->operate->operate_name : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联-操作人
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function operate(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'operate_id')->select(['id', 'real_name as operate_name']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use app\model\org\Dept;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 角色模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Role extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_role';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'pid',
|
||||
'name',
|
||||
'code',
|
||||
'role_type',
|
||||
'data_scope',
|
||||
'enabled',
|
||||
'sort',
|
||||
'remark',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* Id搜索
|
||||
*/
|
||||
public function scopeId($query, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$query->whereIn('id', $value);
|
||||
} else {
|
||||
$query->where('id', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色名称-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeName($query, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
$query->where('name', 'like', $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态-搜索器
|
||||
*
|
||||
* @param $query
|
||||
* @param $value
|
||||
*/
|
||||
public function scopeStatus($query, $value)
|
||||
{
|
||||
if ($value !== '') {
|
||||
$query->where('status', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过中间表获取菜单
|
||||
*/
|
||||
public function menus(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Menu::class, RoleMenu::class, 'role_id', 'menu_id')->orderBy('sort');
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过中间表获取部门
|
||||
*/
|
||||
public function depts(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Dept::class, RoleDept::class, 'role_id', 'dept_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过中间表获取部门
|
||||
*/
|
||||
public function scopes(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Dept::class, RoleScopeDept::class, 'role_id', 'dept_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use core\context\TenantContext;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 角色-关联策略表模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RoleCasbin extends Pivot
|
||||
{
|
||||
protected $table = 'sys_role_casbin';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'role_id',
|
||||
'role_casbin_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RoleDept extends Pivot
|
||||
{
|
||||
protected $table = 'sys_role_dept';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'role_id',
|
||||
'dept_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RoleMenu extends Pivot
|
||||
{
|
||||
protected $table = 'sys_role_menu';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'role_id',
|
||||
'menu_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 关联模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class RoleScopeDept extends Pivot
|
||||
{
|
||||
protected $table = 'sys_role_scope_dept';
|
||||
|
||||
/**
|
||||
* 指示是否自动维护时间戳
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'role_id',
|
||||
'dept_id',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.cn
|
||||
*/
|
||||
|
||||
namespace app\model\system;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 附件模型
|
||||
*
|
||||
* @author Mr.April
|
||||
* @since 1.0
|
||||
*/
|
||||
class Upload extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $table = 'sys_upload';
|
||||
|
||||
protected $appends = ['created_date', 'updated_date'];
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'url',
|
||||
'size',
|
||||
'size_info',
|
||||
'hash',
|
||||
'filename',
|
||||
'original_filename',
|
||||
'base_path',
|
||||
'path',
|
||||
'ext',
|
||||
'content_type',
|
||||
'platform',
|
||||
'th_url',
|
||||
'th_filename',
|
||||
'th_size',
|
||||
'th_size_info',
|
||||
'th_content_type',
|
||||
'object_id',
|
||||
'object_type',
|
||||
'attr',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
/**
|
||||
* createds
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function createds(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'created_by')->select('id', 'real_name as created_name');
|
||||
}
|
||||
|
||||
public function updateds(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Admin::class, 'id', 'updated_by')->select('id', 'real_name as updated_name');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\web;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 广告模型
|
||||
*/
|
||||
class Adv extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'web_adv';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'title',
|
||||
'link',
|
||||
'image',
|
||||
'description',
|
||||
'sort',
|
||||
'enabled',
|
||||
'start_time',
|
||||
'end_time',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 状态映射
|
||||
*/
|
||||
const STATUS_ENABLED = 1; // 启用
|
||||
const STATUS_DISABLED = 0; // 禁用
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
$statuses = [
|
||||
self::STATUS_ENABLED => '启用',
|
||||
self::STATUS_DISABLED => '禁用',
|
||||
];
|
||||
return $statuses[$this->enabled] ?? '未知';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\web;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\web\MenuTarget;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 友情链接模型
|
||||
*/
|
||||
class Link extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'web_link';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'url',
|
||||
'logo',
|
||||
'description',
|
||||
'category',
|
||||
'sort',
|
||||
'target',
|
||||
'click_count',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 类型转换
|
||||
*/
|
||||
protected $casts = [
|
||||
'enabled' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'click_count' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'target_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取目标窗口文本
|
||||
*/
|
||||
public function getTargetTextAttribute(): string
|
||||
{
|
||||
$target = MenuTarget::tryFrom((int)$this->target);
|
||||
return $target?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
$status = EnabledStatus::tryFrom((int)$this->enabled);
|
||||
return $status?->label() ?? '未知';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\web;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\common\YesNoStatus;
|
||||
use app\enum\system\MenuType;
|
||||
use app\enum\web\MenuCategory;
|
||||
use app\enum\web\MenuTarget;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 菜单模型
|
||||
*/
|
||||
class Menu extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'web_menu';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'app',
|
||||
'category',
|
||||
'source',
|
||||
'code',
|
||||
'name',
|
||||
'url',
|
||||
'pid',
|
||||
'level',
|
||||
'type',
|
||||
'sort',
|
||||
'target',
|
||||
'icon',
|
||||
'is_show',
|
||||
'enabled',
|
||||
'permissions',
|
||||
'extra',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'type_text',
|
||||
'target_text',
|
||||
'is_show_text',
|
||||
'enabled_text',
|
||||
'category_text',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
'pid' => 'string',
|
||||
'extra' => 'json',
|
||||
'category'=>'int'
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取导航类型文本
|
||||
*/
|
||||
public function getTypeTextAttribute(): string
|
||||
{
|
||||
$type = MenuType::tryFrom((int)$this->type);
|
||||
return $type?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取目标窗口文本
|
||||
*/
|
||||
public function getTargetTextAttribute(): string
|
||||
{
|
||||
$target = MenuTarget::tryFrom((int)$this->target);
|
||||
return $target?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取显示状态文本
|
||||
*/
|
||||
public function getIsShowTextAttribute(): string
|
||||
{
|
||||
$show = YesNoStatus::tryFrom((int)$this->is_show);
|
||||
return $show?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
$status = EnabledStatus::tryFrom((int)$this->status);
|
||||
return $status?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类文本
|
||||
*/
|
||||
public function getCategoryTextAttribute(): string
|
||||
{
|
||||
$category = MenuCategory::tryFrom((int)$this->category);
|
||||
return $category?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义子级关系
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function children(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'pid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有子级ID(递归)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllChildrenIds(): array
|
||||
{
|
||||
$childIds = $this->children()->pluck('id')->toArray();
|
||||
foreach ($this->children as $child) {
|
||||
$childIds = array_merge($childIds, $child->getAllChildrenIds());
|
||||
}
|
||||
return array_unique($childIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单及所有子级
|
||||
*
|
||||
* @return array|bool 成功删除的ID数组或false
|
||||
*/
|
||||
public function deleteWithAllChildren(): array|bool
|
||||
{
|
||||
$allIds = array_merge([$this->id], $this->getAllChildrenIds());
|
||||
|
||||
if (empty($allIds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$successIds = [];
|
||||
|
||||
// 分块处理以避免内存问题
|
||||
collect($allIds)->chunk(100)->each(function ($chunk) use (&$successIds) {
|
||||
$chunk->each(function ($id) use (&$successIds) {
|
||||
if ($model = self::find($id)) {
|
||||
if ($model->delete()) {
|
||||
$successIds[] = $id;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return !empty($successIds) ? $successIds : false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user