TransferServiceProvider.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Module\Transfer;
  3. use App\Module\Transfer\Commands\TransferProcessCommand;
  4. use App\Module\Transfer\Commands\TransferStatsCommand;
  5. use App\Module\Transfer\Commands\TransferCallbackCommand;
  6. use App\Module\Transfer\Commands\TransferCleanCommand;
  7. use App\Module\Transfer\Commands\InsertTransferAdminMenuCommand;
  8. use App\Module\Transfer\Commands\FeeStatisticsCommand;
  9. use App\Module\Transfer\Commands\TestFeeTransferCommand;
  10. use Illuminate\Support\ServiceProvider;
  11. use Illuminate\Support\Facades\Schedule;
  12. /**
  13. * Transfer模块服务提供者
  14. */
  15. class TransferServiceProvider extends ServiceProvider
  16. {
  17. /**
  18. * 注册服务
  19. */
  20. public function register(): void
  21. {
  22. // 注册配置文件
  23. $this->mergeConfigFrom(
  24. __DIR__ . '/Config/transfer.php',
  25. 'transfer'
  26. );
  27. // 注册服务绑定
  28. $this->registerServices();
  29. }
  30. /**
  31. * 启动服务
  32. */
  33. public function boot(): void
  34. {
  35. // 发布配置文件
  36. $this->publishes([
  37. __DIR__ . '/Config/transfer.php' => config_path('transfer.php'),
  38. ], 'transfer-config');
  39. // 注册命令
  40. $this->registerCommands();
  41. // 注册定时任务
  42. $this->registerSchedules();
  43. // 注册事件监听器
  44. $this->registerEventListeners();
  45. // 注册中间件
  46. $this->registerMiddleware();
  47. }
  48. /**
  49. * 不注册服务
  50. * @deprecated 不注册服务
  51. */
  52. protected function registerServices(): void
  53. {
  54. }
  55. /**
  56. * 注册命令
  57. */
  58. protected function registerCommands(): void
  59. {
  60. if ($this->app->runningInConsole()) {
  61. $this->commands([
  62. TransferProcessCommand::class,
  63. TransferStatsCommand::class,
  64. TransferCallbackCommand::class,
  65. TransferCleanCommand::class,
  66. InsertTransferAdminMenuCommand::class,
  67. FeeStatisticsCommand::class,
  68. TestFeeTransferCommand::class,
  69. ]);
  70. }
  71. }
  72. /**
  73. * 注册定时任务
  74. */
  75. protected function registerSchedules(): void
  76. {
  77. // 在应用完全启动后注册定时任务
  78. $this->app->booted(function () {
  79. // 每天22:00执行手续费统计
  80. Schedule::command('transfer:fee-statistics')
  81. ->dailyAt('00:10')
  82. ->description('Transfer模块手续费每日统计')
  83. ->withoutOverlapping() // 防止重复执行
  84. ->runInBackground(); // 后台运行
  85. });
  86. }
  87. /**
  88. * 注册事件监听器
  89. */
  90. protected function registerEventListeners(): void
  91. {
  92. // Transfer模块使用事件驱动架构
  93. // 事件监听器将在需要时自动注册
  94. }
  95. /**
  96. * 注册中间件
  97. */
  98. protected function registerMiddleware(): void
  99. {
  100. // Transfer模块不直接提供外部API
  101. // 通过OpenAPI模块进行对外开放和集成
  102. }
  103. /**
  104. * 获取提供的服务
  105. */
  106. public function provides(): array
  107. {
  108. return [
  109. 'transfer',
  110. 'transfer.api',
  111. ];
  112. }
  113. }