This commit is contained in:
yyh931018@qq.com
2022-09-08 15:32:32 +08:00
commit 1b0c8f4196
4714 changed files with 974427 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace app\admin\model;
use think\Model;
use think\Session;
class Admin extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
/**
* 重置用户密码
* @author baiyouwen
*/
public function resetPassword($uid, $NewPassword)
{
$passwd = $this->encryptPassword($NewPassword);
$ret = $this->where(['id' => $uid])->update(['password' => $passwd]);
return $ret;
}
// 密码加密
protected function encryptPassword($password, $salt = '', $encrypt = 'md5')
{
return $encrypt($password . $salt);
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace app\admin\model;
use app\admin\library\Auth;
use think\Model;
use think\Loader;
class AdminLog extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
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');
$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 ? $content : self::$content;
if (!$content) {
$content = request()->param('', null, 'trim,strip_tags,htmlspecialchars');
$content = self::getPureContent($content);
}
$title = $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(request()->url(), 0, 1500),
'admin_id' => $admin_id,
'username' => $username,
'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
'ip' => request()->ip()
]);
}
/**
* 获取已屏蔽关键信息的数据
* @param $content
* @return false|string
*/
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,39 @@
<?php
namespace app\admin\model;
use app\common\model\Area;
use think\Model;
class AuthGroup extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'city_text',
];
public function getNameAttr($value, $data)
{
return __($value);
}
public function getCityTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['city']) ? $data['city'] : '');
$list = $this->getCityList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getCityList()
{
return Area::where('pid', 655)->column('name','id');
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace app\admin\model;
use think\Model;
class AuthGroupAccess extends Model
{
//
}

View File

@@ -0,0 +1,62 @@
<?php
namespace app\admin\model;
use think\Cache;
use think\Model;
class AuthRule extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
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('__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 '';
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace app\admin\model;
use think\Model;
class Command extends Model
{
// 表名
protected $name = 'command';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'executetime_text',
'type_text',
'status_text'
];
public function getStatusList()
{
return ['successed' => __('Successed'), 'failured' => __('Failured')];
}
public function getExecutetimeTextAttr($value, $data)
{
$value = $value ? $value : $data['executetime'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : $data['type'];
$list = ['crud' => '一键生成CRUD', 'menu' => '一键生成菜单', 'min' => '一键压缩打包', 'api' => '一键生成文档'];
return isset($list[$value]) ? $list[$value] : '';
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : $data['status'];
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
protected function setExecutetimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace app\admin\model;
use think\Model;
class Grade extends Model
{
// 表名
protected $name = 'grade';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text',
'name'
];
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getNameAttr($value, $data)
{
$name = '';
if(isset($data['grade'])) $name .= $data['grade'].'年';
if(isset($data['class'])) $name .= $data['class'].'班';
return $name;
}
public function groups()
{
return $this->belongsTo('app\admin\model\auth\Group', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace app\admin\model;
use think\Model;
class Identifier extends Model
{
// 表名
protected $name = 'identifier';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function groups()
{
return $this->belongsTo('app\admin\model\auth\Group', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace app\admin\model;
use think\Model;
class Shiyou extends Model
{
// 表名
protected $name = 'shiyou';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getGenderList()
{
return ['1' => __('Male'), '0' => __('Female')];
}
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function groups()
{
return $this->belongsTo('app\admin\model\auth\Group', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace app\admin\model;
use think\Model;
class Student extends Model
{
// 表名
protected $name = 'student';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getGenderList()
{
return ['1' => __('Male'), '0' => __('Female')];
}
public function getTypeList()
{
return ['1' => __('Type 1'), '2' => __('Type 2')];
}
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function groups()
{
return $this->belongsTo('app\admin\model\auth\Group', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function grade()
{
return $this->belongsTo('app\admin\model\Grade', 'grade_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace app\admin\model;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use think\Model;
class User extends Model
{
// 表名
protected $name = 'user';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'prevtime_text',
'logintime_text',
'jointime_text'
];
public function getOriginData()
{
return $this->origin;
}
protected static function init()
{
self::beforeUpdate(function ($row) {
$changed = $row->getChangedData();
//如果有修改密码
if (isset($changed['password'])) {
if ($changed['password']) {
$salt = \fast\Random::alnum();
$row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt);
$row->salt = $salt;
} else {
unset($row->password);
}
}
});
self::beforeUpdate(function ($row) {
$changedata = $row->getChangedData();
$origin = $row->getOriginData();
if (isset($changedata['money']) && (function_exists('bccomp') ? bccomp($changedata['money'], $origin['money'], 2) !== 0 : (double)$changedata['money'] !== (double)$origin['money'])) {
MoneyLog::create(['user_id' => $row['id'], 'money' => $changedata['money'] - $origin['money'], 'before' => $origin['money'], 'after' => $changedata['money'], 'memo' => '管理员变更金额']);
}
if (isset($changedata['score']) && (int)$changedata['score'] !== (int)$origin['score']) {
ScoreLog::create(['user_id' => $row['id'], 'score' => $changedata['score'] - $origin['score'], 'before' => $origin['score'], 'after' => $changedata['score'], 'memo' => '管理员变更积分']);
}
});
}
public function getGenderList()
{
return ['1' => __('Male'), '0' => __('Female')];
}
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getPrevtimeTextAttr($value, $data)
{
$value = $value ? $value : ($data['prevtime'] ?? "");
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getLogintimeTextAttr($value, $data)
{
$value = $value ? $value : ($data['logintime'] ?? "");
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getJointimeTextAttr($value, $data)
{
$value = $value ? $value : ($data['jointime'] ?? "");
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setPrevtimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
protected function setLogintimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
protected function setJointimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
protected function setBirthdayAttr($value)
{
return $value ? $value : null;
}
public function group()
{
return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace app\admin\model;
use think\Model;
class UserGroup extends Model
{
// 表名
protected $name = 'user_group';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : $data['status'];
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace app\admin\model;
use fast\Tree;
use think\Model;
class UserRule extends Model
{
// 表名
protected $name = 'user_rule';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : $data['status'];
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public static function getTreeList($selected = [])
{
$ruleList = collection(self::where('status', 'normal')->order('weigh desc,id desc')->select())->toArray();
$nodeList = [];
Tree::instance()->init($ruleList);
$ruleList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
$hasChildrens = [];
foreach ($ruleList as $k => $v)
{
if ($v['haschild'])
$hasChildrens[] = $v['id'];
}
foreach ($ruleList as $k => $v) {
$state = array('selected' => in_array($v['id'], $selected) && !in_array($v['id'], $hasChildrens));
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
}
return $nodeList;
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace app\admin\model\auth;
use think\Model;
class Group extends Model
{
// 表名
protected $name = 'auth_group';
}