Git 文件整理

This commit is contained in:
2025-11-18 10:07:09 +08:00
parent 9ea7e69f22
commit 4bf358de6b
19 changed files with 2935 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<?php
namespace app\guildadmin\model;
use fast\Random;
use think\Model;
use think\Session;
use app\guildadmin\library\Auth;
class Admin extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $table = 'fa_vs_guild_admin';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $hidden = [
'password',
'salt'
];
public static function init()
{
self::beforeWrite(function ($row) {
$changed = $row->getChangedData();
//如果修改了用户或或密码则需要重新登录
if (isset($changed['username']) || isset($changed['password']) || isset($changed['salt'])) {
$row->token = '';
}
});
}
//创建管理员(公会创建调用)
public function createAdmin($data){
$params['salt'] = Random::alnum();
$params['username'] = $data['username'];
$params['nickname'] = $data['nickname'];
$params['password'] = md5(md5($data['password']) . $params['salt']);
$params['guild_id'] = $data['guild_id'];
$result = $this->save($params);
if ($result === false) {
return V(0,"失败", []);
}
//创建角色组
$group_data = [
'guild_id' => $data['guild_id'],
'pid' => 1,
'name' => '超级管理员',
'rules' => '*',
'status' => 'normal'
];
$group = model('guildadmin/AuthGroup')->create($group_data);
if (!$group) {
return V(0,"失败", []);
}
$dataset = [];
$dataset[] = ['uid' => $this->id, 'group_id' => $group['id']];
model('guildadmin/AuthGroupAccess')->saveAll($dataset);
}
}

View File

@@ -0,0 +1,118 @@
<?php
namespace app\guildadmin\model;
use app\admin\library\Auth;
use think\Model;
use think\Loader;
class AdminLog extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
protected $table = 'fa_vs_guild_admin_log';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = '';
//自定义日志标题
protected static $title = '';
//自定义日志内容
protected static $content = '';
//忽略的链接正则列表
protected static $ignoreRegex = [
'/^(.*)\/(selectpage|index)$/i',
];
public static function setTitle($title)
{
self::$title = $title;
}
public static function setContent($content)
{
self::$content = $content;
}
public static function setIgnoreRegex($regex = [])
{
$regex = is_array($regex) ? $regex : [$regex];
self::$ignoreRegex = array_merge(self::$ignoreRegex, $regex);
}
/**
* 记录日志
* @param string $title 日志标题
* @param string $content 日志内容
*/
public static function record($title = '', $content = '')
{
$auth = Auth::instance();
$admin_id = $auth->isLogin() ? $auth->id : 0;
$username = $auth->isLogin() ? $auth->username : __('Unknown');
// 设置过滤函数
request()->filter('trim,strip_tags,htmlspecialchars');
$controllername = Loader::parseName(request()->controller());
$actionname = strtolower(request()->action());
$path = str_replace('.', '/', $controllername) . '/' . $actionname;
if (self::$ignoreRegex) {
foreach (self::$ignoreRegex as $index => $item) {
if (preg_match($item, $path)) {
return;
}
}
}
$content = $content ?: self::$content;
if (!$content) {
$content = request()->param('') ?: file_get_contents("php://input");
$content = self::getPureContent($content);
}
$title = $title ?: self::$title;
if (!$title) {
$title = [];
$breadcrumb = Auth::instance()->getBreadcrumb($path);
foreach ($breadcrumb as $k => $v) {
$title[] = $v['title'];
}
$title = implode(' / ', $title);
}
self::create([
'title' => $title,
'content' => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,
'url' => substr(xss_clean(strip_tags(request()->url())), 0, 1500),
'admin_id' => $admin_id,
'username' => $username,
'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
'ip' => xss_clean(strip_tags(request()->ip()))
]);
}
/**
* 获取已屏蔽关键信息的数据
* @param $content
* @return array
*/
protected static function getPureContent($content)
{
if (!is_array($content)) {
return $content;
}
foreach ($content as $index => &$item) {
if (preg_match("/(password|salt|token)/i", $index)) {
$item = "***";
} else {
if (is_array($item)) {
$item = self::getPureContent($item);
}
}
}
return $content;
}
public function admin()
{
return $this->belongsTo('Admin', 'admin_id')->setEagerlyType(0);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace app\guildadmin\model;
use think\Model;
class AuthGroup extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
protected $table = 'fa_vs_guild_admin_auth_group';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function getNameAttr($value, $data)
{
return __($value);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace app\guildadmin\model;
use think\Model;
class AuthGroupAccess extends Model
{
protected $table = 'fa_vs_guild_admin_auth_group_access';
//
}

View File

@@ -0,0 +1,63 @@
<?php
namespace app\guildadmin\model;
use think\Cache;
use think\Model;
class AuthRule extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
protected $table = 'fa_vs_guild_admin_auth';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 数据自动完成字段
protected $insert = ['py', 'pinyin'];
protected $update = ['py', 'pinyin'];
// 拼音对象
protected static $pinyin = null;
protected static function init()
{
self::$pinyin = new \Overtrue\Pinyin\Pinyin('Overtrue\Pinyin\MemoryFileDictLoader');
self::beforeWrite(function ($row) {
if (isset($_POST['row']) && is_array($_POST['row']) && isset($_POST['row']['condition'])) {
$originRow = $_POST['row'];
$row['condition'] = $originRow['condition'] ?? '';
}
});
self::afterWrite(function ($row) {
Cache::rm('__guild_menu__');
});
}
public function getTitleAttr($value, $data)
{
return __($value);
}
public function getMenutypeList()
{
return ['addtabs' => __('Addtabs'), 'dialog' => __('Dialog'), 'ajax' => __('Ajax'), 'blank' => __('Blank')];
}
public function setPyAttr($value, $data)
{
if (isset($data['title']) && $data['title']) {
return self::$pinyin->abbr(__($data['title']));
}
return '';
}
public function setPinyinAttr($value, $data)
{
if (isset($data['title']) && $data['title']) {
return self::$pinyin->permalink(__($data['title']), '');
}
return '';
}
}