一大波修正

This commit is contained in:
1099438829 2021-02-18 16:00:49 +08:00
parent 28709cd599
commit 5a4c3f2529
64 changed files with 186 additions and 1212 deletions

View File

@ -1,3 +0,0 @@
<?php
define('INSTALL_DATE',1605972689);
define('SERIALNUMBER','u2lzT0');

View File

@ -1,13 +0,0 @@
### 该问题是怎么引起的?
### 重现步骤
### 报错信息

View File

@ -1,14 +0,0 @@
### 相关的Issue
### 原因(目的、解决的问题等)
### 描述(做了什么,变更了什么)
### 测试用例(新增、改动、可能影响的功能)

View File

@ -3,7 +3,7 @@ declare (strict_types = 1);
namespace app;
use learn\utils\Json;
use app\common\utils\Json;
use think\Service;
/**

View File

@ -5,9 +5,9 @@ namespace app\admin\controller;
use app\admin\model\Admin as aModel;
use app\admin\model\AdminRole as rModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use app\admin\services\FormBuilderService as Form;
use think\facade\Route as Url;
/**

View File

@ -5,9 +5,9 @@ namespace app\admin\controller;
use app\admin\model\AdminAuth as aModel;
use app\Request;
use FormBuilder\Exception\FormBuilderException;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use app\admin\services\FormBuilderService as Form;
use think\facade\Route as Url;
/**

View File

@ -4,7 +4,7 @@ namespace app\admin\controller;
use app\admin\model\AdminLog as lModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* 日志

View File

@ -2,7 +2,7 @@
namespace app\admin\controller;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
use app\admin\model\AdminNotify as nModel;
/**
* 消息提醒

View File

@ -6,9 +6,9 @@ use app\admin\model\AdminRole as rModel;
use app\admin\model\AdminAuth as aModel;
use app\Request;
use FormBuilder\Exception\FormBuilderException;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use app\admin\services\FormBuilderService as Form;
class AdminRole extends AuthController
{

View File

@ -6,7 +6,7 @@ use app\admin\model\Document;
use app\admin\model\DocumentArticle;
use app\admin\model\DocumentProduct;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Class Article

View File

@ -6,8 +6,8 @@ use app\admin\model\DocumentCategory as aModel;
use app\Request;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use learn\services\UtilService as Util;
use app\admin\services\FormBuilderService as Form;
use app\admin\services\UtilService as Util;
use think\facade\Route as Url;
/**

View File

@ -4,8 +4,8 @@ namespace app\admin\controller;
use app\admin\model\Attachment;
use learn\services\storage\QcloudCoService;
use learn\services\UtilService as Util;
use app\admin\services\storage\QcloudCoService;
use app\admin\services\UtilService as Util;
use think\facade\Filesystem;
class Files extends AuthController

View File

@ -4,7 +4,7 @@ namespace app\admin\controller;
use app\admin\model\FriendLink as aModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Class Message

View File

@ -6,10 +6,10 @@ namespace app\admin\controller;
use app\admin\model\Attachment;
use app\admin\model\AttachmentCategory;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use learn\services\storage\QcloudCoService;
use learn\services\UtilService as Util;
use learn\utils\Json;
use app\admin\services\FormBuilderService as Form;
use app\admin\services\storage\QcloudCoService;
use app\admin\services\UtilService as Util;
use app\common\utils\Json;
/**
* Class Images

View File

@ -5,7 +5,7 @@ namespace app\admin\controller;
use app\admin\model\AdminAuth;
use app\admin\model\AdminNotify;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
class Index extends AuthController
{

View File

@ -4,7 +4,7 @@ namespace app\admin\controller;
use app\admin\model\InvitationCode as aModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Class Invitation

View File

@ -5,7 +5,7 @@ namespace app\admin\controller;
use app\admin\model\Admin;
use app\admin\model\Admin as adminModel;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
class Login extends AuthController
{

View File

@ -4,7 +4,7 @@ namespace app\admin\controller;
use app\admin\model\MessageForm as aModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Class Message

View File

@ -4,7 +4,7 @@ namespace app\admin\controller;
use app\admin\model\Slides as aModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Class Slides

View File

@ -6,8 +6,7 @@
*/
namespace app\admin\controller;
use learn\basic\admin\BaseController;
use app\BaseController;
class SystemBasic extends BaseController

View File

@ -6,8 +6,8 @@ use app\admin\model\SystemConfig as cModel;
use app\admin\model\SystemConfigTab as tModel;
use app\Request;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use learn\services\UtilService as Util;
use app\admin\services\FormBuilderService as Form;
use app\admin\services\UtilService as Util;
/**
* 系统配置

View File

@ -5,8 +5,8 @@ namespace app\admin\controller;
use app\Request;
use FormBuilder\Factory\Elm;
use learn\services\FormBuilderService as Form;
use learn\services\UtilService as Util;
use app\admin\services\FormBuilderService as Form;
use app\admin\services\UtilService as Util;
use app\admin\model\SystemConfigTab as tModel;
use app\admin\model\SystemConfig as cModel;

View File

@ -3,7 +3,7 @@
namespace app\admin\controller;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Trait TemplateTrait

View File

@ -2,9 +2,9 @@
namespace app\admin\controller;
use app\admin\model\Document as aModel;
use app\admin\model\User as aModel;
use app\Request;
use learn\services\UtilService as Util;
use app\admin\services\UtilService as Util;
/**
* Class User
@ -39,11 +39,10 @@ class User extends AuthController
public function lst(Request $request)
{
$where = Util::postMore([
['status',''],
['name',''],
['tel',''],
['start_time',''],
['end_time',''],
['role_id',''],
['status',''],
['page',1],
['limit',20],

View File

@ -5,7 +5,7 @@ namespace app\admin\model;
use app\admin\model\BaseModel;
use app\admin\model\system\SystemConfig;
use app\admin\model\SystemConfig;
/**
* Class attachment

92
app/admin/model/User.php Normal file
View File

@ -0,0 +1,92 @@
<?php
namespace app\admin\model;
use think\facade\Cache;
use think\facade\Session;
/**
* 用户管理
* Class User
* @package app\admin\model
* @author 李玉坤
* @date 2021-02-18 15:49
*/
class User extends BaseModel
{
/**
* 登录
* @param $name
* @param $pwd
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function login(string $name,string $pwd): bool
{
$info = self::where("name|tel","=", $name)->find();
if (!$info) return self::setErrorInfo("登录账号不存在");
if ($info['pwd'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!");
if ($info['status'] == 2) return self::setErrorInfo("账号已被冻结!");
self::setLoginInfo($info);
return true;
}
/**
* 设置登录信息
* @param $info
* @return bool
*/
public static function setLoginInfo($info)
{
Session::set("adminId",$info['id']);
Session::set("adminInfo",$info->toArray());
event("AdminLog",[$info->toArray(),"admin","login","login"]);
return true;
}
/**
* 退出登录
*/
public static function clearLoginInfo()
{
Session::delete("adminId");
Session::delete("adminInfo");
Session::clear();
return true;
}
/**
* 是否登录
* @return bool
*/
public static function isActive(): bool
{
return Session::has('adminId') && Session::has('adminInfo');
}
/**
* 列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function systemPage(array $where): array
{
$model = new self;
if ($where['name'] != '') $model = $model->where("username|nickname","like","%$where[name]%");
if ($where['start_time'] != '') $model = $model->where("create_time",">",strtotime($where['start_time']." 00:00:00"));
if ($where['end_time'] != '') $model = $model->where("create_time","<", strtotime($where['end_time']." 23:59:59"));
if ($where['tel'] != '') $model = $model->where("tel|mail", "like","%$where[tel]%");
if ($where['status'] != '') $model = $model->where("status",$where['status']);
$count = self::counts($model);
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'],(int)$where['limit']);
$data = $model->select();
$data = $data ? $data->toArray() : [];
return compact("data","count");
}
}

View File

@ -1,14 +1,14 @@
<?php
namespace learn\services;
namespace app\admin\services;
use FormBuilder\Form\IviewForm;
/**
* 表单构建
* Class FormBuilderService
* @package learn\services
* @package app\admin\services
*/
class FormBuilderService
{

View File

@ -1,12 +1,12 @@
<?php
namespace learn\services;
namespace app\admin\services;
/**
* UTIL
* Class UtilService
* @package learn\services
* @package app\admin\services
*/
class UtilService
{

View File

@ -1,14 +1,14 @@
<?php
namespace learn\subscribes;
namespace app\admin\subscribes;
use app\admin\model\AdminLog;
/**
* 操作员日志记录
* Class AdminSubscribe
* @package learn\subscribes
* @package app\common\subscribes
*/
class AdminSubscribe
{

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<title>登录页面 - {:system_config("title")}后台管理系统</title>
<title>用户管理 - {:system_config("title")}后台管理系统</title>
{include file="public/header" /}
</head>
<body>
@ -76,19 +76,11 @@
pagination: true, // 是否显示分页
sortOrder: "asc", // 排序方式
queryParams: function(params) {
var add_time = new Array();
$("input[name='add_time']").each(function(){
add_time.push($(this).val());
});
var temp = {
is_read: $('#is_read option:selected').val(),
type: $('#type option:selected').val(),
add_time: add_time,
limit: params.limit, // 每页数据量
page: (params.offset / params.limit) + 1,
};
let temp = toArrayList($(".searchForm").serializeArray());
temp['limit'] = params.limit;
temp['page'] = (params.offset / params.limit) + 1;
return temp;
}, // 传递参数
}, // 传递参数
sidePagination: "server", // 分页方式client客户端分页server服务端分页
pageNumber: 1, // 初始化加载第一页,默认第一页
pageSize: 10, // 每页的记录行数
@ -99,7 +91,7 @@
field: 'id',
title: '留言ID',
}, {
field: 'name',
field: 'truename',
title: '用户昵称'
}, {
field: 'tel',
@ -107,31 +99,28 @@
}, {
field: 'email',
title: '邮箱'
}, {
field: 'type',
title: '留言来源'
}, {
field: 'content',
title: '内容',
}, {
field: 'ip',
title: 'ip',
}, {
field: 'user_agent',
title: 'UserAgent',
field: 'is_admin',
title: '管理员',
formatter: function (value, row, index) {
return value?'是':'否';
}
}, {
field: 'add_time',
field: 'create_time',
title: '创建时间',
}, {
field: 'is_read',
title: '是否已读',
field: 'status',
title: '状态',
formatter: function (value, row, index) {
if (value == 0) {
is_checked = '';
} else if (value == 1){
is_checked = 'checked="checked"';
}
var field = "is_read";
var field = "status";
result = '<label class="lyear-switch switch-primary switch-solid lyear-status"><input type="checkbox" '+ is_checked +'><span onClick="updateStatus('+ row.id +', '+ value +', \''+ field +'\')"></span></label>';
return result;
},

View File

@ -15,7 +15,7 @@ if (!function_exists('system_config_more'))
{
$systemConfig = cache('systemConfig');
if (empty($systemConfig)){
$systemConfig = \app\admin\model\system\SystemConfig::getSystemConfigValues();
$systemConfig = \app\admin\model\SystemConfig::getSystemConfigValues();
cache('systemConfig',$systemConfig);
}
$data = [];
@ -75,7 +75,7 @@ if (!function_exists('system_config'))
{
$systemConfig = cache('systemConfig');
if (empty($systemConfig)){
$systemConfig = \app\admin\model\system\SystemConfig::getSystemConfigValues();
$systemConfig = \app\admin\model\SystemConfig::getSystemConfigValues();
cache('systemConfig',$systemConfig);
}
return $systemConfig[$formName]??'';

View File

@ -1,13 +1,13 @@
<?php
namespace learn\exceptions;
namespace app\common\exceptions;
use Throwable;
/**
* Class AuthException
* @package learn\exceptions
* @package app\common\exceptions
*/
class AuthException extends \Exception
{

View File

@ -1,14 +1,14 @@
<?php
namespace learn\interfaces;
namespace app\common\interfaces;
use app\Request;
/**
* Interface MiddlewareInterface
* @package learn\interfaces
* @package app\common\interfaces
*/
interface MiddlewareInterface
{

View File

@ -1,11 +1,11 @@
<?php
namespace learn\middleware;
namespace app\common\middleware;
use app\Request;
use learn\interfaces\MiddlewareInterface;
use app\common\interfaces\MiddlewareInterface;
use think\Response;
/**

View File

@ -1,18 +1,18 @@
<?php
namespace learn\middleware;
namespace app\common\middleware;
use app\api\model\user\User;
use app\admin\model\User;
use app\Request;
use learn\exceptions\AuthException;
use learn\interfaces\MiddlewareInterface;
use app\common\exceptions\AuthException;
use app\common\interfaces\MiddlewareInterface;
/**
* token验证
* Class AuthTokenMiddleware
* @package learn\middleware
* @package app\common\middleware
*/
class AuthTokenMiddleware implements MiddlewareInterface
{

View File

@ -1,11 +1,11 @@
<?php
namespace learn\utils;
namespace app\common\utils;
/**
* Class Curl
* @package learn\utils
* @package app\common\utils
*/
class Curl
{

View File

@ -1,13 +1,13 @@
<?php
namespace learn\utils;
namespace app\common\utils;
use think\Response;
/**
* Class Json
* @package learn\utils
* @package app\common\utils
*/
class Json
{

View File

@ -1,12 +1,12 @@
<?php
namespace learn\utils;
namespace app\common\utils;
use Firebase\JWT\JWT as jt;
/**
* Class Jwt
* @package learn\utils
* @package app\common\utils
*/
class Jwt
{

View File

@ -1,12 +1,12 @@
<?php
namespace learn\utils;
namespace app\common\utils;
/**
* 宝塔邮件发送
* Class Mail
* @package learn\utils
* @package app\common\utils
*/
class Mail
{

View File

@ -1,7 +1,7 @@
<?php
namespace learn\utils;
namespace app\common\utils;
use think\facade\Session as systemSession;

View File

@ -1,5 +1,5 @@
<?php
namespace app\http\validates\user;
namespace app\common\validate;
use think\Validate;

View File

@ -5,23 +5,10 @@ return [
],
'listen' => [
'Task_1'=>[],//1秒钟执行的方法
'Task_5'=>[],//5秒钟执行的方法
'Task_10'=>[],//10秒钟执行的方法
'Task_30'=>[],//30秒钟执行的方法
'Task_60'=>[],//60秒钟执行的方法
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
'Test' => [], // 后台通知测试
'AdminLog' => [], // 操作日志记录
],
'subscribe' => [
\learn\subscribes\AdminSubscribe::class, // 操作记录
\learn\subscribes\SystemSubscribe::class, // 系统通知
\learn\subscribes\TimerSubscribe::class, // 定时器
\app\admin\subscribes\AdminSubscribe::class, // 操作记录
],
];

View File

@ -6,7 +6,7 @@ use app\BaseController;
use think\facade\Config;
use think\facade\Db;
use think\facade\View;
use app\admin\model\system\SystemConfig;
use app\admin\model\SystemConfig;
/**
* 控制器基础类

View File

@ -1,122 +0,0 @@
<?php
declare (strict_types = 1);
namespace learn\basic\admin;
use think\App;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\facade\View;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = app("request");
// 控制器初始化
$this->initialize();
}
// 初始化
protected function initialize()
{}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
/**
* 视图赋值
* @param mixed ...$vars
*/
protected function assign(...$vars)
{
View::assign(...$vars);
}
/**
* 返回视图
* @return string
* @throws \Exception
*/
protected function fetch(string $template = '')
{
return View::fetch($template);
}
/**
* 页面
* @param mixed ...$args
*/
protected function redirect(...$args){
throw new HttpResponseException(redirect(...$args));
}
}

View File

@ -1,122 +0,0 @@
<?php
declare (strict_types = 1);
namespace learn\basic\index;
use think\App;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\facade\View;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = app("request");
// 控制器初始化
$this->initialize();
}
// 初始化
protected function initialize()
{}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
/**
* 视图赋值
* @param mixed ...$vars
*/
protected function assign(...$vars)
{
View::assign(...$vars);
}
/**
* 返回视图
* @return string
* @throws \Exception
*/
protected function fetch(string $template = '')
{
return View::fetch($template);
}
/**
* 页面
* @param mixed ...$args
*/
protected function redirect(...$args){
throw new HttpResponseException(redirect(...$args));
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace learn\subscribes;
class RedisSubscribe
{
}

View File

@ -1,23 +0,0 @@
<?php
namespace learn\subscribes;
use learn\workerman\channel\ChannelClient;
/**
* 系统通知订阅
* Class SystemSubscribe
* @package learn\subscribes
*/
class SystemSubscribe
{
/**
* 后台通知测试
* @param $event
*/
public function onTest($event)
{
ChannelClient::instance()->send("Message",[]);
}
}

View File

@ -1,60 +0,0 @@
<?php
namespace learn\subscribes;
/**
* Class TimerSubscribe
* @package learn\subscribes
*/
class TimerSubscribe
{
/**
* 每隔1秒执行的任务
*/
public function onTask_1()
{
}
/**
* 每隔5秒执行的任务
*/
public function onTask_5()
{
}
/**
* 每隔10秒执行的任务
*/
public function onTask_10()
{
}
/**
* 每隔30秒执行的任务
*/
public function onTask_30()
{
}
/**
* 每隔60秒执行的任务
*/
public function onTask_60()
{
}
/**
* 每隔4小时执行的任务
*/
public function onTask_14400()
{
}
/**
* 每隔一天执行的任务
*/
public function onTask_86400()
{
}
}

View File

@ -1,101 +0,0 @@
<?php
namespace learn\workerman;
use Workerman\Connection\TcpConnection;
class Response
{
/**
* @var TcpConnection
*/
protected $connection;
/**
* 设置用户
*
* @param TcpConnection $connection
* @return $this
*/
public function connection(TcpConnection $connection)
{
$this->connection = $connection;
return $this;
}
/**
* 发送请求
*
* @param string $type
* @param array|null $data
* @param bool $close
* @param array $other
* @return bool|null
*/
public function send(string $type, ?array $data = null, bool $close = false, array $other = [])
{
$this->connection->lastMessageTime = time();
$res = compact('type');
if (!is_null($data)) $res['data'] = $data;
$data = array_merge($res, $other);
if ($close)
$data['close'] = true;
$json = json_encode($data);
return $close
? ($this->connection->close($json) && true)
: $this->connection->send($json);
}
/**
* 成功
*
* @param string $message
* @param array|null $data
* @return bool|null
*/
public function success($type = 'success', ?array $data = null)
{
if (is_array($type)) {
$data = $type;
$type = 'success';
}
return $this->send($type, $data);
}
/**
* 失败
*
* @param string $message
* @param array|null $data
* @return bool|null
*/
public function fail($type = 'error', ?array $data = null)
{
if (is_array($type)) {
$data = $type;
$type = 'error';
}
return $this->send($type, $data);
}
/**
* 关闭连接
*
* @param string $type
* @param array|null $data
* @return bool|null
*/
public function close($type = 'error', ?array $data = null)
{
if (is_array($type)) {
$data = $type;
$type = 'error';
}
return $this->send($type, $data, true);
}
}

View File

@ -1,88 +0,0 @@
<?php
namespace learn\workerman;
use Workerman\Lib\Timer;
use think\worker\Server;
use Workerman\Worker;
class TimerService extends Server
{
/**
* 协议
* @var string
*/
protected $protocol = "frame";
/**
* 监听地址
* @var string
*/
protected $host = '0.0.0.0';
/**
* 端口
* @var string
*/
protected $port = 1999;
/**
* @var int
*/
protected $timer;
/**
* @var null
*/
protected $worker = null;
/**
* @var int|float
*/
protected $interval = 1;
/**
* 基础配置
* @var array
*/
protected $option = [
'count' => 1,
'name' => 'timer'
];
/**
* @param Worker $worker
*/
protected function init(Worker $worker = null)
{
parent::init(); // TODO: Change the autogenerated stub
$this->worker = $worker;
}
/**
* 定时器开启
* @throws \Exception
*/
public function onWorkerStart()
{
$last = time();
$task = [1 => $last, 5 => $last, 10 => $last, 30 => $last, 60 => $last, 14400 => $last, 86400 => $last];
$this->timer = Timer::add($this->interval, function () use (&$task) {
try {
$now = time();
foreach ($task as $sec => $time) {
if ($now - $time >= $sec) {
event('Task_' . $sec);
$task[$sec] = $now;
}
}
} catch (\Exception $e) {
var_dump($e);
// 出错定时器停止
Timer::del($this->timer);
}
});
}
}

View File

@ -1,128 +0,0 @@
<?php
namespace learn\workerman\admin;
use app\admin\model\admin\Admin;
use learn\services\WechatService;
use learn\workerman\Response;
use learn\workerman\admin\WorkerService;
use think\facade\Cache;
use Workerman\Connection\TcpConnection;
use Workerman\Worker;
use think\facade\Session;
use learn\utils\Session as MySession;
/**
* Class WorkerHandle
* @package learn\workerman\admin
*/
class WorkerHandle
{
protected $service;
public function __construct(WorkerService &$service)
{
$this->service = &$service;
}
/**
* 后台登录
* @param TcpConnection $connection
* @param array $res
* @param Response $response
* @return bool|null
*/
public function login(TcpConnection &$connection, array $res, Response $response)
{
if (!isset($res['data']) || !$sessionId = $res['data']) {
return $response->close([
'msg' => '授权失败!'
]);
}
MySession::setId($sessionId);
if (!Session::has('adminId') || !Session::has('adminInfo')) {
return $response->close([
'msg' => '授权失败!'
]);
}
$connection->adminInfo = Session::get('adminInfo');
$connection->sessionId = $sessionId;
$this->service->setUser($connection);
return $response->success();
}
/**
* 超时关闭
* @param Worker $worker
* @param Response $response
*/
public function timeoutClose(Worker $worker,Response $response)
{
$time_now = time();
foreach ($worker->connections as $connection) {
if ($time_now - $connection->lastMessageTime > 28) {
$response->connection($connection)->close('timeout');
}
}
}
/**
* 后台微信扫码登录
* @param TcpConnection $connection
* @param array $res
* @param Response $response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function qrcode(TcpConnection &$connection, array $res, Response $response)
{
MySession::setId($res['token']);
// 保存缓存
if (Cache::store('redis')->has($res['token']))
{
$response->connection($connection)->send('qrcode',['src'=>Cache::store('redis')->get($res['token'])]);
}
else
{
$qrcode = WechatService::temporary("type=login&method=wechat&to=admin&token=$res[token]",180);
Cache::store('redis')->set($res['token'],$qrcode,180);
$response->connection($connection)->send('qrcode',['src'=>$qrcode]);
}
}
/**
* 验证二维码是否有效
* @param TcpConnection $connection
* @param array $res
* @param Response $response
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function valid(TcpConnection &$connection, array $res, Response $response)
{
try {
if (Cache::store('redis')->has("info_".$res['token']))
{
if (Admin::setLoginInfo(Cache::store('redis')->get("info_".$res['token'])))
{
$response->connection($connection)->close('valid',['status'=>200]);
Cache::store('redis')->delete($res['token']);
Cache::store('redis')->delete("info_".$res['token']);
}
}
elseif(Cache::store('redis')->has($res['token'])) $response->connection($connection)->send('valid',['status'=>300]);
else $response->connection($connection)->close('valid',['status'=>400]);
}catch (\Exception $e)
{
file_put_contents("wsLogin.log",$e->getMessage());
$response->connection($connection)->close('valid',['status'=>200]);
}
}
}

View File

@ -1,152 +0,0 @@
<?php
namespace learn\workerman\admin;
use Channel\Client;
use learn\workerman\channel\ChannelClient;
use learn\workerman\Response;
use think\worker\Server;
use Workerman\Connection\TcpConnection;
use Workerman\Lib\Timer;
use Workerman\Worker;
/**
* 后台ws服务
* Class worker
* @package learn\workerman\admin
*/
class WorkerService extends Server
{
/**
* 协议
* @var string
*/
protected $protocol = "websocket";
/**
* 监听地址
* @var string
*/
protected $host = '0.0.0.0';
/**
* 端口
* @var string
*/
protected $port = 1996;
/**
* 基础配置
* @var array
*/
protected $option = [
'count' => 1,
'name' => 'admin'
];
/**
* 定时程序
* @var null
*/
protected $time;
/**
* @var Worker
*/
protected $worker;
/**
* @var TcpConnection[]
*/
protected $connections = [];
/**
* @var TcpConnection[]
*/
protected $user = [];
/**
* @var WorkerHandle
*/
protected $handle;
/**
* @var Response
*/
protected $response;
public function setUser(TcpConnection $connection)
{
$this->user[$connection->adminInfo['id']] = $connection;
}
/**
* worker constructor.
* @param Worker|null $worker
*/
protected function init(Worker $worker = null)
{
parent::init();
$this->worker = $worker;
$this->handle = new WorkerHandle($this);
$this->response = new Response();
}
/**
* 连接
* @param TcpConnection $connection
*/
public function onConnect(TcpConnection $connection)
{
$this->connections[$connection->id] = $connection;
$connection->lastMessageTime = time();
}
/**
* 当获取到信息
* @param TcpConnection $connection
* @param $res
* @return bool|void|null
*/
public function onMessage(TcpConnection $connection, $res)
{
$connection->lastMessageTime = time();
$res = json_decode($res, true);
if (!$res || !isset($res['type']) || !$res['type']) return;
if ($res['type'] == 'ping') return $this->response->connection($connection)->send('pong');
if (!method_exists($this->handle, $res['type'])) return;
$this->handle->{$res['type']}($connection, $res + ['data' => []], $this->response->connection($connection));
}
/**
* 开启时
* @param Worker $worker
* @throws \Exception
*/
public function onWorkerStart(Worker $worker)
{
// 开启订阅
ChannelClient::connet();
Client::on('learn', function ($eventData) use ($worker) {
if (!isset($eventData['type']) || !$eventData['type']) return;
$ids = isset($eventData['ids']) && count($eventData['ids']) ? $eventData['ids'] : array_keys($this->user);
foreach ($ids as $id) {
if (isset($this->user[$id]))
$this->response->connection($this->user[$id])->success($eventData['type'], $eventData['data'] ?? null);
}
});
// 超时关闭
Timer::add(35, array($this->handle, 'timeoutClose'), array($worker,$this->response), true);
}
/**
* 连接关闭
* @param TcpConnection $connection
*/
public function onClose(TcpConnection $connection)
{
unset($this->connections[$connection->id]);
}
}

View File

@ -1,73 +0,0 @@
<?php
namespace learn\workerman\channel;
use Channel\Client;
class ChannelClient
{
/**
* @var Client
*/
protected $channel;
/**
* @var ChannelClient
*/
protected static $instance;
/**
* 监听地址
* @var string
*/
const LISTENHOST = '0.0.0.0';
/**
* 监听端口
* @var string
*/
const LISTENPORT = 1998;
public function __construct()
{
self::connet();
}
public static function instance()
{
if (is_null(self::$instance))
self::$instance = new self();
return self::$instance;
}
public static function connet()
{
Client::connect(self::LISTENHOST, self::LISTENPORT);
}
/**
* 发送消息
* @param string $type 类型
* @param array|null $data 数据
* @param array|null $ids 用户 id,不传为全部用户
*/
public function send(string $type, ?array $data = null, ?array $ids = null)
{
$res = compact('type');
if (!is_null($data))
$res['data'] = $data;
if (!is_null($ids) && count($ids))
$res['ids'] = $ids;
$this->trigger('learn', $res);
}
public function trigger(string $type, ?array $data = null)
{
Client::publish($type, $data);
}
}

View File

@ -1,140 +0,0 @@
<?php
namespace learn\workerman\channel;
use think\worker\Server;
use Workerman\Connection\TcpConnection;
use Workerman\Worker;
class ChannelService extends Server
{
/**
* 协议
* @var string
*/
protected $protocol = "frame";
/**
* 监听地址
* @var string
*/
protected $host = '0.0.0.0';
/**
* 端口
* @var string
*/
protected $port = 1998;
/**
* Worker instance.
* @var Worker
*/
protected $_worker = null;
/**
* 基础配置
* @var array
*/
protected $option = [
'count' => 1,
'name' => 'ChannelServer'
];
/**
* 事件
* @var array
*/
protected $event = ['onMessage', 'onClose'];
/**
* 实例化
*/
public function init()
{
$this->worker->channels = array();
$this->_worker = $this->worker;
parent::init();
}
/**
* onClose
* @param $connection
* @return void
*/
public function onClose($connection)
{
if(empty($connection->channels))
{
return;
}
foreach($connection->channels as $channel)
{
unset($this->_worker->channels[$channel][$connection->id]);
if(empty($this->_worker->channels[$channel]))
{
unset($this->_worker->channels[$channel]);
}
}
}
/**
* onMessage.
* @param TcpConnection $connection
* @param string $data
*/
public function onMessage($connection, $data)
{
if(!$data)
{
return;
}
$worker = $this->_worker;
$data = unserialize($data);
$type = $data['type'];
$channels = $data['channels'];
switch($type)
{
case 'subscribe':
foreach($channels as $channel)
{
$connection->channels[$channel] = $channel;
$worker->channels[$channel][$connection->id] = $connection;
}
break;
case 'unsubscribe':
foreach($channels as $channel)
{
if(isset($connection->channels[$channel]))
{
unset($connection->channels[$channel]);
}
if(isset($worker->channels[$channel][$connection->id]))
{
unset($worker->channels[$channel][$connection->id]);
if(empty($worker->channels[$channel]))
{
unset($worker->channels[$channel]);
}
}
}
break;
case 'publish':
foreach($channels as $channel)
{
if(empty($worker->channels[$channel]))
{
continue;
}
$buffer = serialize(array('channel'=>$channel, 'data' => $data['data']))."\n";
foreach($worker->channels[$channel] as $connection)
{
$connection->send($buffer);
}
}
break;
}
}
}

View File

@ -1,43 +0,0 @@
<?php
namespace learn\workerman\chat;
use think\worker\Server;
/**
* 客服聊天
* Class Worker
* @package learn\workerman\chat
*/
class WorkerService extends Server
{
/**
* 协议
* @var string
*/
protected $protocol = "websocket";
/**
* 监听地址
* @var string
*/
protected $host = '0.0.0.0';
/**
* 端口
* @var string
*/
protected $port = 1997;
/**
* 基础配置
* @var array
*/
protected $option = [
'count' => 1,
'name' => 'chat'
];
}

View File

@ -305,7 +305,7 @@ CREATE TABLE `lea_system_config` (
-- ----------------------------
-- Records of lea_system_config
-- ----------------------------
INSERT INTO `lea_system_config` VALUES (1, 1, '网站标题', 'title', 'text', 'input', 0, '', '派后台管理系统', 'systemConfig(\"title\")', 90, 1, 1, '1', '1582792265', '1', '1583855342');
INSERT INTO `lea_system_config` VALUES (1, 1, '网站标题', 'title', 'text', 'input', 0, '', '派后台管理系统', 'system_config(\"title\")', 90, 1, 1, '1', '1582792265', '1', '1583855342');
INSERT INTO `lea_system_config` VALUES (2, 1, '网站图标', 'favicon', 'file', 'input', 0, '', 'http://file.cos.leapy.cn/image/20200509/898b720200509204528197.jpg', '', 89, 1, 1, '1', '1582793160', NULL, NULL);
INSERT INTO `lea_system_config` VALUES (3, 1, '站点关键词', 'keywords', 'text', 'input', 0, '', '派后台管理系统', '', 88, 1, 1, '1', '1582793221', NULL, NULL);
INSERT INTO `lea_system_config` VALUES (4, 1, '站点描述', 'description', 'text', 'input', 0, '', '派后台管理系统', '', 87, 1, 1, '1', '1582793248', NULL, NULL);

View File

@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{$zzField['title']}_{:systemConfig("title")}</title>
<title>{$zzField['title']}_{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">

View File

@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{$zzField['title']}_{:systemConfig("title")}</title>
<title>{$zzField['title']}_{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">
@ -47,17 +47,17 @@
<div class="contact_info">
<div class="info_item">
<i class="lnr lnr-home"></i>
<h6>{:systemConfig("web_contact_add")}</h6>
<p>联系人:{:systemConfig("author")}</p>
<h6>{:system_config("web_contact_add")}</h6>
<p>联系人:{:system_config("author")}</p>
</div>
<div class="info_item">
<i class="lnr lnr-phone-handset"></i>
<h6><a href="#">{:systemConfig("web_contact_tel")}</a></h6>
<h6><a href="#">{:system_config("web_contact_tel")}</a></h6>
<p>周一至周六 08:00--18:00</p>
</div>
<div class="info_item">
<i class="lnr lnr-envelope"></i>
<h6><a href="#">{:systemConfig("web_contact_qq")}@qq.com</a></h6>
<h6><a href="#">{:system_config("web_contact_qq")}@qq.com</a></h6>
<p>任何时间,随时恭候。</p>
</div>
</div>

View File

@ -6,7 +6,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{$zzField['title']}_{:systemConfig("title")}</title>
<title>{$zzField['title']}_{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">

View File

@ -7,7 +7,7 @@
<h3>关于我们</h3>
</div>
<p> {:cn_substr(html2text(get_type_content(86)),80)}...</p>
<p>{:systemConfig("copyright")}</p>
<p>{:system_config("copyright")}</p>
</aside>
</div>
<div class="col-lg-5 col-sm-6">

View File

@ -6,7 +6,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{:systemConfig("title")}</title>
<title>{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">

View File

@ -6,7 +6,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{$zzField['title']}_{:systemConfig("title")}</title>
<title>{$zzField['title']}_{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">

View File

@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{$zzField['title']}_{:systemConfig("title")}</title>
<title>{$zzField['title']}_{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">
@ -33,7 +33,7 @@
<div class="banner_content">
<h2>
呼啦资源网<br>
{:systemConfig("title")}
{:system_config("title")}
</h2>
<p>
{:cn_substr(html2text(:systemConfig'description')),100)}...

View File

@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="/template/default/img/favicon.png" type="image/png">
<title>{$zzField['title']}_{:systemConfig("title")}</title>
<title>{$zzField['title']}_{:system_config("title")}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/template/default/css/bootstrap.css">
<link rel="stylesheet" href="/template/default/vendors/linericon/style.css">