69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Virtual\Commands\Sync;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\Card\Card;
|
|
use App\Models\Virtual\Order;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use App\Domains\Virtual\Jobs\LogSyncJob;
|
|
use App\Domains\Config\Services\ConfigService;
|
|
use App\Domains\Virtual\Services\ProductService;
|
|
use App\Domains\Card\Repositories\BlocRepository;
|
|
use App\Domains\Card\Repositories\CardRepository;
|
|
use App\Domains\Virtual\Repositories\PackageRepository;
|
|
use App\Domains\Virtual\Repositories\ProductRepository;
|
|
|
|
class LogSync extends Command
|
|
{
|
|
protected $name = 'virtual:sync-log';
|
|
|
|
protected $description = '同步VD订单数据';
|
|
|
|
const CURSOR_KEY = 'sync_log_cursor';
|
|
|
|
protected $limit = 1000;
|
|
|
|
public function handle()
|
|
{
|
|
$maxId = app(ConfigService::class)->get(self::CURSOR_KEY) ?: 0;
|
|
|
|
$query = DB::connection('vd_old')->table('logs')->whereIn('type', array_keys(LogSyncJob::$types))
|
|
->where('id', '>', $maxId)->orderBy('id');
|
|
|
|
$nextId = $query->max('id');
|
|
|
|
$total = $query->count();
|
|
|
|
$this->line('待同步条数:'.$total);
|
|
|
|
if ($total) {
|
|
Artisan::call('virtual:sync-company');
|
|
Artisan::call('virtual:sync-package');
|
|
Artisan::call('virtual:sync-product');
|
|
}
|
|
|
|
$page = 1;
|
|
|
|
$jobs = new Collection();
|
|
|
|
while ($total) {
|
|
$page++;
|
|
|
|
if ($page * $this->limit >= $total) {
|
|
break;
|
|
}
|
|
|
|
$jobs->push(new LogSyncJob($page, $this->limit, $maxId));
|
|
}
|
|
|
|
$total && LogSyncJob::withChain($jobs->toArray())
|
|
->dispatch(1, $this->limit, $maxId)
|
|
->allOnQueue('sync');
|
|
|
|
$nextId && app(ConfigService::class)->set(self::CURSOR_KEY, $nextId);
|
|
}
|
|
}
|