This commit is contained in:
你的名字
2025-10-15 14:53:54 +08:00
commit ac0f12b21a
864 changed files with 200931 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class BlackIp extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
// * +++++++++++++++++++++++++++
// | 以下两种写法适用于 with 关联
// * +++++++++++++++++++++++++
// public function cate(): BelongsTo
// {
// return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
// }
}

View File

@ -0,0 +1,18 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class MallCate extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
class MallGoods extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
// * +++++++++++++++++++++++++++
// | 以下两种写法适用于 with 关联
// * +++++++++++++++++++++++++
// public function cate(): BelongsTo
// {
// return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
// }
public function cate(): HasOne
{
return $this->hasOne(MallCate::class, 'id', 'cate_id');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
use think\model\relation\HasOne;
class MallOrder extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
// * +++++++++++++++++++++++++++
// | 以下两种写法适用于 with 关联
// * +++++++++++++++++++++++++
// public function cate(): BelongsTo
// {
// return $this->belongsTo('app\admin\model\MallCate', 'cate_id', 'id');
// }
}

View File

@ -0,0 +1,36 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class SystemAdmin extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
public array $notes = [
'login_type' => [
1 => '密码登录',
2 => '密码 + 谷歌验证码登录'
],
];
public static function getAuthIdsAttr($value): array
{
if (!$value) return [];
return explode(',', $value);
}
public static function getAuthList(): array
{
return SystemAuth::where('status', 1)->column('title', 'id');
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class SystemAuth extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
/**
* 根据角色ID获取授权节点
* @param $authId
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getAuthorizeNodeListByAdminId($authId): array
{
$checkNodeList = (new SystemAuthNode())
->where('auth_id', $authId)
->column('node_id');
$systemNode = new SystemNode();
$nodeList = $systemNode
->where('is_auth', 1)
->field('id,node,title,type,is_auth')
->select()
->toArray();
$newNodeList = [];
foreach ($nodeList as $vo) {
if ($vo['type'] == 1) {
$vo = array_merge($vo, ['field' => 'node', 'spread' => true]);
$vo['checked'] = false;
$vo['title'] = "{$vo['title']}{$vo['node']}";
$children = [];
foreach ($nodeList as $v) {
if ($v['type'] == 2 && strpos($v['node'], $vo['node'] . '/') !== false) {
$v = array_merge($v, ['field' => 'node', 'spread' => true]);
$v['checked'] = in_array($v['id'], $checkNodeList) ? true : false;
$v['title'] = "{$v['title']}{$v['node']}";
$children[] = $v;
}
}
!empty($children) && $vo['children'] = $children;
$newNodeList[] = $vo;
}
}
return $newNodeList;
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class SystemAuthNode extends TimeModel
{
}

View File

@ -0,0 +1,21 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
use think\Model;
class SystemConfig extends TimeModel
{
public static function onBeforeUpdate(Model $model): void
{
if ($model->getData('name') === 'upload_allow_ext') {
//去除 php
$model->value = implode(',',array_map(function ($ext) {
return trim(strtolower($ext), ' ');
}, array_filter(explode(',', $model->getData('value')), function ($ext) {
return strtolower(trim($ext)) !== 'php';
})));
}
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace app\admin\model;
use app\admin\service\SystemLogService;
use app\common\model\TimeModel;
use think\model\relation\BelongsTo;
class SystemLog extends TimeModel
{
protected array $type = [
'content' => 'json',
'response' => 'json',
];
protected function init(): void
{
SystemLogService::instance()->detectTable();
}
public function admin(): BelongsTo
{
return $this->belongsTo('app\admin\model\SystemAdmin', 'admin_id', 'id');
}
}

View File

@ -0,0 +1,132 @@
<?php
namespace app\admin\model;
use app\common\constants\MenuConstant;
use app\common\model\TimeModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
class SystemMenu extends TimeModel
{
public static array $menuTypeList = [
'system' => '系统管理',
'mall' => '商城管理',
'article' => '文章管理',
];
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
public static function onBeforeUpdate(Model $model): void
{
$model->system = 0; // 系统添加
}
/**
* @throws ModelNotFoundException
* @throws DbException
* @throws DataNotFoundException
*/
public static function getPidMenuList(): array
{
$list = self::field('id,pid,title')->where([
['pid', '<>', MenuConstant::HOME_PID],
['status', '=', 1],
])->select()->toArray();
$pidMenuList = self::buildPidMenu(0, $list);
return array_merge([[
'id' => 0,
'pid' => 0,
'title' => '顶级菜单',
]], $pidMenuList);
}
protected static function buildPidMenu($pid, $list, $level = 0): array
{
$newList = [];
foreach ($list as $vo) {
if ($vo['pid'] == $pid) {
$level++;
foreach ($newList as $v) {
if ($vo['pid'] == $v['pid'] && isset($v['level'])) {
$level = $v['level'];
break;
}
}
$vo['level'] = $level;
if ($level > 1) {
$repeatString = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$markString = str_repeat("{$repeatString}{$repeatString}", $level - 1);
$vo['title'] = $markString . $vo['title'];
}
$newList[] = $vo;
$childList = self::buildPidMenu($vo['id'], $list, $level);
!empty($childList) && $newList = array_merge($newList, $childList);
}
}
return $newList;
}
public static function refreshMenu($nodeList): void
{
$nodeList = array_filter($nodeList, function ($item) {
return $item['type'] == 1;
});
$menuList = array_map(function ($item) {
return "{$item['node']}/index";
}, $nodeList);
if (!empty($menuList)) {
$hasMenu = (new self())->whereIn('href', $menuList)->column('href');
$needInsertMenu = array_diff($menuList, $hasMenu);
$insertNode = array_filter($nodeList, function ($item) use ($needInsertMenu) {
return in_array("{$item['node']}/index", $needInsertMenu);
});
$data = [];
foreach ($insertNode as $vo) {
$pidText = explode('.', $vo['node']);
if (isset($pidText[0]) && self::$menuTypeList[$pidText[0]]) {
$pidMenuId = (new self())->where([
'title' => self::$menuTypeList[$pidText[0]],
'pid' => 0,
])->value('id');
if (empty($pidMenuId)) {
$pidMenuId = (new self())->insertGetId([
'title' => self::$menuTypeList[$pidText[0]],
'href' => '',
'icon' => 'fa fa-list',
'pid' => 0,
'status' => 1,
'system' => 0, // 系统添加
'create_time' => time(),
]);
}
$data[] = [
'title' => $vo['title'],
'href' => "{$vo['node']}/index",
'icon' => 'fa fa-list',
'target' => '_self',
'pid' => $pidMenuId,
'status' => 1,
'system' => 1, // 系统添加
'create_time' => time(),
];
}
};
if (count($data) > 0) (new self())->insertAll($data);
self::getPidMenuList(); // 刷新菜单缓存
}
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class SystemNode extends TimeModel
{
public static function getNodeTreeList(): array
{
$list = self::select()->toArray();
return self::buildNodeTree($list);
}
protected static function buildNodeTree($list): array
{
$newList = [];
$repeatString = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
foreach ($list as $vo) {
if ($vo['type'] == 1) {
$newList[] = $vo;
foreach ($list as $v) {
if ($v['type'] == 2 && str_contains($v['node'], $vo['node'] . '/')) {
$v['node'] = "{$repeatString}{$repeatString}" . $v['node'];
$newList[] = $v;
}
}
}
}
return $newList;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class SystemQuick extends TimeModel
{
protected function getOptions(): array
{
return [
'deleteTime' => 'delete_time',
];
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\admin\model;
use app\common\model\TimeModel;
class SystemUploadfile extends TimeModel
{
}