| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Console\Commands;
- use App\Services\ThirdGameOrderService;
- use Illuminate\Console\Command;
- class ThirdGameOrderSync extends Command
- {
- protected $signature = 'third-game:sync-orders';
- protected $description = '同步 api-bet 最新10分钟(不含当前分钟)的实时游戏订单';
- public function handle(ThirdGameOrderService $service): int
- {
- $page = 1;
- $synced = 0;
- do {
- try {
- $result = $service->syncRealtime($page, 2000);
- } catch (\Throwable $e) {
- $this->error($e->getMessage());
- return self::FAILURE;
- }
- if (empty($result['ok'])) {
- $this->error((string) ($result['msg'] ?? '三方实时订单同步失败'));
- return self::FAILURE;
- }
- $synced += (int) ($result['synced'] ?? 0);
- $this->line(sprintf(
- 'page=%d received=%d synced=%d unmatched=%d',
- $page,
- (int) ($result['received'] ?? 0),
- (int) ($result['synced'] ?? 0),
- (int) ($result['unmatched_orders'] ?? 0)
- ));
- if (empty($result['has_more'])) {
- break;
- }
- if ($page >= 1000) {
- $this->error('实时订单分页超过1000页,已停止同步');
- return self::FAILURE;
- }
- $page++;
- } while (true);
- $this->info("实时订单同步完成,共写入或更新 {$synced} 条");
- return self::SUCCESS;
- }
- }
|