Skip to content

Commit

Permalink
更新:优化安装
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Feb 18, 2023
1 parent b5f4850 commit 6d4c3ab
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/Controller/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace App\Controller;

use App\Event\SuccessInstallEvent;
use App\Model\AdminUser;
use App\Plugins\User\src\Models\UserClass;
use Hyperf\HttpServer\Annotation\Controller;
Expand Down Expand Up @@ -99,6 +100,8 @@ public function step_5($request){
'permission-value' => '1',
]);
});
// 安装成功事件
EventDispatcher()->dispatch(new SuccessInstallEvent());
return Json_Api(200, true, ['msg' => '安装成功!']);
}

Expand Down
14 changes: 14 additions & 0 deletions app/Event/SuccessInstallEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Event;

/**
* 安装成功
*/
class SuccessInstallEvent
{
public function __construct()
{

}
}
50 changes: 50 additions & 0 deletions app/Listener/InstallSuccessListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Listener;

use App\Event\SuccessInstallEvent;
use Hyperf\Database\Schema\Schema;
use Hyperf\DB\DB;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Utils\ApplicationContext;

/**
* 安装成功
*/
#[Listener]
class InstallSuccessListener implements ListenerInterface
{
public function listen(): array
{
// 返回一个该监听器要监听的事件数组,可以同时监听多个事件
return [
SuccessInstallEvent::class,
];
}

/**
* @param SuccessInstallEvent $event
*/
public function process(object $event): void
{
// 转换user_options数据类型

$db = ApplicationContext::getContainer()->get(DB::class);
if (Schema::getColumnType('users_options', 'money') !== 'integer') {
$db->query('ALTER TABLE users_options MODIFY money INT;');
}
// 积分
if (Schema::getColumnType('users_options', 'credits') !== 'integer') {
$db->query('ALTER TABLE users_options MODIFY credits INT;');
}
// 金币
if (Schema::getColumnType('users_options', 'golds') !== 'integer') {
$db->query('ALTER TABLE users_options MODIFY golds INT;');
}
// 经验
if (Schema::getColumnType('users_options', 'exp') !== 'integer') {
$db->query('ALTER TABLE users_options MODIFY exp INT;');
}
}
}

0 comments on commit 6d4c3ab

Please sign in to comment.