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, ]); } } }