loadWholeBookOrderInfo(); Log::info('wholeBookOrderData end command'); } function loadWholeBookOrderInfo() { $bookArray = []; $lastCidArray = []; $pageSize = 10000; $totalCount = BookOrderService::getCount(); $totalPageCount = Ceil($totalCount / $pageSize); ////总页数 for ($pageIndex = 0; $pageIndex < $totalPageCount; $pageIndex++) { $startIndex = $pageIndex * $pageSize; $orderInfo = BookOrderService::getOrderInfos($startIndex, $startIndex + $pageSize); foreach ($orderInfo as $orderItem) { $bid = $orderItem->bid; $readRecod = ReadRecordService::getRecordByUidBid($orderItem->uid, $bid); if ($readRecod) { $read_cid = explode($readRecod, '_')[0]; if (isset($lastCidArray[$bid])) { $last_cid = $lastCidArray[$bid]; } else { $cidInfo = Book::where('id', $bid)->select('last_cid')->first(); $last_cid = $cidInfo->last_cid; $lastCidArray[$bid] = $last_cid; } if ($read_cid == $last_cid) { $bookArray[$bid] = isset($bookArray[$bid]) ? ($bookArray[$bid] + 1) : 1; } } } } foreach ($bookArray as $bid => $count) { DB::table('temp_book_order_stats')->where('bid', $bid)->update(['read_end_sub_user_num' => $count]); } } }