fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -12,8 +12,13 @@ declare(strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\Query;
use think\Model;
use app\common\library\ParseData;
use think\model\relation\HasOne;
/**
* @mixin \think\Model
@@ -27,9 +32,9 @@ class Admin extends \think\Model
/**
* 关联管理组
*
* @return \think\model\relation\HasOne
* @return HasOne
*/
public function group(): \think\model\relation\HasOne
public function group(): HasOne
{
return $this->hasOne(AdminGroup::class, 'id', 'group_id');
}
@@ -38,10 +43,10 @@ class Admin extends \think\Model
* 根据用户名/密码 进行登录判断
* @param $user
* @param $pwd
* @return Admin|array|mixed|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function checkLogin($user, $pwd)
{
@@ -59,10 +64,10 @@ class Admin extends \think\Model
* 根据用户名/验证码 进行数据查找
* @param $user
* @param $code
* @return Admin|array|mixed|Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function checkForget($user, $code)
{
@@ -76,36 +81,4 @@ class Admin extends \think\Model
$where[] = ['valicode', '=', $code];
return Admin::where($where)->find();
}
/**
* 设置创建IP
*/
public function setCreateIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取创建IP
*/
public function getCreateIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 设置登录IP
*/
public function setLoginIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取登录IP
*/
public function getLoginIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
}

View File

@@ -6,11 +6,11 @@ use think\Model;
/**
* login_log
* admin_log
* 登录日志
* @package app\admin\model\system
*/
class LoginLog extends Model
class AdminLog extends Model
{
// 定义时间戳字段名
@@ -18,8 +18,4 @@ class LoginLog extends Model
protected $updateTime = 'update_time';
protected $deleteTime = false;
}

View File

@@ -0,0 +1,66 @@
<?php
namespace app\common\model\system;
use think\Model;
use think\model\relation\HasOne;
use Webman\Event\Event;
/**
* admin_notice
* 管理员通知
* @package app\admin\model\system
*/
class AdminNotice extends Model
{
// 定义时间戳字段名
protected $updateTime = 'update_time';
protected $deleteTime = false;
/**
* 获取管理员
* @access public
* @return HasOne
*/
public function admin(): HasOne
{
return $this->hasOne(Admin::class,'id','send_id')->bind(['nickname','face']);
}
/**
* @param array $data
* @param string $msgType
* @return false|void
* @throws \Exception
*/
public static function sendNotice(array $data = [], string $msgType = 'array')
{
if (!$data) {
return false;
}
$model = new self();
if ($msgType == 'array') {
$model->saveAll($data);
} else {
$model->insert($data);
}
// 钩子消息推送
Event::emit('sendAdminNotice', $data);
}
/*
* 获取时间戳
* @return false|int
*/
public function getCreateTimeAttr($time): string
{
if (!empty($time) && strlen($time) >= 10) {
$time = published_date($time);
}
return $time;
}
}

View File

@@ -3,6 +3,9 @@ declare (strict_types=1);
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
use think\model\concern\SoftDelete;
@@ -25,17 +28,18 @@ class AdminRules extends Model
* @param array $array 引用数组
* @param int $blank 替换字符
* @param int $level 栏目等级
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getListRule(string $tips = '', int $pid = 0, array &$array = [], int $blank = 0, int $level = 0): array
{
$result = self::where('pid', $pid)->select()->toArray();
foreach ($result as $key => $value) {
if (!empty($tips)) {
$catename = $tips . $value['title'];
$value['title'] = str_repeat('', $blank) . $catename;
$cateName = $tips . $value['title'];
$value['title'] = str_repeat('', $blank) . $cateName;
}
$value['_level'] = $level;
$array[] = $value;
@@ -48,11 +52,10 @@ class AdminRules extends Model
/**
* 返回栏目树形结构
*
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return array|void
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getListTree()
{
@@ -71,11 +74,11 @@ class AdminRules extends Model
* @param array $list 菜单列表
* @param string $note
* @param mixed $parent 父类的name或pid
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function createMenu(array $list = [], string $note = '', $parent = 0)
public static function createMenu(array $list = [], string $note = '',mixed $parent = 0)
{
$fields = array_flip(['title', 'router', 'alias', 'type', 'icon', 'note', 'status']);
foreach ($list as $key => $item) {
@@ -104,11 +107,11 @@ class AdminRules extends Model
* 启用菜单
* @param string $name
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function enabled(string $name)
public static function enabled(string $name): void
{
$list = self::getNoteByMenus($name);
foreach ($list as $item) {
@@ -121,11 +124,11 @@ class AdminRules extends Model
* @param string $name
* @param bool $force
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function disabled(string $name, bool $force = false)
public static function disabled(string $name, bool $force = false): void
{
$list = self::getNoteByMenus($name);
foreach ($list as $item) {
@@ -137,9 +140,9 @@ class AdminRules extends Model
* 导出指定名称的菜单规则
* @param string $name
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function export(string $name): array
{
@@ -168,12 +171,12 @@ class AdminRules extends Model
/**
* 根据名称获取规则IDS
* @param string $name
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return object|mixed|void
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getNoteByMenus(string $name)
public static function getNoteByMenus(string $name = '')
{
return self::withTrashed()->where('note', $name)->select();
}

View File

@@ -12,6 +12,9 @@ declare(strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
/**
@@ -26,13 +29,12 @@ class Config extends Model
/**
* 获取系统配置
*
* @param string $name
* @param bool $group
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function all(string $name = '', bool $group = false): array
{

View File

@@ -3,8 +3,11 @@ declare (strict_types = 1);
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\Query;
use think\Model;
use think\facade\Db;
use think\model\concern\SoftDelete;
/**
@@ -21,21 +24,23 @@ class Department extends Model
/**
* 树形分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getListTree(): array
{
$array = self::select()->toArray();
if (is_array($array) && !empty($array)) {
if (!empty($array)) {
return list_to_tree($array);
}
return [];
}
// 字段修改器
/**
* 字段修改器
*/
public function setSortAttr($value)
{
if (is_empty($value)) {

View File

@@ -4,9 +4,11 @@ declare(strict_types=1);
namespace app\common\model\system;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\Query;
use think\Model;
use think\model\concern\SoftDelete;
@@ -39,12 +41,12 @@ class Dictionary extends Model
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getValueList(string $value = '')
public static function getValueList(string $value = ''): array
{
$list = [];
$data = self::where(['pid' => 0,'value' => $value])->find();
if (!empty($data)) {
$list = self::where('pid', $data['id'])->select();
$list = self::where('pid', $data['id'])->select()->toArray();
}
return $list;

View File

@@ -22,7 +22,7 @@ class Jobs extends Model
public static function getListTree()
{
$array = self::select()->toArray();
if (is_array($array) && !empty($array)) {
if (!empty($array)) {
return list_to_tree($array);
}
}

View File

@@ -1,20 +0,0 @@
<?php
declare (strict_types = 1);
namespace app\common\model\system;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin \think\Model
*/
class Project extends Model
{
use SoftDelete;
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
}

View File

@@ -30,26 +30,4 @@ class SystemLog extends Model
}
}
}
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public function setIPAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public function getIPAttr($ip)
{
return ParseData::getIPAttr($ip);
}
}

View File

@@ -2,9 +2,12 @@
declare (strict_types = 1);
namespace app\common\model\system;
use Psr\SimpleCache\InvalidArgumentException;
use think\Model;
use app\common\library\ParseData;
use think\model\concern\SoftDelete;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
/**
* @mixin \think\Model
@@ -17,8 +20,11 @@ class User extends Model
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
// 定义第三方关联
public function third(): \think\model\relation\HasMany
/**
* 定义第三方登录
* @return HasMany
*/
public function third(): HasMany
{
return $this->hasMany(UserThird::class,'user_id');
}
@@ -26,9 +32,9 @@ class User extends Model
/**
* 关联用户组
*
* @return \think\model\relation\HasOne
* @return HasOne
*/
public function group(): \think\model\relation\HasOne
public function group(): HasOne
{
return $this->hasOne(UserGroup::class,'id','group_id');
}
@@ -64,12 +70,13 @@ class User extends Model
*/
public static function onAfterUpdate(object $model)
{}
/**
* 获取头像
* @param string $value
* @param array $data
* @return string
* @throws InvalidArgumentException
*/
public function getAvatarAttr(string $value, array $data): string
{
@@ -97,6 +104,7 @@ class User extends Model
* @param string $value
* @param array $data
* @return string
* @throws InvalidArgumentException
*/
public function setAvatarAttr(string $value, array $data): string
{
@@ -115,66 +123,6 @@ class User extends Model
return $value;
}
/**
* 设置创建IP
* @param $ip
* @return mixed
*/
public function setCreateIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取创建IP
* @param $ip
* @return mixed
*/
public function getCreateIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 设置登录IP
* @param $ip
* @return mixed
*/
public function setLoginIpAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取登录IP
*/
public function getLoginIpAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public function setIPAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public function getIPAttr($ip)
{
return ParseData::getIPAttr($ip);
}
/**
* 减少会员积分
*

View File

@@ -3,10 +3,9 @@ declare (strict_types = 1);
namespace app\common\model\system;
use think\db\exception\DataNotFoundException;
use think\Model;
use think\facade\Db;
use think\model\concern\SoftDelete;
use think\model\relation\HasMany;
/**
* @mixin \think\Model
@@ -19,36 +18,12 @@ class UserGroup extends Model
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 关联用户组
*
* @return int|\think\model\relation\HasMany
* @return HasMany
*/
public function userTotal()
public function userTotal(): HasMany
{
return $this->hasMany(User::class,'group_id','id');
}
/**
* 获取用户组
*
* @param integer $id
* @param boolean $mark
* @return void|array
* @throws DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function ToObtain(int $id = 0, bool $mark = true)
{
$groupList = system_cache('groupList');
if (empty($groupList)) {
$groupList = self::select()->toArray();
system_cache('groupList',$groupList,86400);
}
return $groupList;
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace app\common\model\system;
use think\Model;
/**
* user_log
* 登录日志
* @package app\admin\model\system
*/
class UserLog extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $deleteTime = false;
/**
* 用户登录日志
* @param string $error
* @param string $nickname
* @param int $login_id
* @param int $status
*/
public static function write(string $error, string $nickname,int $login_id = 0, int $status = 0)
{
$userAgent = \request()->header('user-agent');
if (preg_match('/.*?\((.*?)\).*?/', $userAgent, $matches)) {
$user_os = substr($matches[1], 0, strpos($matches[1], ';'));
} else {
$user_os = '未知';
}
$user_browser = preg_replace('/[^(]+\((.*?)[^)]+\) .*?/','$1',$userAgent);
$data = [
'login_id' => $login_id,
'login_ip' => request()->getRealIp(),
'login_agent' => $userAgent,
'login_os' => $user_os,
'login_browser' => $user_browser,
'nickname' => $nickname ?? '未知',
'error' => $error,
'status' => $status,
];
self::create($data);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace app\common\model\system;
use think\Model;
use Webman\Event\Event;
/**
* user_notice
* 用户消息
* @package app\admin\model\system
*/
class UserNotice extends Model
{
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $deleteTime = false;
/**
* 消息发送
* @param array $data
* @param string $msgType
* @return false|void
* @throws \Exception
*/
public static function sendNotice(array $data = [], string $msgType = 'array')
{
if (!$data) {
return false;
}
$model = new self();
if ($msgType == 'array') {
$model->saveAll($data);
} else {
$model->insert($data);
}
// 钩子消息推送
Event::emit('sendUserNotice', $data);
}
}

View File

@@ -17,26 +17,4 @@ class UserValidate extends Model
// 定义时间戳字段名
protected $createTime = 'create_time';
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public function setIPAttr($ip)
{
return ParseData::setIPAttr($ip);
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public function getIPAttr($ip)
{
return ParseData::getIPAttr($ip);
}
}