SyncReporting.php 951 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Reporting\ReportSync;
  4. use App\Support\SyncCommandLock;
  5. use Illuminate\Console\Command;
  6. class SyncReporting extends Command
  7. {
  8. protected $signature = 'reporting:sync {--full : 分批重新核对全部历史来源,不修改业务订单或钱包}';
  9. protected $description = '同步后台统一报表事实(默认增量,幂等,可重试)';
  10. public function handle(ReportSync $service, SyncCommandLock $lock): int
  11. {
  12. $exit = $lock->run('reporting:sync', function () use ($service) {
  13. $result = $service->sync((bool) $this->option('full'));
  14. $this->line(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
  15. return $result['errors'] > 0 ? self::FAILURE : self::SUCCESS;
  16. });
  17. if ($exit === null) $this->info('报表同步已在运行,跳过本次执行');
  18. return $exit ?? self::SUCCESS;
  19. }
  20. }