72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Real\Commands\Sync;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\Card\Card;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Domains\Card\Repositories\CardRepository;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
|
|
|
class CancelledSync extends Command
|
|
{
|
|
protected $name = 'real:sync-cancelled';
|
|
|
|
protected $description = '同步注销数据(每天同步昨天的注销数据)';
|
|
|
|
protected $limit = 1000;
|
|
|
|
public function handle()
|
|
{
|
|
$day = $this->getDay();
|
|
|
|
$cancelRecords = DB::connection('real')->table('jxc_cancel_card')
|
|
->where('cn_date', $day->format('Y-m-d'))
|
|
->where('cn_status', 1)->get();
|
|
|
|
$this->line('待同步条数:'.count($cancelRecords));
|
|
|
|
if (empty($cancelRecords)) {
|
|
return;
|
|
}
|
|
|
|
$cards = DB::connection('real')->table('jxc_cancel_card_item')
|
|
->whereIn('item_cn_id', $cancelRecords->pluck('cn_id')->toArray())->get();
|
|
|
|
$array = [];
|
|
|
|
foreach ($cards as $item) {
|
|
$array[] = [
|
|
'sim' => $item->item_sim,
|
|
'cancelled_at' => $day,
|
|
];
|
|
}
|
|
|
|
Card::updateBatch($array, 'sim::int8');
|
|
|
|
app(CardRepository::class)->forgetCached();
|
|
app(OrderCardPartitionRepository::class)->forgetCached();
|
|
}
|
|
|
|
protected function getDay()
|
|
{
|
|
if ($day = $this->argument('day')) {
|
|
if (!preg_match('/\d{4}-\d{1,2}-\d{1,2}/', $day)) {
|
|
throw new \App\Exceptions\InvalidArgumentException('请输入正确的日期 #示例: 2018-10-01');
|
|
}
|
|
|
|
return Carbon::parse($day)->startOfDay();
|
|
}
|
|
|
|
return Carbon::yesterday()->startOfDay();
|
|
}
|
|
|
|
protected function getArguments()
|
|
{
|
|
return [
|
|
['day', InputArgument::OPTIONAL, '要同步的数据日期,默认昨天 #示例: 2018-10-01'],
|
|
];
|
|
}
|
|
}
|