| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace App\Module\Farm\Providers;
- use App\Module\Farm\Commands;
- use App\Module\AppGame\Events\LoginSuccessEvent;
- use App\Module\Farm\Events\CropGrowthStageChangedEvent;
- use App\Module\Farm\Events\FarmCreatedEvent;
- use App\Module\Farm\Events\HouseUpgradedEvent;
- use App\Module\Farm\Listeners\AddLandAfterHouseUpgradeListener;
- use App\Module\Farm\Listeners\FarmInitRewardListener;
- use App\Module\Farm\Listeners\GenerateDisasterListener;
- use App\Module\Farm\Listeners\LoginSuccessListener;
- use App\Module\Farm\Listeners\UpdateCropStatusListener;
- use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
- /**
- * 农场模块服务提供者
- */
- class FarmServiceProvider extends ServiceProvider
- {
- /**
- * 事件与监听器映射
- *
- * @var array
- */
- protected $listen = [
- CropGrowthStageChangedEvent::class => [
- UpdateCropStatusListener::class,
- GenerateDisasterListener::class,
- ],
- HouseUpgradedEvent::class => [
- AddLandAfterHouseUpgradeListener::class,
- ],
- LoginSuccessEvent::class => [
- LoginSuccessListener::class,
- ],
- FarmCreatedEvent::class => [
- FarmInitRewardListener::class,
- ],
- ];
- /**
- * 注册服务
- *
- * @return void
- */
- public function register()
- {
- // 注册命令
- $this->commands([
- Commands\UpdateCropGrowthCommand::class,
- Commands\FixCropFinalOutputCommand::class,
- Commands\GenerateDisastersCommand::class,
- Commands\CheckHouseDowngradeCommand::class,
- Commands\CleanExpiredLogsCommand::class,
- Commands\GenerateFarmHouseConfigJson::class,
- Commands\GenerateFarmShrineConfigJson::class,
- Commands\GenerateFarmLandConfigJson::class,
- Commands\GenerateFarmSeedConfigJson::class,
- Commands\MigrateLandUpgradeMaterialsToConsumeGroupsCommand::class,
- Commands\MigrateLandUpgradeConditionsToConditionGroupsCommand::class,
- Commands\InitializeUserLandsCommand::class,
- ]);
- }
- /**
- * 引导服务
- *
- * @return void
- */
- public function boot()
- {
- $events = $this->app['events'];
- foreach ($this->listen as $event => $listeners) {
- foreach ($listeners as $listener) {
- $events->listen($event, $listener);
- }
- }
- // 注册农场配置管理路由
- $this->registerAdminRoutes();
- // 注册定时任务监听器
- // $this->app->booted(function () {
- // $schedule = $this->app->make(\Illuminate\Console\Scheduling\Schedule::class);
- //
- //
- // // 每小时随机生成灾害
- // $schedule->command('farm:generate-disasters')->hourly();
- //
- // // 每周一凌晨4点清理过期日志
- // $schedule->command('farm:clean-expired-logs')->weekly()->mondays()->at('04:00');
- //
- // // 每天凌晨5点重建缓存
- // $schedule->command('farm:rebuild-cache')->dailyAt('05:00');
- // });
- }
- /**
- * 注册后台管理路由
- *
- * @return void
- */
- protected function registerAdminRoutes()
- {
- $attributes = [
- 'prefix' => config('admin.route.prefix'),
- 'middleware' => config('admin.route.middleware'),
- ];
- app('router')->group($attributes, function ($router) {
- // 农场配置管理路由
- $router->resource('farm-configs', \App\Module\Farm\AdminControllers\FarmConfigController::class);
- // 清除缓存路由
- $router->post('farm-configs/clear-cache', [\App\Module\Farm\AdminControllers\FarmConfigController::class, 'clearCache']);
- });
- }
- }
|