增减消息队列命令行提示

This commit is contained in:
liaofei 2022-08-24 12:19:26 +08:00
parent 43de83a4a3
commit fff771eddc
9 changed files with 148 additions and 6 deletions

View File

@ -56,8 +56,8 @@ class Login extends AuthController
*/
public function login()
{
[$account, $password, $imgcode] = $this->request->postMore([
'account', 'pwd', ['imgcode', '']
[$account, $password, $imgcode, $key] = $this->request->postMore([
'account', 'pwd', ['imgcode', ''], ['key', '']
], true);
if (!app()->make(Captcha::class)->check($imgcode)) {
@ -66,7 +66,7 @@ class Login extends AuthController
$this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
return app('json')->success($this->services->login($account, $password, 'admin'));
return app('json')->success($this->services->login($account, $password, 'admin', $key));
}
/**

View File

@ -22,7 +22,10 @@ return [
'HttpEnd' => [\app\listener\http\HttpEnd::class], //HTTP请求结束回调事件
'LogLevel' => [],
'LogWrite' => [],
'queue.start' => [\app\listener\queue\QueueStart::class],
'user.login' => [\app\listener\user\Login::class], //
'admin.info' => [\app\listener\admin\AdminInfo::class],//管理员登录前获取登录信息事件
'admin.login' => [\app\listener\admin\AdminLogin::class],//管理员登录
'user.register' => [\app\listener\user\Register::class], //用户注册后置事件
'wechat.auth' => [\app\listener\wechat\Auth::class], //用户授权后置事件
'order.orderCreateAfter' => [\app\listener\order\OrderCreateAfter::class], //订单创建后置事件

View File

@ -0,0 +1,35 @@
<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
namespace app\jobs;
use crmeb\basic\BaseJobs;
use crmeb\traits\QueueTrait;
/**
* 检测消息队列是否执行
* Class CheckQueueJob
* @package app\jobs
*/
class CheckQueueJob extends BaseJobs
{
use QueueTrait;
public function handle($key)
{
$path = runtime_path() . '.queue';
file_put_contents($path, $key);
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
namespace app\listener\admin;
use app\jobs\CheckQueueJob;
use crmeb\interfaces\ListenerInterface;
/**
* 登录前获取信息
* Class AdminInfo
* @package app\listener\admin
*/
class AdminInfo implements ListenerInterface
{
public function handle($event): void
{
CheckQueueJob::dispatch($event);
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
namespace app\listener\admin;
/**
* Class AdminLogin
* @package app\listener\admin
*/
class AdminLogin
{
public function handle($event)
{
try {
[$key] = $event;
//检测消息队列是否执行
$path = root_path('runtime') . '.queue';
$content = file_get_contents($path);
$res = $key === $content;
unlink($path);
return $res;
} catch (\Throwable $e) {
return false;
}
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
namespace app\listener\queue;
use think\console\Output;
class QueueStart
{
public function handle(Output $output)
{
$output->writeln('消息队列已启动,正在运行中,windows请不要关闭命令行。linux请使用Supervisor进行进程守护');
}
}

View File

@ -21,6 +21,7 @@ use app\dao\system\admin\SystemAdminDao;
use app\services\system\SystemMenusServices;
use crmeb\services\FormBuilder;
use crmeb\services\workerman\ChannelService;
use think\facade\Event;
/**
* 管理员service
@ -87,13 +88,14 @@ class SystemAdminServices extends BaseServices
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function login(string $account, string $password, string $type)
public function login(string $account, string $password, string $type, string $key = '')
{
$adminInfo = $this->verifyLogin($account, $password);
$tokenInfo = $this->createToken($adminInfo->id, $type);
/** @var SystemMenusServices $services */
$services = app()->make(SystemMenusServices::class);
[$menus, $uniqueAuth] = $services->getMenusList($adminInfo->roles, (int)$adminInfo['level']);
$queue = Event::until('admin.login', [$key]);
return [
'token' => $tokenInfo['token'],
'expires_time' => $tokenInfo['params']['exp'],
@ -107,7 +109,8 @@ class SystemAdminServices extends BaseServices
'logo' => sys_config('site_logo'),
'logo_square' => sys_config('site_logo_square'),
'version' => get_crmeb_version(),
'newOrderAudioLink' => get_file_link(sys_config('new_order_audio_link', ''))
'newOrderAudioLink' => get_file_link(sys_config('new_order_audio_link', '')),
'queue' => $queue
];
}
@ -117,12 +120,15 @@ class SystemAdminServices extends BaseServices
*/
public function getLoginInfo()
{
$key = uniqid();
event('admin.info', [$key]);
return [
'slide' => sys_data('admin_login_slide') ?? [],
'logo_square' => sys_config('site_logo_square'),//透明
'logo_rectangle' => sys_config('site_logo'),//方形
'login_logo' => sys_config('login_logo'),//登陆
'site_name' => sys_config('site_name')
'site_name' => sys_config('site_name'),
'key' => $key
];
}

View File

@ -44,6 +44,7 @@ class TaskSubscribe
*/
public function onTask_6()
{
file_put_contents(runtime_path() . '.timer', time());
}
/**

View File

@ -55,6 +55,8 @@ class Listen extends Command
$timeout = $input->getOption('timeout');
$sleep = $input->getOption('sleep');
$tries = $input->getOption('tries');
$this->app->event->trigger('queue.start', [$output]);
$this->listener->listen($connection, $queue, $delay, $sleep, $tries, $memory, $timeout);
}