getDateTime(); $starttime = $datetime->copy()->startOfMonth()->startOfDay()->timestamp; $endtime = $datetime->copy()->endOfMonth()->endOfDay()->timestamp; $cancelRecords = DB::connection('real')->table('jxc_cancel_card') ->where('cn_create_time', '>=', $starttime) ->where('cn_create_time', '<=', $endtime) ->where('cn_status', 1)->get()->keyBy('cn_id'); $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(); $cards = $cards->chunk(1000); foreach ($cards as $values) { $array = []; foreach ($values as $item) { $record = $cancelRecords[$item->item_cn_id]; $array[] = [ 'sim' => $item->item_sim, 'cancelled_at' => Carbon::createFromTimestamp($record->cn_create_time), ]; } Card::updateBatch($array, 'sim::int8'); } app(CardRepository::class)->forgetCached(); app(OrderCardPartitionRepository::class)->forgetCached(); } }