43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Real\Commands\Sync;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\Card\Bloc;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Domains\Card\Repositories\BlocRepository;
|
|
|
|
class BlocSync extends Command
|
|
{
|
|
protected $name = 'real:sync-bloc';
|
|
|
|
protected $description = '同步RD集团数据';
|
|
|
|
protected $carrier_operator = ['lt' => 0, 'yd' => 1, 'dx' => 2, 'qw' => 3];
|
|
|
|
public function handle()
|
|
{
|
|
$select = ['id', 'bloc_code as sn', "bloc_name as name", 'carrieroperator as carrier_operator', 'create_time as created_at', 'del'];
|
|
|
|
$blocs = DB::connection('real')->table('jxc_bloc_manage')->select($select)->get()->collect()->toArray();
|
|
$carders = DB::connection('real')->table('jxc_carder_manage')->select(['bloc_code', 'inside_card_from_sn'])->get()->collect()->toArray();
|
|
$carders = array_pluck($carders, 'inside_card_from_sn', 'bloc_code');
|
|
|
|
foreach ($blocs as &$item) {
|
|
$item['shorthand'] = $carders[$item['sn']] ?? '';
|
|
$item['carrier_operator'] = $this->carrier_operator[$item['carrier_operator']];
|
|
$item['created_at'] = Carbon::createFromTimestamp($item['created_at']);
|
|
$item['updated_at'] = date('Y-m-d H:i:s');
|
|
$item['deleted_at'] = $item['del'] ? date('Y-m-d H:i:s') : null;
|
|
unset($item['del']);
|
|
}
|
|
|
|
$blocs = array_values(array_keyBy($blocs, 'id'));
|
|
|
|
Bloc::upsert($blocs, 'id');
|
|
|
|
app(BlocRepository::class)->forgetCached();
|
|
}
|
|
}
|