FarmServiceProvider.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Module\Farm\Providers;
  3. use App\Module\Farm\Commands;
  4. use App\Module\Farm\Events\CropGrowthStageChangedEvent;
  5. use App\Module\Farm\Events\CropHarvestedEvent;
  6. use App\Module\Farm\Listeners\CalculateHarvestOutputListener;
  7. use App\Module\Farm\Listeners\CheckHouseDowngradeListener;
  8. use App\Module\Farm\Listeners\DistributeTeamProfitListener;
  9. use App\Module\Farm\Listeners\GenerateDisasterListener;
  10. use App\Module\Farm\Listeners\UpdateCropStatusListener;
  11. use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
  12. use Illuminate\Support\Facades\Event;
  13. /**
  14. * 农场模块服务提供者
  15. */
  16. class FarmServiceProvider extends ServiceProvider
  17. {
  18. /**
  19. * 事件与监听器映射
  20. *
  21. * @var array
  22. */
  23. protected $listen = [
  24. CropGrowthStageChangedEvent::class => [
  25. UpdateCropStatusListener::class,
  26. GenerateDisasterListener::class,
  27. ],
  28. CropHarvestedEvent::class => [
  29. CalculateHarvestOutputListener::class,
  30. DistributeTeamProfitListener::class,
  31. ],
  32. ];
  33. /**
  34. * 注册服务
  35. *
  36. * @return void
  37. */
  38. public function register()
  39. {
  40. // 注册命令
  41. $this->commands([
  42. Commands\UpdateCropGrowthCommand::class,
  43. Commands\GenerateDisastersCommand::class,
  44. Commands\CheckHouseDowngradeCommand::class,
  45. Commands\CleanExpiredLogsCommand::class,
  46. Commands\GenerateFarmHouseConfigJson::class,
  47. Commands\GenerateFarmShrineConfigJson::class,
  48. Commands\MigrateLandUpgradeMaterialsToConsumeGroupsCommand::class,
  49. Commands\MigrateLandUpgradeConditionsToConditionGroupsCommand::class
  50. ]);
  51. }
  52. /**
  53. * 引导服务
  54. *
  55. * @return void
  56. */
  57. public function boot()
  58. {
  59. parent::boot();
  60. // 注册定时任务监听器
  61. // $this->app->booted(function () {
  62. // $schedule = $this->app->make(\Illuminate\Console\Scheduling\Schedule::class);
  63. //
  64. // // 每5分钟更新作物生长状态
  65. // $schedule->command('farm:update-crop-growth')->everyFiveMinutes();
  66. //
  67. // // 每小时随机生成灾害
  68. // $schedule->command('farm:generate-disasters')->hourly();
  69. //
  70. // // 每天凌晨2点检查房屋降级
  71. // $schedule->command('farm:check-house-downgrade')->dailyAt('02:00');
  72. //
  73. // // 达人等级更新已移至Team模块
  74. //
  75. // // 每周一凌晨4点清理过期日志
  76. // $schedule->command('farm:clean-expired-logs')->weekly()->mondays()->at('04:00');
  77. //
  78. // // 每天凌晨5点重建缓存
  79. // $schedule->command('farm:rebuild-cache')->dailyAt('05:00');
  80. // });
  81. }
  82. }