option('is_all'); $is_init = $this->option('is_init'); if ($is_init) { $bids = RententionBookList::where('sex', 2)->pluck('bid')->all(); foreach ($bids as $bid) { RententionBookService::saveRententionBook($bid); } } else if ($is_all) { $bids = $this->findAllRunBooks(); foreach ($bids as $bid) { $this->runBook($bid); } } else { $bid = $this->option('bid'); $begin_bid = $this->option('begin_bid'); $end_bid = $this->option('end_bid'); if ($begin_bid) { $bids = Book::where('id', '>=', $begin_bid) ->where('id', '<', $end_bid) ->orderBy('id', 'desc') ->pluck('id') ->all(); foreach ($bids as $bid) { $this->runBook($bid); } } else { $this->runBook($bid); } } Log::info("======计算章节留存率 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n")); print_r("======计算章节留存率 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n")); } public function findAllRunBooks() { $catetory_ids = BookCategory::where('pid', 2)->pluck('id')->all(); $new_bids = Book::where('created_at', '>=', date('Y-m-d', strtotime('-3 months'))) ->whereIn('category_id', $catetory_ids) ->pluck('id')->all(); $bids = BookConfig::whereIn('bid', $new_bids)->whereIn('is_on_shelf', [1, 2])->pluck('bid')->all(); $rentention_bids = RententionBookList::join('book_configs', 'book_configs.bid', 'rentention_book_list.bid') ->where([ 'is_updated' => 1, ])->where('type', '!=', RententionBookService::BelowStandard) ->where('sex', 2) ->whereIn('is_on_shelf', [1, 2]) ->pluck('rentention_book_list.bid')->all(); return array_merge( $rentention_bids, $bids ); } public function runBook(int $bid) { myLog('rentention_book')->info('bid: ' . $bid . ' begin: ' . date('Y-m-d H:i:s')); RententionBookService::runRentention($bid); RententionBookService::saveRententionBook($bid); myLog('rentention_book')->info('bid: ' . $bid . ' end: ' . date('Y-m-d H:i:s')); } }