-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5f4850
commit 6d4c3ab
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Event; | ||
|
||
/** | ||
* 安装成功 | ||
*/ | ||
class SuccessInstallEvent | ||
{ | ||
public function __construct() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;'); | ||
} | ||
} | ||
} |