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

@@ -5,23 +5,33 @@ namespace app\common\exception;
use app\common\model\system\SystemLog;
use Psr\SimpleCache\InvalidArgumentException;
use support\exception\BusinessException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Exception\ExceptionHandler;
use Webman\Http\Request;
use Webman\Http\Response;
use Throwable;
class ExceptionHandle extends \Webman\Exception\ExceptionHandler
class ExceptionHandle extends ExceptionHandler
{
public $dontReport = [
BusinessException::class,
];
/**
*
* @param Throwable $exception
* @return void|mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function report(Throwable $exception)
{
try {
if (saenv('system_exception') && !empty($exception->getMessage())) {
if (saenv('system_exception')
&& !empty($exception->getMessage())) {
$data = [
'module' => request()->app,
'controller' => request()->controller,
@@ -32,11 +42,9 @@ class ExceptionHandle extends \Webman\Exception\ExceptionHandler
'ip' => request()->getRealIp(),
'name' => session('AdminLogin.name'),
];
if (empty($data['name'])) {
$data['name'] = 'system';
}
$data['type'] = 1;
$data['code'] = $exception->getCode();
$data['file'] = $exception->getFile();
@@ -50,6 +58,11 @@ class ExceptionHandle extends \Webman\Exception\ExceptionHandler
parent::report($exception);
}
/**
* @param Throwable $exception
* @param Request $request
* @return Response
*/
public function render(Request $request, Throwable $exception): Response
{
if (!file_exists(root_path(). '.env')) {

View File

@@ -0,0 +1,156 @@
<?php
namespace app\common\gateway;
use GatewayWorker\Lib\Gateway;
use support\Log;
use Webman\Event\Event;
/**
* IM网关通讯接口
* Class Events
* @package app\common\gateway
* @Author Meystack <
*/
class Events
{
/**
* onWorkerStart 事件回调
* @param $worker
* @return void
*/
public static function onWorkerStart($worker): void
{
Event::emit('onWorkerStart', $worker);
}
/**
* 当客户端连接上gateway进程时(TCP三次握手完毕时)触发
* @param $client_id
* @return void
*/
public static function onConnect($client_id): void
{
$data = [
'type' => 'init',
'client_id' => $client_id,
];
Gateway::sendToCurrentClient(json_encode($data));
}
/**
* 当客户端连接上gateway完成websocket握手时触发
* @param $client_id
* @param $data
* @return void
*/
public static function onWebSocketConnect($client_id, $data): void
{
Event::emit('onWebSocketConnect', $client_id, $data);
}
/**
* 当客户端发来数据(Gateway进程收到数据)后触发
* @param $client_id
* @param $message
* @return void
*/
public static function onMessage($client_id, $message): void
{}
/**
* 推送消息
* @param $client_id
* @param array $message
* @return void
*/
public static function onSendMsg($client_id, array $message = []): void
{
Gateway::sendToUid($client_id, json_encode($message, JSON_UNESCAPED_UNICODE));
}
/**
* 绑定用户UID
* @param $client_id
* @param $uid
* @param string $type
* @return bool
*/
public static function onBindUid($client_id, $uid, string $type = 'admin'): bool
{
if (empty($client_id) || empty($uid)) {
return false;
}
$uid = $type . '_' . $uid;
try {
Gateway::bindUid($client_id, $uid);
} catch (\Exception $e) {
Log::info('绑定用户UID失败' . $e->getMessage());
return false;
}
return true;
}
/**
* 通过UID获取socketID
* @param $uid
* @param string $type
* @return array
*/
public static function onGetClientByUid($uid, string $type = 'admin'): array
{
if (empty($uid)) {
return [];
}
$uid = $type . '_' . $uid;
return Gateway::getClientIdByUid($uid);
}
/**
* 当用户断开连接时触发
* @param $client_id
* @param $uid
* @param string $type
* @return bool
*/
public static function onUnbindUid($client_id, $uid, string $type = 'admin'): bool
{
if (empty($client_id) || empty($uid)) {
return false;
}
$uid = $type . '_' . $uid;
try {
Gateway::unbindUid($client_id, $uid);
} catch (\Exception $e) {
Log::info('解绑用户UID失败' . $e->getMessage());
return false;
}
return true;
}
/**
* 用户加入群组
* @param $client_id
* @param $group_id
* @return void
*/
public static function onJoinGroup($client_id, $group_id): void
{
Gateway::joinGroup($client_id, $group_id);
}
/**
* 当客户端断开连接时触发
* @param $client_id
* @return void
*/
public static function onClose($client_id): void
{
Event::emit('onWebSocketClose', $client_id);
}
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\library;
use app\common\model\system\UserLog;
use system\Random;
use support\Response;
use think\facade\Cache;
@@ -25,30 +26,30 @@ class Auth
* token令牌
* @var string
*/
public $token = null;
public string $token;
/**
* 用户数据
* @var object|array
*/
public $userInfo = null;
public mixed $userData;
/**
* 保活时间
* @var string
* @var int
*/
protected $keepTime = 604800;
protected int $keepTime = 604800;
/**
* 错误信息
* @var string
*/
protected $_error = '';
protected string $_error = '';
/**
* @var object 对象实例
*/
protected static $instance = null;
protected static $instance;
/**
* 类构造函数
@@ -78,7 +79,7 @@ class Auth
/**
* 用户注册
* @param array $post
* @return false|mixed
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DbException
*/
@@ -127,9 +128,9 @@ class Auth
$post['pwd'] = encryptPwd($post['pwd'], $post['salt']);
}
$this->userInfo = UserModel::create($post);
$this->userData = UserModel::create($post);
return $this->responseToken($this->userInfo);
return $this->responseToken($this->userData);
} catch (\Throwable $th) {
$this->setError($th->getMessage());
@@ -154,31 +155,36 @@ class Auth
} else {
$where[] = ['mobile', '=', htmlspecialchars(trim($nickname))];
}
$this->userInfo = UserModel::where($where)->find();
$this->userData = UserModel::where($where)->find();
if (!empty($this->userInfo)) {
if (!empty($this->userData)) {
$uPwd = encryptPwd($pwd, $this->userData['salt']);
if ($this->userData['pwd'] !== $uPwd) {
$uPwd = encryptPwd($pwd, $this->userInfo['salt']);
if ($this->userInfo['pwd'] !== $uPwd) {
$this->setError('用户名或密码错误');
UserLog::write($this->getError(), $this->userData->nickname, $this->userData->id);
return false;
}
if (!$this->userInfo['status']) {
if (!$this->userData['status']) {
$this->setError('用户异常或未审核,请联系管理员');
UserLog::write($this->getError(), $this->userData->nickname, $this->userData->id);
return false;
}
// 更新登录数据
$userUpdate = [
'id' => $this->userInfo['id'],
'id' => $this->userData['id'],
'login_time' => time(),
'login_ip' => request()->getRealIp(),
'login_count' => $this->userInfo['login_count'] + 1,
'login_count' => $this->userData['login_count'] + 1,
];
if (UserModel::update($userUpdate)) {
return $this->responseToken($this->userInfo);
Event::emit('userLoginSuccess', $this->userData);
UserLog::write('登录成功', $this->userData->nickname, $this->userData->id, 1);
return $this->responseToken($this->userData);
}
}
@@ -199,12 +205,11 @@ class Auth
if (!$token) {
return false;
}
$uid = $this->checkToken($token);
if (!empty($uid)) {
$this->token = $token;
$this->userInfo = UserModel::find($uid);
$this->userData = UserModel::with('group')->find($uid);
return true;
}
@@ -224,20 +229,20 @@ class Auth
/**
*
* 返回前端令牌
* @param mixed $userInfo
* @param mixed $userData
* @param bool $token
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function responseToken($userInfo, bool $token = false)
public function responseToken($userData, bool $token = false)
{
$this->token = $token ? $this->getToken() : $this->buildToken($userInfo['id']);
$this->token = $token ? $this->getToken() : $this->buildToken($userData['id']);
$response = response();
$response->cookie('uid', $userInfo['id'],$this->keepTime, '/');
$response->cookie('uid', $userData['id'],$this->keepTime, '/');
$response->cookie('token', $this->token,$this->keepTime, '/');
$response->cookie('nickname', $userInfo['nickname'],$this->keepTime, '/');
Cache::set($this->token, $userInfo['id'], $this->keepTime);
Event::emit("userLoginSuccess", $userInfo);
$response->cookie('nickname', $userData['nickname'],$this->keepTime, '/');
Cache::set($this->token, $userData['id'], $this->keepTime);
Event::emit("userLoginSuccess", $userData);
return $response;
}
@@ -266,13 +271,13 @@ class Auth
* 校验token
* @access protected
* @param $token
* @return mixed
* @return void
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function checkToken($token)
{
$userId = Cache::get($token);
return $userId ?? false;
$user_id = Cache::get($token);
return $user_id ?? false;
}
/**
@@ -287,8 +292,9 @@ class Auth
/**
* 设置错误
* @param string $error 信息信息
* @return void
*/
protected function setError(string $error)
protected function setError(string $error): void
{
$this->_error = $error;
}

View File

@@ -13,7 +13,6 @@ class DataBase {
/**
* 导入目录下Install.sql文件
* @param string $sqlPath
* @return void
*/
public static function importSql(string $sqlPath)
{
@@ -28,8 +27,7 @@ class DataBase {
}
try {
Db::getPdo()->exec($line);
} catch (\Throwable $th) {
}
} catch (\Throwable $th) {}
}
}
}

View File

@@ -14,8 +14,15 @@ declare(strict_types=1);
namespace app\common\library;
use app\common\model\system\UserValidate;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use Psr\SimpleCache\InvalidArgumentException;
use system\Random;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\db\Query;
use think\Model;
/**
* 邮件发送类
@@ -32,28 +39,28 @@ class Email
/**
* @PHPMailer 对象实例
*/
protected $mail = [];
protected mixed $mail;
/**
* 验证码对象
* @var UserValidate
* @var mixed
*/
private $userVModel;
private mixed $userVModel;
/**
* 验证码过期时间
* @var string
* @var int
*/
private $expireTime = 5; //验证码过期时间(分钟)
private int $expireTime = 5; //验证码过期时间(分钟)
/**
* 错误信息
* @var string
*/
protected $_error = '';
protected string $_error = '';
//默认配置
protected $config = [
protected array $config = [
'smtp_debug' => false, // 是否调试
'smtp_host' => 'smtp.163.com', // 服务器地址
'smtp_port' => 587, // 服务器端口
@@ -65,6 +72,11 @@ class Email
/**
* 类构造函数
* class constructor.
* @throws Exception
* @throws InvalidArgumentException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function __construct()
{
@@ -105,6 +117,11 @@ class Email
* @access public
* @param array $options 参数
* @return EMAIL
* @throws DataNotFoundException
* @throws DbException
* @throws Exception
* @throws InvalidArgumentException
* @throws ModelNotFoundException
*/
public static function instance($options = [])
{
@@ -158,10 +175,10 @@ class Email
/**
* 设置收件人
* @param mixed $email 收件人,多个收件人以,进行分隔
* @param string $name 收件人名称
* @param $email
* @param string $name
* @return $this
* @throws \PHPMailer\PHPMailer\Exception
* @throws Exception
*/
public function to($email, string $name = ''): Email
{
@@ -191,7 +208,7 @@ class Email
/**
* 构建Email地址
* @param mixed $emails Email数据
* @param $emails
* @return array
*/
protected function buildAddress($emails): array
@@ -209,10 +226,10 @@ class Email
/**
* 获取最后一条
* @param string $email
* @return UserValidate|array|mixed|\think\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 function getLast(string $email)
{
@@ -297,7 +314,7 @@ class Email
* 设置错误
* @param string $error 信息信息
*/
protected function setError(string $error)
protected function setError(string $error): void
{
$this->_error = $error;
}
@@ -321,13 +338,10 @@ class Email
}
/**
* 测试发送
* @return boolean
* @throws \PHPMailer\PHPMailer\Exception
* 测试发送邮件
*/
public function testEmail($config)
{
if (empty($config) || !is_array($config)) {
return '缺少必要的信息';
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\library;
use support\Log;
use system\Random;
/**
@@ -27,7 +28,7 @@ class Ftp
protected static $instance = null;
//默认配置
protected $config = [
protected array $config = [
'upload_ftp_host' => '127.0.0.1', // 服务器地址
'upload_ftp_port' => 21, // 服务器端口
'upload_ftp_user' => 'username', // FTP用户名
@@ -52,7 +53,6 @@ class Ftp
* @param array $options 参数
* @return Ftp
*/
public static function instance($options = [])
{
if (is_null(self::$instance)) {
@@ -120,7 +120,6 @@ class Ftp
*/
public function ftpTest(array $config): bool
{
$connect = @ftp_connect($config['host'], (int)$config['port']) or die('Could not connect');
if (@ftp_login($connect, $config['user'], $config['pass'])) {
@@ -145,11 +144,11 @@ class Ftp
}
} catch (\Throwable $th) {
return $th->getMessage();
Log::info('upload ftp ' . $th->getMessage());
return false;
}
}
return false;
}
}

View File

@@ -15,12 +15,10 @@ class Images
* @access public
* @param string $filename 文件路径
* @param array $config 配置数组
* @return mixed
* @throws \Exception
*/
public function waterMark(string $filename, array $config)
{
try {
// 获取文件信息
@@ -48,7 +46,6 @@ class Images
}
$ImageWaterInfo = getimagesize($config['upload_water_img']);
// 对比图片大小
if ($ImageWaterInfo[0] >= $ImageInfo[0] ||
$ImageWaterInfo[1] >= $ImageInfo[1]) {
@@ -74,6 +71,7 @@ class Images
* @param bool $avatar
* @param bool $newfile
* @return Image|void
* @throws \Exception
*/
public function thumb($filepath, $filename, $config, bool $avatar = false, bool $newfile = true)
{
@@ -95,10 +93,8 @@ class Images
// 保留原来的图片 新文件名建议源文件名+_thumb.jpg 格式
$resource = $filepath . '/thumb_' . $filename;
}
$resThumb = $Image->thumb($config['upload_thumb_w'], $config['upload_thumb_h'], 6)->save($resource, NULL, 90);
}
return $resThumb;
}
} catch (\Exception $e) {

View File

@@ -1,164 +0,0 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\common\library;
/**
* Jwt简易验证类
* Class Jwt
* @package app\common\library
* @author meystack <
*/
class Jwt
{
/**
* @var object 对象实例
*/
protected static $instance = null;
// 头部信息
private static $header = array(
'alg' => 'HS256', //生成signature的算法
'typ' => 'JWT' //类型
);
private static $key = '123456';
/**
* 类构造函数
* class constructor.
*/
public function __construct()
{
}
/**
* 初始化
* @access public
* @param array $options 参数
* @return Jwt
*/
public static function instance($options = [])
{
if (is_null(self::$instance)) {
self::$instance = new static($options);
}
// 返回实例
return self::$instance;
}
/**
* 获取jwt token
* @param $payload
* [
* 'iss'=>'jwt_admin', // 该JWT的签发者
* 'iat'=>time(), // 签发时间
* 'exp'=>time()+7200, // 过期时间
* 'nbf'=>time()+60, // 该时间之前不接收处理该Token
* 'sub'=>'www.admin.com', // 面向的用户
* 'jti'=>md5(uniqid('JWT').time()) // 该Token唯一标识
* ]
* @return bool|string
*/
public static function getToken($payload)
{
if (is_array($payload)) {
$base64header = self::base64UrlEncode(json_encode(self::$header, JSON_UNESCAPED_UNICODE));
$base64payload = self::base64UrlEncode(json_encode($payload, JSON_UNESCAPED_UNICODE));
return $base64header . '.' . $base64payload . '.' . self::signature($base64header . '.' . $base64payload, self::$key, self::$header['alg']);
} else {
return false;
}
}
/**
* 验证token是否有效,默认验证exp,nbf,iat时间
* @param string $Token 需要验证的token
* @return bool|string
*/
public static function verifyToken(string $Token)
{
$tokens = explode('.', $Token);
if (count($tokens) != 3)
return false;
list($base64header, $base64payload, $sign) = $tokens;
// 获取jwt算法
$base64DecodeHeader = json_decode(self::base64UrlDecode($base64header), JSON_OBJECT_AS_ARRAY);
if (empty($base64DecodeHeader['alg']))
return false;
// 签名验证
if (self::signature($base64header . '.' . $base64payload, self::$key, $base64DecodeHeader['alg']) !== $sign)
return false;
$payload = json_decode(self::base64UrlDecode($base64payload), JSON_OBJECT_AS_ARRAY);
// 签发时间大于当前服务器时间验证失败
if (isset($payload['iat']) && $payload['iat'] > time())
return false;
// 过期时间小宇当前服务器时间验证失败
if (isset($payload['exp']) && $payload['exp'] < time())
return false;
// 该nbf时间之前不接收处理该Token
if (isset($payload['nbf']) && $payload['nbf'] > time())
return false;
return $payload;
}
/**
* base64UrlEncode https://jwt.io/ 中base64UrlEncode编码实现
* @param string $input 需要编码的字符串
* @return string
*/
private static function base64UrlEncode(string $input): string
{
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
/**
* base64UrlEncode https://jwt.io/ 中base64UrlEncode解码实现
* @param string $input 需要解码的字符串
* @return bool|string
*/
private static function base64UrlDecode(string $input)
{
$remainder = strlen($input) % 4;
if ($remainder) {
$addLen = 4 - $remainder;
$input .= str_repeat('=', $addLen);
}
return base64_decode(strtr($input, '-_', '+/'));
}
/**
* HMACSHA256签名 https://jwt.io/ 中HMACSHA256签名实现
* @param string $input 为base64UrlEncode(header).".".base64UrlEncode(payload)
* @param string $key
* @param string $alg 算法方式
* @return string
*/
private static function signature(string $input, string $key, string $alg = 'HS256'): string
{
$alg_config = array(
'HS256' => 'sha256'
);
return self::base64UrlEncode(hash_hmac($alg_config[$alg], $input, $key, true));
}
}

View File

@@ -77,7 +77,7 @@ class ParseData
* @access public
* @param string $content
* @return string
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws InvalidArgumentException
*/
public static function setContentAttr(string $content): string
{
@@ -93,7 +93,7 @@ class ParseData
* @access public
* @param string $content
* @return string
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws InvalidArgumentException
*/
public static function getContentAttr(string $content): string
{
@@ -124,7 +124,7 @@ class ParseData
* @param $data
* @param bool $ready
* @return string
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws InvalidArgumentException
*/
public static function setImageAttr(string $image, $data, bool $ready = false): string
{
@@ -143,7 +143,8 @@ class ParseData
* 获取图片链接
* @access public
* @param string $image
* @return string
* @return string
* @throws InvalidArgumentException
*/
public static function getImageAttr(string $image): string
{
@@ -178,36 +179,6 @@ class ParseData
return $image;
}
/**
* 获取IP转换
* @access public
* @param $ip
* @return mixed
*/
public static function getIPAttr($ip)
{
if (!empty($ip)) {
$ip = long2ip($ip);
}
return $ip;
}
/**
* 设置IP转换
* @access public
* @param $ip
* @return mixed
*/
public static function setIPAttr($ip)
{
if (!empty($ip)) {
$ip = ip2long($ip);
}
return $ip;
}
/**
* 设置独立模板
* @access public

View File

@@ -0,0 +1,74 @@
<?php
declare (strict_types=1);
namespace app\common\library;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
use Endroid\QrCode\Label\Alignment\LabelAlignmentCenter;
use Endroid\QrCode\Label\Font\NotoSans;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\Result\ResultInterface;
/**
* 生成二维码
* Class Qrcode
* @package app\common\library
* @author meystack
*/
class Qrcode
{
/**
* @param array $params
* @return ResultInterface
*/
public static function build(array $params = []): ResultInterface
{
$params['data'] = $params['data'] ?? 'Hello world!';
$params['size'] = $params['size'] ?? 280;
$params['margin'] = $params['margin'] ?? 0;
$params['format'] = $params['format'] ?? 'png';
$params['foreground'] = $params['foreground'] ?? "#000000";
$params['background'] = $params['background'] ?? "#ffffff";
$params['label'] = $params['label'] ?? '';
$params['logo'] = $params['logo'] ?? '';
$params['logosize'] = $params['logosize'] ?? 50;
// 二维码颜色
list($r, $g, $b) = sscanf($params['foreground'], "#%02x%02x%02x");
$foregroundColor = new Color($r, $g, $b);
// 背景色调
list($r, $g, $b) = sscanf($params['background'], "#%02x%02x%02x");
$backgroundColor = new Color($r, $g, $b);
// 创建对象
$qrcode = Builder::create()
->writer(new PngWriter())
->writerOptions([])
->data($params['data'])
->encoding(new Encoding('UTF-8'))
->errorCorrectionLevel(new ErrorCorrectionLevelHigh())
->size((int)$params['size'])
->margin((int)$params['margin'])
->roundBlockSizeMode(new RoundBlockSizeModeMargin())
->foregroundColor($foregroundColor)
->backgroundColor($backgroundColor);
// 设置LOGO
if (!empty($params['logo'])) {
$qrcode = $qrcode->logoPath($params['logo'])
->logoResizeToWidth($params['logosize'])
->logoResizeToHeight($params['logosize']);
}
// 返回实例对象
return $qrcode->labelText($params['label'])
->labelFont(new NotoSans(20))
->labelAlignment(new LabelAlignmentCenter())
->build();
}
}

View File

@@ -11,7 +11,6 @@ declare (strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\library;
/**
* RESULT代码文件
*/
@@ -107,6 +106,12 @@ class ResultCode
'msg' => '当前用户已被禁用',
];
const PLEASELOGININ = [
'code' => -111,
'status' => 'PLEASELOGININ',
'msg' => '请登录后操作',
];
const ACCESS_TOKEN_TIMEOUT = [
'code' => -300,
'status' => 'ACCESS_TOKEN_TIMEOUT',

View File

@@ -12,6 +12,10 @@ declare (strict_types=1);
namespace app\common\library;
use app\common\model\system\UserValidate;
use Psr\SimpleCache\InvalidArgumentException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Event\Event;
/**
@@ -20,28 +24,42 @@ use Webman\Event\Event;
*/
class Sms
{
/**
* 默认配置
* @var array
*/
protected array $config = [];
/**
* 错误信息
* @var string
*/
protected string $_error = '';
/**
* 验证码对象
* @var mixed
*/
protected string $smsType = 'alisms';
/**
* 验证码过期时间
* @var int
*/
private int $expireTime = 5; //验证码过期时间(分钟)
/**
* @var object 对象实例
*/
protected static $instance = null;
// 默认配置
protected $config = [];
// 错误信息
protected $_error = '';
protected $smsType = 'alisms';
/**
* 验证码过期时间
* @var string
*/
private $expireTime = 5; //验证码过期时间(分钟)
/**
* 类构造函数
* class constructor.
* @throws InvalidArgumentException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function __construct()
{
@@ -56,8 +74,11 @@ class Sms
* @access public
* @param array $options 参数
* @return self
* @throws DataNotFoundException
* @throws DbException
* @throws InvalidArgumentException
* @throws ModelNotFoundException
*/
public static function instance($options = [])
{
if (is_null(self::$instance)) {
@@ -164,7 +185,7 @@ class Sms
* 设置错误
* @param string $error 信息信息
*/
protected function setError(string $error)
protected function setError(string $error): void
{
$this->_error = $error;
}

View File

@@ -11,10 +11,14 @@ declare (strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\library;
use Psr\SimpleCache\InvalidArgumentException;
use system\Http;
use app\common\model\system\Attachment;
use app\common\validate\system\UploadFile;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Event\Event;
/**
@@ -32,46 +36,50 @@ class Upload
/**
* 文件类型
*/
protected $fileClass;
protected mixed $fileClass;
/**
* 文件名称
*/
protected $filename;
protected mixed $filename;
/**
* 文件保存路径
*/
protected $filepath;
protected mixed $filepath;
/**
* 文件全路径名称
*/
protected $resource;
protected mixed $resource;
/**
* 附件信息
*/
protected $fileInfo = [];
protected mixed $fileInfo = [];
/**
* 图形对象实例
*/
protected $Images;
protected mixed $Images;
/**
* 错误信息
*/
protected $_error = '';
protected string $_error = '';
/**
* 配置文件
*/
protected $config = [];
protected mixed $config = [];
/**
* 类构造函数
* class constructor.
* @throws InvalidArgumentException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function __construct()
{
@@ -86,6 +94,10 @@ class Upload
* @access public
* @param array $options 参数
* @return self
* @throws DataNotFoundException
* @throws DbException
* @throws InvalidArgumentException
* @throws ModelNotFoundException
*/
public static function instance(array $options = [])
{
@@ -100,7 +112,7 @@ class Upload
/**
* 文件上传
* @return array|false
* @throws \Exception
* @throws \Exception|InvalidArgumentException
*/
public function upload()
{
@@ -159,6 +171,7 @@ class Upload
* @param object $file
* @param array $params
* @return array|false
* @throws InvalidArgumentException
*/
public function multiPartUpload(object $file, array $params = [])
{
@@ -199,6 +212,7 @@ class Upload
* 分片合并
* @param array $params
* @return array|false
* @throws InvalidArgumentException
*/
public function multiMarge(array $params = [])
{
@@ -284,6 +298,7 @@ class Upload
* 文件下载函数
* @param string|null $url
* @return array|false
* @throws InvalidArgumentException
*/
public function download(string $url = null)
{
@@ -323,7 +338,7 @@ class Upload
/**
* 删除本地文件
* @return void
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function uploadAfterDelete()
{
@@ -367,7 +382,7 @@ class Upload
/**
* 获取文件扩展名
* @param object $file
* @return false|mixed|string
* @return false|string
*/
public function getFileExt(object $file)
{
@@ -416,7 +431,7 @@ class Upload
* @param string|null $dir
* @return void
*/
public function getFileSavePath(object $file, string $dir = null)
public function getFileSavePath(object $file, string $dir = null): void
{
$this->filename = uniqid() . '.' . strtolower($file->getUploadExtension());
$this->filepath = DS . $this->config['upload_path'] . DS . ($dir ?? $this->fileClass) . DS . date($this->config['upload_style']);
@@ -428,7 +443,7 @@ class Upload
* @param string $filePath
* @param array $extend
* @return array
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function success(string $msg, string $filePath, array $extend = []): array
{
@@ -464,7 +479,7 @@ class Upload
* 设置错误
* @param string $error 信息信息
*/
protected function setError(string $error)
protected function setError(string $error): void
{
$this->_error = $error;
}

View File

@@ -11,6 +11,7 @@ declare (strict_types=1);
// +----------------------------------------------------------------------
namespace app\common\middleware;
use Webman\Event\Event;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;
@@ -20,7 +21,6 @@ use Webman\Http\Request;
* @package app\common\middleware
* @author meystack <
*/
class AppInitialize implements MiddlewareInterface
{
public function process(Request $request, callable $handler): Response
@@ -29,6 +29,8 @@ class AppInitialize implements MiddlewareInterface
return \response(request_error(), 404);
}
// 执行插件初始化钩子
Event::emit('appInit', $request);
return $handler($request);
}
}

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);
}
}

View File

@@ -13,7 +13,11 @@ declare(strict_types=1);
namespace app\common\taglib;
use Psr\SimpleCache\InvalidArgumentException;
use system\Random;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
use think\template\TagLib;
@@ -22,15 +26,15 @@ use think\template\TagLib;
*/
class SaLibs extends TagLib
{
/**
* 定义标签列表
*/
protected $tags = [
// 标签定义: attr 属性列表 close 是否闭合0 或者1 默认1 alias 标签别名 level 嵌套层次
'variable' => ['attr' => 'name', 'close' => 0], // 自定义变量
'company' => ['attr' => 'name,alias', 'close' => 0], // 公司信息
'dictionary' => ['attr' => 'id,value'], // 获取字典列表
'variable' => ['attr' => 'name', 'close' => 0], // 自定义变量
'company' => ['attr' => 'name,alias', 'close' => 0], // 公司信息
'usergroup' => ['attr' => 'id, name,alias'], // 用户组列表
'dictionary' => ['attr' => 'id,value'], // 获取字典列表
];
/**
@@ -38,7 +42,10 @@ class SaLibs extends TagLib
* @access public
* @param $tags
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws InvalidArgumentException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function tagVariable($tags)
{
@@ -57,7 +64,7 @@ class SaLibs extends TagLib
* 获取公司变量
* @access public
* @param $tags
* @return mixed
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
@@ -75,6 +82,33 @@ class SaLibs extends TagLib
if (!empty($data) && isset($data[$tags['name']])) {
return $data[$tags['name']];
}
return '';
}
/**
* 获取用户组
* @access public
* @param array $tags
* @param string $content
* @return string
*/
public function tagUsergroup(array $tags, string $content): string
{
$tags['id'] = $tags['id'] ?? 'vo';
$id = $this->autoBuildVar($tags['id']);
$_var = Random::alpha();
$where = [];
if (isset($tags['pay'])) {
$where[] = ['pay', '=', $tags['pay']];
}
$parse = '<?php ';
$parse .= '$_' . $_var . ' = \app\common\model\system\UserGroup::where('.var_exports($where).')->select();';
$parse .= ' ?>';
$parse .= '<?php foreach($_' . $_var . ' as $key=>' . $id . '):?>';
$parse .= $content;
$parse .= '<?php endforeach; ?>';
return $parse;
}
/**

View File

@@ -4,7 +4,7 @@ namespace app\common\validate\system;
use think\Validate;
class LoginLog extends Validate
class AdminLog extends Validate
{
/**
* 验证规则

View File

@@ -4,6 +4,10 @@ declare(strict_types=1);
namespace app\common\validate\system;
use Psr\SimpleCache\InvalidArgumentException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Validate;
class User extends Validate
@@ -37,22 +41,25 @@ class User extends Validate
// 测试验证场景
protected $scene = [
'test' => ['test_filed'],
'test' => ['test_filed'],
'nickname' => ['nickname'],
];
/**
* 自定义验证规则
* @param $value
* @return bool
* @throws InvalidArgumentException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
protected function filters($value): bool
{
$notAllow = saenv('user_reg_notallow');
$notAllow = explode(',', $notAllow);
foreach ($notAllow as $values) {
if ($value == $values) {
return false;
}
if (in_array($value, $notAllow)) {
return false;
}
return true;
}