get(self::CURSOR_KEY) ?: 946656000000; $utcDateTime = new UTCDateTime($microtime); Artisan::call('real:sync-bloc'); $blocs = app(BlocRepository::class)->get()->pluck('id', 'sn')->toArray(); $query = DB::connection('mongo')->table('tblCard') ->select(['cNo', 'iccid', 'imsi', 'comId', 'oType', 'saDate', 'sDate']) ->where('isDel', '<>', 1) ->where('sDate', '>', $utcDateTime) ->orderBy('sDate'); $total = $query->count(); $this->line('待同步条数:'.$total); $page = 1; while ($total) { echo $nextMicrotime . PHP_EOL; $res = $query->offset(($page - 1) * $this->limit)->limit($this->limit)->get(); $values = []; foreach ($res as $key => $value) { $activated_at = $value['saDate'] ? $value['saDate']->toDateTime()->format('Y-m-d H:i:s') : null; $sim = intval(preg_replace('/\D/', '', $value['cNo'])); $values[$sim] = [ 'sim' => $sim, 'imsi' => $value['imsi'] ?? '', 'iccid' => $value['iccid'] ?? '', 'bloc_id' => $blocs[$value['comId']] ?? 0, 'carrier_operator' => self::$carrierOperators[$value['oType']] ?? 255, 'activated_at' => $activated_at, 'created_at' => $value['sDate']->toDateTime()->format('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; $nextMicrotime = intval($value['sDate']->toDateTime()); $nextMicrotime = ($nextMicrotime > $microtime) ? $nextMicrotime : $microtime; } Card::upsert($values, 'sim', true); app(ConfigService::class)->set(self::CURSOR_KEY, $nextMicrotime); if ($page * $this->limit >= $total) { break; } $page++; } app(CardRepository::class)->forgetCached(); } }