ThirdGameOrderSync.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\ThirdGameOrderService;
  4. use Illuminate\Console\Command;
  5. class ThirdGameOrderSync extends Command
  6. {
  7. protected $signature = 'third-game:sync-orders';
  8. protected $description = '同步 api-bet 最新10分钟(不含当前分钟)的实时游戏订单';
  9. public function handle(ThirdGameOrderService $service): int
  10. {
  11. $page = 1;
  12. $synced = 0;
  13. do {
  14. try {
  15. $result = $service->syncRealtime($page, 2000);
  16. } catch (\Throwable $e) {
  17. $this->error($e->getMessage());
  18. return self::FAILURE;
  19. }
  20. if (empty($result['ok'])) {
  21. $this->error((string) ($result['msg'] ?? '三方实时订单同步失败'));
  22. return self::FAILURE;
  23. }
  24. $synced += (int) ($result['synced'] ?? 0);
  25. $this->line(sprintf(
  26. 'page=%d received=%d synced=%d unmatched=%d',
  27. $page,
  28. (int) ($result['received'] ?? 0),
  29. (int) ($result['synced'] ?? 0),
  30. (int) ($result['unmatched_orders'] ?? 0)
  31. ));
  32. if (empty($result['has_more'])) {
  33. break;
  34. }
  35. if ($page >= 1000) {
  36. $this->error('实时订单分页超过1000页,已停止同步');
  37. return self::FAILURE;
  38. }
  39. $page++;
  40. } while (true);
  41. $this->info("实时订单同步完成,共写入或更新 {$synced} 条");
  42. return self::SUCCESS;
  43. }
  44. }