mergeConfigFrom( __DIR__ . '/../Config/mex.php', 'mex' ); // 注册单例服务 ;不注册服务 // $this->registerServices(); } /** * 启动服务 */ public function boot(): void { // 注册命令 $this->registerCommands(); // 注册Mex定时任务 $this->registerSchedules(); // 注册事件监听器 $this->registerEventListeners(); // 发布配置文件 $this->publishes([ __DIR__ . '/../Config/mex.php' => config_path('mex.php'), ], 'mex-config'); } /** * 注册命令 */ protected function registerCommands(): void { if ($this->app->runningInConsole()) { $this->commands([ \App\Module\Mex\Commands\MexUserBuyItemMatchCommand::class, \App\Module\Mex\Commands\MexUserSellItemMatchCommand::class, \App\Module\Mex\Commands\MexTestCommand::class, \App\Module\Mex\Commands\TestMultiCurrencyCommand::class, \App\Module\Mex\Commands\TestOpenHandlerCommand::class, \App\Module\Mex\Commands\FixMissingTransactionRecordsCommand::class, \App\Module\Mex\Commands\GenerateDailyPriceTrendsCommand::class, \App\Module\Mex\Commands\TestConfigCommand::class, ]); } } /** * 注册事件监听器 */ protected function registerEventListeners(): void { Event::listen( \App\Module\Mex\Events\OrderCreatedEvent::class, \App\Module\Mex\Listeners\OrderCreatedListener::class ); Event::listen( \App\Module\Mex\Events\OrderCompletedEvent::class, [\App\Module\Mex\Listeners\OrderCreatedListener::class, 'handleCompleted'] ); Event::listen( \App\Module\Mex\Events\TransactionCreatedEvent::class, \App\Module\Mex\Listeners\TransactionCreatedListener::class ); } /** * 注册Mex相关的定时任务 * * 将原本在 routes/console.php 中的Mex调度配置迁移到此处 */ protected function registerSchedules(): void { // 在应用完全启动后注册定时任务 $this->app->booted(function () { // 每天凌晨00:05生成每日价格趋势数据 ScheduleFacade::command('mex:generate-daily-trends') ->dailyAt('00:05') ->description('生成交易所每日价格趋势数据'); // 注释掉的匹配任务(可根据需要启用) // php artisan mex:user-sell-item-match // ScheduleFacade::command('mex:user-sell-item-match') // ->everyMinute() // ->onOneServer() // ->description('用户卖出物品匹配'); // php artisan mex:user-sell-item-match // ScheduleFacade::command('mex:user-buy-item-match') // ->everyFiveMinutes() // ->onOneServer() // ->description('用户买入物品匹配'); }); } }