TeamServiceProvider.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Module\Promotion\Providers;
  3. use App\Module\Promotion\Commands\CleanExpiredReferralCodesCommand;
  4. use App\Module\Promotion\Commands\RebuildRelationCacheCommand;
  5. use App\Module\Promotion\Commands\UpdateTalentLevelsCommand;
  6. use App\Module\Promotion\Events\ReferralCreatedEvent;
  7. use App\Module\Promotion\Events\ReferralUpdatedEvent;
  8. use App\Module\Promotion\Events\PromotionProfitCreatedEvent;
  9. use App\Module\Promotion\Listeners\DistributePromotionProfitListener;
  10. use App\Module\Promotion\Listeners\UpdateTalentLevelListener;
  11. use App\Module\Promotion\Listeners\UpdatePromotionCountsListener;
  12. use App\Module\Promotion\Logics\ReferralCodeLogic;
  13. use App\Module\Promotion\Logics\ReferralLogic;
  14. use App\Module\Promotion\Logics\RelationCacheLogic;
  15. use App\Module\Promotion\Logics\TalentLogic;
  16. use App\Module\Promotion\Logics\PromotionProfitLogic;
  17. use Illuminate\Support\Facades\Event;
  18. use Illuminate\Support\ServiceProvider;
  19. /**
  20. * 团队模块服务提供者
  21. *
  22. * 注册团队模块的服务、事件、命令等。
  23. */
  24. class PromotionServiceProvider extends ServiceProvider
  25. {
  26. /**
  27. * 注册服务
  28. *
  29. * @return void
  30. */
  31. public function register()
  32. {
  33. // 注册逻辑层类
  34. $this->app->singleton(ReferralLogic::class, function ($app) {
  35. return new ReferralLogic();
  36. });
  37. $this->app->singleton(RelationCacheLogic::class, function ($app) {
  38. return new RelationCacheLogic();
  39. });
  40. $this->app->singleton(TalentLogic::class, function ($app) {
  41. return new TalentLogic($app->make(ReferralLogic::class));
  42. });
  43. $this->app->singleton(PromotionProfitLogic::class, function ($app) {
  44. return new PromotionProfitLogic(
  45. $app->make(ReferralLogic::class),
  46. $app->make(TalentLogic::class)
  47. );
  48. });
  49. $this->app->singleton(ReferralCodeLogic::class, function ($app) {
  50. return new ReferralCodeLogic($app->make(ReferralLogic::class));
  51. });
  52. }
  53. /**
  54. * 启动服务
  55. *
  56. * @return void
  57. */
  58. public function boot()
  59. {
  60. // 注册事件和监听器
  61. Event::listen(ReferralCreatedEvent::class, UpdatePromotionCountsListener::class);
  62. Event::listen(ReferralCreatedEvent::class, UpdateTalentLevelListener::class);
  63. Event::listen(ReferralUpdatedEvent::class, UpdatePromotionCountsListener::class);
  64. Event::listen(ReferralUpdatedEvent::class, UpdateTalentLevelListener::class);
  65. Event::listen(PromotionProfitCreatedEvent::class, DistributePromotionProfitListener::class);
  66. // 注册命令
  67. if ($this->app->runningInConsole()) {
  68. $this->commands([
  69. CleanExpiredReferralCodesCommand::class,
  70. RebuildRelationCacheCommand::class,
  71. UpdateTalentLevelsCommand::class,
  72. ]);
  73. }
  74. }
  75. }