自动推广

This commit is contained in:
wangjinlei
2026-03-27 17:57:25 +08:00
parent 20a68ddc8a
commit 22947a56a4
5 changed files with 625 additions and 145 deletions

View File

@@ -242,70 +242,54 @@ class ExpertFinder extends Base
// ==================== Cron / Auto Fetch ====================
/**
* Daily cron: auto-fetch experts for every journal's fields via queue
* Daily cron: auto-fetch experts for all active fields in t_expert_fetch via queue.
* No longer tied to journals; t_expert_fetch is the sole source of crawl targets.
*/
public function dailyFetchAll()
{
$journalId = intval($this->request->param('journal_id', 0));
$perPage = max(10, intval($this->request->param('per_page', 200)));
$source = $this->request->param('source', 'pubmed');
$minYear = intval($this->request->param('min_year', date('Y') - 3));
$perPage = max(10, intval($this->request->param('per_page', 200)));
$source = $this->request->param('source', 'pubmed');
$minYear = intval($this->request->param('min_year', date('Y') - 3));
if ($journalId) {
$journals = Db::name('journal')->field("journal_id,issn,title")->where('journal_id', $journalId)->select();
} else {
$journals = Db::name('journal')->field("journal_id,issn,title")->where('state', 0)->select();
}
$fetchList = Db::name('expert_fetch')
->where('state', 0)
->select();
if (empty($journals)) {
return jsonSuccess(['msg' => 'No active journals found', 'queued' => 0]);
if (empty($fetchList)) {
return jsonSuccess(['msg' => 'No active fetch fields found', 'queued' => 0]);
}
$queued = 0;
$skipped = 0;
$details = [];
$todayStart = strtotime(date('Y-m-d'));
foreach ($journals as $journal) {
$issn = trim($journal['issn'] ?? '');
if (empty($issn)) continue;
$majors = Db::name('major_to_journal')
->alias('mtj')
->join('t_major m', 'm.major_id = mtj.major_id', 'left')
->where('mtj.journal_issn', $issn)
->where('mtj.mtj_state', 0)
->where("m.pid", "<>", 0)
->where('m.major_state', 0)
->column('m.major_title');
foreach ($fetchList as $item) {
$keyword = trim($item['field']);
$itemSource = trim($item['source'] ?: $source);
if ($keyword === '') continue;
$majors = array_unique(array_filter($majors));
if (empty($majors)) continue;
foreach ($majors as $keyword) {
$keyword = trim($keyword);
if (empty($keyword)) continue;
$fetchLog = $this->service->getFetchLog($keyword, $source);
if ($fetchLog['last_time'] >= $todayStart) {
$skipped++;
continue;
}
$delay = $queued * 10;
\think\Queue::later($delay, 'app\api\job\FetchExperts@fire', [
'field' => $keyword,
'source' => $source,
'per_page' => $perPage,
'min_year' => $minYear,
'journal_id' => $journal['journal_id'],
], 'FetchExperts');
$queued++;
$details[] = [
'journal' => $journal['title'] ?? $journal['journal_id'],
'keyword' => $keyword,
'delay_s' => $delay,
];
$fetchLog = $this->service->getFetchLog($keyword, $itemSource);
if ($fetchLog['last_time'] >= $todayStart) {
$skipped++;
continue;
}
$delay = $queued * 10;
\think\Queue::later($delay, 'app\api\job\FetchExperts@fire', [
'field' => $keyword,
'source' => $itemSource,
'per_page' => $perPage,
'min_year' => $minYear,
], 'FetchExperts');
$queued++;
$details[] = [
'expert_fetch_id' => $item['expert_fetch_id'],
'field' => $keyword,
'source' => $itemSource,
'delay_s' => $delay,
];
}
return jsonSuccess([
@@ -371,7 +355,7 @@ class ExpertFinder extends Base
], 'FetchExperts');
}
public function mytest()
public function fetchOneField()
{
$data = $this->request->post();
$rule = new Validate([