| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Module\Promotion\Providers;
- use App\Module\Promotion\Commands\CleanExpiredReferralCodesCommand;
- use App\Module\Promotion\Commands\RebuildRelationCacheCommand;
- use App\Module\Promotion\Commands\UpdateTalentLevelsCommand;
- use App\Module\Promotion\Events\ReferralCreatedEvent;
- use App\Module\Promotion\Events\ReferralUpdatedEvent;
- use App\Module\Promotion\Events\PromotionProfitCreatedEvent;
- use App\Module\Promotion\Listeners\DistributePromotionProfitListener;
- use App\Module\Promotion\Listeners\UpdateTalentLevelListener;
- use App\Module\Promotion\Listeners\UpdatePromotionCountsListener;
- use App\Module\Promotion\Logics\ReferralCodeLogic;
- use App\Module\Promotion\Logics\ReferralLogic;
- use App\Module\Promotion\Logics\RelationCacheLogic;
- use App\Module\Promotion\Logics\TalentLogic;
- use App\Module\Promotion\Logics\PromotionProfitLogic;
- use Illuminate\Support\Facades\Event;
- use Illuminate\Support\ServiceProvider;
- /**
- * 团队模块服务提供者
- *
- * 注册团队模块的服务、事件、命令等。
- */
- class PromotionServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- *
- * @return void
- */
- public function register()
- {
- // 注册逻辑层类
- $this->app->singleton(ReferralLogic::class, function ($app) {
- return new ReferralLogic();
- });
- $this->app->singleton(RelationCacheLogic::class, function ($app) {
- return new RelationCacheLogic();
- });
- $this->app->singleton(TalentLogic::class, function ($app) {
- return new TalentLogic($app->make(ReferralLogic::class));
- });
- $this->app->singleton(PromotionProfitLogic::class, function ($app) {
- return new PromotionProfitLogic(
- $app->make(ReferralLogic::class),
- $app->make(TalentLogic::class)
- );
- });
- $this->app->singleton(ReferralCodeLogic::class, function ($app) {
- return new ReferralCodeLogic($app->make(ReferralLogic::class));
- });
- }
- /**
- * 启动服务
- *
- * @return void
- */
- public function boot()
- {
- // 注册事件和监听器
- Event::listen(ReferralCreatedEvent::class, UpdatePromotionCountsListener::class);
- Event::listen(ReferralCreatedEvent::class, UpdateTalentLevelListener::class);
- Event::listen(ReferralUpdatedEvent::class, UpdatePromotionCountsListener::class);
- Event::listen(ReferralUpdatedEvent::class, UpdateTalentLevelListener::class);
- Event::listen(PromotionProfitCreatedEvent::class, DistributePromotionProfitListener::class);
- // 注册命令
- if ($this->app->runningInConsole()) {
- $this->commands([
- CleanExpiredReferralCodesCommand::class,
- RebuildRelationCacheCommand::class,
- UpdateTalentLevelsCommand::class,
- ]);
- }
- }
- }
|