| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Console\Commands;
- use App\Services\ThirdGameCommissionService;
- use App\Support\SyncCommandLock;
- use Illuminate\Console\Command;
- class ThirdGameCommissionBackfill extends Command
- {
- protected $signature = 'third-game:backfill-commission {--retry-missing : 同时按当前费率补录上线后仍缺费率的订单}';
- protected $description = '在本地补录三方游戏抽成,已保存的费率保持固定';
- public function handle(ThirdGameCommissionService $service, SyncCommandLock $lock): int
- {
- if (!$service->migrated()) {
- // 定时任务在迁移前也会触发;未迁移时没有可补录的范围,跳过而不是每次报错。
- $this->info('三方抽成迁移尚未执行,跳过补录');
- return self::SUCCESS;
- }
- $exit = $lock->run('third-game:backfill-commission', function () use ($service) {
- // 历史订单(上线前)按上线费率快照补录;定时任务也会执行,直到历史订单补完,部署后无需手动运行。
- $exit = self::SUCCESS;
- try {
- $history = $service->backfill(false);
- $this->info(sprintf('历史订单:已补录 %d 笔,仍缺费率 %d 笔', $history['updated'], $history['remaining']));
- } catch (\RuntimeException $e) {
- $this->error('历史订单:' . $e->getMessage());
- $exit = self::FAILURE;
- }
- if ($this->option('retry-missing')) {
- $result = $service->backfill(true);
- $this->info(sprintf('上线后订单:已补录 %d 笔,仍缺费率 %d 笔', $result['updated'], $result['remaining']));
- }
- return $exit;
- });
- if ($exit === null) {
- $this->info('三方抽成补录正在运行');
- }
- return $exit ?? self::SUCCESS;
- }
- }
|