This commit is contained in:
wangjinlei
2026-04-10 11:19:20 +08:00
parent d92df3e103
commit b0f0d6461f
2 changed files with 250 additions and 23 deletions

View File

@@ -526,31 +526,40 @@ class References extends Base
* - type (可选):默认 0仅文本 main传空则处理所有 type
* - dry_run (可选)1=只预览不落库
*/
public function convertArticleMainCitationsToMycite($aParam = [])
public function convertArticleMainCitationsToMycite()
{
$aParam = empty($aParam) ? $this->request->post() : $aParam;
$pArticleId = intval($aParam['p_article_id'] ?? 0);
if ($pArticleId <= 0) {
return jsonError('p_article_id is required');
}
// $aParam = empty($aParam) ? $this->request->post() : $aParam;
// $pArticleId = intval($aParam['p_article_id'] ?? 0);
// if ($pArticleId <= 0) {
// return jsonError('p_article_id is required');
// }
//
// // 通过 production_article -> article_id确保是当前系统存在的文章
// $aArticle = $this->getArticle(['p_article_id' => $pArticleId]);
// $iStatus = empty($aArticle['status']) ? 0 : $aArticle['status'];
// if ($iStatus != 1) {
// return json_encode($aArticle);
// }
// $aArticle = empty($aArticle['data']) ? [] : $aArticle['data'];
// $articleId = intval($aArticle['article_id'] ?? 0);
// if ($articleId <= 0) {
// return jsonError('Article not found');
// }
// 通过 production_article -> article_id确保是当前系统存在的文章
$aArticle = $this->getArticle(['p_article_id' => $pArticleId]);
$iStatus = empty($aArticle['status']) ? 0 : $aArticle['status'];
if ($iStatus != 1) {
return json_encode($aArticle);
$aParam = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($aParam)){
return jsonError($rule->getError());
}
$aArticle = empty($aArticle['data']) ? [] : $aArticle['data'];
$articleId = intval($aArticle['article_id'] ?? 0);
if ($articleId <= 0) {
return jsonError('Article not found');
}
$dryRun = intval($aParam['dry_run'] ?? 0) === 1;
$type = isset($aParam['type']) ? $aParam['type'] : 0;
$type = $aParam['type'] ?? 0;
$p_info = $this->production_article_obj->where('article_id', $aParam['article_id'])->where('state', 0)->find();
$pArticleId = $p_info['p_article_id'];
$query = Db::name('article_main')
->where('article_id', $articleId)
->where('article_id', $aParam['article_id'])
->whereIn('state', [0, 2])
->order('sort asc');
if ($type !== '' && $type !== null) {
@@ -593,8 +602,7 @@ class References extends Base
->where('am_id', $amId)
->limit(1)
->update([
'content' => $new,
'update_time' => time(),
'content' => $new
]);
}
}
@@ -610,7 +618,7 @@ class References extends Base
}
return jsonSuccess([
'article_id' => $articleId,
'article_id' => $aParam['article_id'],
'p_article_id' => $pArticleId,
'dry_run' => $dryRun ? 1 : 0,
'total' => count($mains),
@@ -619,6 +627,97 @@ class References extends Base
]);
}
/**
* 批量更新 production_article_refer
*
* 参数:
* - list必填数组每项至少含 p_refer_id其余为可更新字段
* - p_article_id可选若传则校验每条记录均属该生产文章防止误改
*
* 可更新字段白名单author,title,joura,dateno,doilink,doi,refer_doi,refer_content,refer_frag,
* refer_type,isbn,index,is_change,is_ai_check,cs,is_ja,article_id
*/
public function batchUpdateRefer($aParam = [])
{
$aParam = empty($aParam) ? $this->request->post() : $aParam;
$list = isset($aParam['list']) ? $aParam['list'] : (isset($aParam['refer_list']) ? $aParam['refer_list'] : null);
if (is_string($list)) {
$list = json_decode($list, true);
}
if (!is_array($list) || $list === []) {
return jsonError('list is required and must be a non-empty array');
}
$pArticleIdCheck = isset($aParam['p_article_id']) ? intval($aParam['p_article_id']) : 0;
$allowed = [
'author', 'title', 'joura', 'dateno', 'doilink', 'doi', 'refer_doi',
'refer_content', 'refer_frag', 'refer_type', 'isbn', 'index',
'is_change', 'is_ai_check', 'cs', 'is_ja', 'article_id',
];
$ok = 0;
$failed = [];
Db::startTrans();
try {
foreach ($list as $idx => $row) {
if (!is_array($row)) {
$failed[] = ['index' => $idx, 'msg' => 'item must be object'];
continue;
}
$pReferId = intval(isset($row['p_refer_id']) ? $row['p_refer_id'] : 0);
if ($pReferId <= 0) {
$failed[] = ['index' => $idx, 'msg' => 'p_refer_id is required'];
continue;
}
$where = ['p_refer_id' => $pReferId, 'state' => 0];
$exist = Db::name('production_article_refer')->where($where)->find();
if (empty($exist)) {
$failed[] = ['p_refer_id' => $pReferId, 'msg' => 'reference not found or state!=0'];
continue;
}
if ($pArticleIdCheck > 0 && intval($exist['p_article_id']) !== $pArticleIdCheck) {
$failed[] = ['p_refer_id' => $pReferId, 'msg' => 'p_article_id mismatch'];
continue;
}
$update = [];
foreach ($allowed as $field) {
if (array_key_exists($field, $row)) {
$update[$field] = $row[$field];
}
}
if ($update === []) {
$failed[] = ['p_refer_id' => $pReferId, 'msg' => 'no updatable fields'];
continue;
}
$update['update_time'] = time();
if (!isset($update['is_change'])) {
$update['is_change'] = 1;
}
$result = Db::name('production_article_refer')->where($where)->limit(1)->update($update);
if ($result === false) {
$failed[] = ['p_refer_id' => $pReferId, 'msg' => 'update failed'];
continue;
}
$ok++;
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
return jsonError('batch update failed: ' . $e->getMessage());
}
return jsonSuccess([
'updated' => $ok,
'failed' => $failed,
'total' => count($list),
]);
}
/**
* 修改参考文献的信息
* @param p_refer_id 主键ID