| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Module\UrsPromotion\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Console\Scheduling\Schedule;
- use App\Module\Farm\Events\CropHarvestedEvent;
- use App\Module\UrsPromotion\Listeners\CropHarvestedListener;
- /**
- * URS推广模块服务提供者
- */
- class UrsPromotionServiceProvider extends ServiceProvider
- {
- /**
- * 事件与监听器映射
- *
- * @var array
- */
- protected $listen = [
- CropHarvestedEvent::class => [
- CropHarvestedListener::class,
- ],
- ];
- /**
- * 注册服务
- */
- public function register(): void
- {
- // 注册命令
- if ($this->app->runningInConsole()) {
- $this->commands([
- \App\Module\UrsPromotion\Commands\TestUrsProfitCommand::class,
- \App\Module\UrsPromotion\Commands\TestUrsTalentCommand::class,
- \App\Module\UrsPromotion\Commands\InsertUrsPromotionAdminMenuCommand::class,
- \App\Module\UrsPromotion\Commands\UrsPromotionIntegrationTestCommand::class,
- \App\Module\UrsPromotion\Commands\TestFarmIntegrationCommand::class,
- \App\Module\UrsPromotion\Commands\TestPromotionRewardCommand::class,
- ]);
- }
- }
- /**
- * 启动服务
- */
- public function boot(): void
- {
- // 注册事件监听器
- $events = $this->app['events'];
- foreach ($this->listen as $event => $listeners) {
- foreach ($listeners as $listener) {
- $events->listen($event, $listener);
- }
- }
- // 加载API路由
- if (file_exists(__DIR__ . '/../Routes/api.php')) {
- require __DIR__ . '/../Routes/api.php';
- }
- // 注册定时任务
- $this->app->booted(function () {
- $schedule = $this->app->make(Schedule::class);
- // 每小时更新一次达人等级
- $schedule->command('urs:update-talents')->hourly();
- // 每天清理过期数据
- $schedule->command('urs:clean-data')->daily();
- });
- }
- }
|