FarmServiceProvider.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Module\Farm\Providers;
  3. use App\Module\Farm\Commands;
  4. use App\Module\AppGame\Events\LoginSuccessEvent;
  5. use App\Module\Farm\Events\CropGrowthStageChangedEvent;
  6. use App\Module\Farm\Events\FarmCreatedEvent;
  7. use App\Module\Farm\Events\HouseUpgradedEvent;
  8. use App\Module\Farm\Listeners\AddLandAfterHouseUpgradeListener;
  9. use App\Module\Farm\Listeners\FarmInitRewardListener;
  10. use App\Module\Farm\Listeners\GenerateDisasterListener;
  11. use App\Module\Farm\Listeners\LoginSuccessListener;
  12. use App\Module\Farm\Listeners\UpdateCropStatusListener;
  13. use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
  14. /**
  15. * 农场模块服务提供者
  16. */
  17. class FarmServiceProvider extends ServiceProvider
  18. {
  19. /**
  20. * 事件与监听器映射
  21. *
  22. * @var array
  23. */
  24. protected $listen = [
  25. CropGrowthStageChangedEvent::class => [
  26. UpdateCropStatusListener::class,
  27. GenerateDisasterListener::class,
  28. ],
  29. HouseUpgradedEvent::class => [
  30. AddLandAfterHouseUpgradeListener::class,
  31. ],
  32. LoginSuccessEvent::class => [
  33. LoginSuccessListener::class,
  34. ],
  35. FarmCreatedEvent::class => [
  36. FarmInitRewardListener::class,
  37. ],
  38. ];
  39. /**
  40. * 注册服务
  41. *
  42. * @return void
  43. */
  44. public function register()
  45. {
  46. // 注册命令
  47. $this->commands([
  48. Commands\UpdateCropGrowthCommand::class,
  49. Commands\FixCropFinalOutputCommand::class,
  50. Commands\GenerateDisastersCommand::class,
  51. Commands\CheckHouseDowngradeCommand::class,
  52. Commands\CleanExpiredLogsCommand::class,
  53. Commands\GenerateFarmHouseConfigJson::class,
  54. Commands\GenerateFarmShrineConfigJson::class,
  55. Commands\GenerateFarmLandConfigJson::class,
  56. Commands\GenerateFarmSeedConfigJson::class,
  57. Commands\MigrateLandUpgradeMaterialsToConsumeGroupsCommand::class,
  58. Commands\MigrateLandUpgradeConditionsToConditionGroupsCommand::class,
  59. Commands\InitializeUserLandsCommand::class,
  60. ]);
  61. }
  62. /**
  63. * 引导服务
  64. *
  65. * @return void
  66. */
  67. public function boot()
  68. {
  69. $events = $this->app['events'];
  70. foreach ($this->listen as $event => $listeners) {
  71. foreach ($listeners as $listener) {
  72. $events->listen($event, $listener);
  73. }
  74. }
  75. // 注册农场配置管理路由
  76. $this->registerAdminRoutes();
  77. // 注册定时任务监听器
  78. // $this->app->booted(function () {
  79. // $schedule = $this->app->make(\Illuminate\Console\Scheduling\Schedule::class);
  80. //
  81. //
  82. // // 每小时随机生成灾害
  83. // $schedule->command('farm:generate-disasters')->hourly();
  84. //
  85. // // 每周一凌晨4点清理过期日志
  86. // $schedule->command('farm:clean-expired-logs')->weekly()->mondays()->at('04:00');
  87. //
  88. // // 每天凌晨5点重建缓存
  89. // $schedule->command('farm:rebuild-cache')->dailyAt('05:00');
  90. // });
  91. }
  92. /**
  93. * 注册后台管理路由
  94. *
  95. * @return void
  96. */
  97. protected function registerAdminRoutes()
  98. {
  99. $attributes = [
  100. 'prefix' => config('admin.route.prefix'),
  101. 'middleware' => config('admin.route.middleware'),
  102. ];
  103. app('router')->group($attributes, function ($router) {
  104. // 农场配置管理路由
  105. $router->resource('farm-configs', \App\Module\Farm\AdminControllers\FarmConfigController::class);
  106. // 清除缓存路由
  107. $router->post('farm-configs/clear-cache', [\App\Module\Farm\AdminControllers\FarmConfigController::class, 'clearCache']);
  108. });
  109. }
  110. }