writeln("开始" . getDateFull()); $resp = (new \app\model\poem\PoemData)->where("is_done",0)->page($nextPage,10)->select(); if ($resp->isEmpty()) { $output->writeln("没有更多任务啦!===".getDateFull()); $nextPage = null; return self::SUCCESS; } $model = (new \app\model\poem\PoemContent); foreach ($resp as $val) { $output->writeln("标题:{$val['title']}==作者:{$val['author_name']}===链接地址:https://www.gushiji.cc/gushi/{$val['poem_id']}.html====".getDateFull()); $ql = QueryList::getInstance()->get("https://www.gushiji.cc/gushi/{$val['poem_id']}.html")->rules([ "data" => [".shicicontent","text"], "tags" => [".relatedCategory>ul>li>a","texts"], "notes" => [".shici-content","texts"], ])->query()->getData(function ($item,$key){ foreach ($item['notes'] as $k=>$v){ if ($k == 0) { $note = splitTransAndNote($v); } else { $note = $v; } $item['notes'][$k] = $note; } return $item; }); $respData = $ql->all(); $poemData = $model->where("poem_id",$val['poem_id'])->findOrEmpty(); if ($poemData->isEmpty()) { $output->writeln("【新增】标题:{$val['title']}====".getDateFull()); $poemData->insertGetId([ 'poem_id' => $val['poem_id'], "content" => $respData['data'], "trans" => $respData['notes'][0]['trans']??'', "note" => $respData['notes'][0]['note']??'', "review" => $respData['notes'][1]??'', "background" => $respData['notes'][2]??'', ]); } else { $output->writeln("【更新】标题:{$val['title']}====".getDateFull()); $poemData->save([ "content" => $respData['data'], "trans" => $respData['notes'][0]['trans']??'', "note" => $respData['notes'][0]['note']??'', "review" => $respData['notes'][1]??'', "background" => $respData['notes'][2]??'' ]); } (new \app\model\poem\PoemData)->where('id',$val['id'])->save(['is_done'=>1,"tags" => json_encode($respData['tags'])]); } $nextPage = $nextPage+1; $output->writeln("进入下一篇=={$nextPage}==".getDateFull()); } } catch (\Throwable $throwable) { echo $throwable->getMessage()."\n"; } return self::SUCCESS; } }