This commit is contained in:
wyn
2026-08-03 11:08:03 +08:00
parent 05af67bc1a
commit fc655f7aaa
2 changed files with 243 additions and 23 deletions

View File

@@ -82,18 +82,46 @@ class Special extends Controller {
$special_insert['intro'] = $data['intro']; $special_insert['intro'] = $data['intro'];
$special_insert['keywords'] = $data['keywords']; $special_insert['keywords'] = $data['keywords'];
$special_insert['deadline'] = $data['deadline']; $special_insert['deadline'] = $data['deadline'];
if(isset($data['specialIcon']))$special_insert['icon'] = $data['specialIcon'];
// 记录是否有客座编辑(入库 + 流程控制)
$hasEditor = (isset($data['hasEditor']) && intval($data['hasEditor']) === 1) ? 1 : 0;
$special_insert['hasEditor'] = $hasEditor;
$special_insert['ctime'] = time(); $special_insert['ctime'] = time();
$special_id = $this->journal_special_obj->insertGetId($special_insert); $special_id = $this->journal_special_obj->insertGetId($special_insert);
//处理客座编辑 if (!$special_id) {
$editor_insert['journal_id'] = $data['journal_id']; Db::rollback();
$editor_insert['email'] = $data['email']; return jsonError('system error');
$editor_insert['first_name'] = $data['first_name']; }
$editor_insert['last_name'] = $data['last_name'];
$editor_insert['address'] = $data['address']; // hasEditor 非 1只创建专刊不保存客座编辑信息
$editor_insert['interests'] = $data['interests']; if (!$hasEditor) {
$editor_insert['website'] = $data['website']; Db::commit();
$editor_insert['orcid'] = $data['orcid']; return jsonSuccess(['journal_special_id' => intval($special_id), 'hasEditor' => 0]);
$editor_id = $this->journal_special_editor_obj->insertGetId($editor_insert); }
//处理客座编辑:同期刊下相同邮箱已存在则复用,否则新建
$email = trim($data['email']);
$existEditor = $this->journal_special_editor_obj
->where('journal_id', $data['journal_id'])
->where('email', $email)
->where('state', 0)
->find();
if ($existEditor) {
$editor_id = $existEditor['journal_special_editor_id'];
} else {
$editor_insert['journal_id'] = $data['journal_id'];
$editor_insert['email'] = $email;
$editor_insert['first_name'] = $data['first_name'];
$editor_insert['last_name'] = $data['last_name'];
$editor_insert['address'] = $data['address'];
$editor_insert['interests'] = $data['interests'];
$editor_insert['website'] = $data['website'];
$editor_insert['orcid'] = $data['orcid'];
if (isset($data['icon'])) {
$editor_insert['icon'] = $data['icon'];
}
$editor_id = $this->journal_special_editor_obj->insertGetId($editor_insert);
}
//处理客座编辑关系信息 //处理客座编辑关系信息
$to_insert['journal_special_editor_id'] = $editor_id; $to_insert['journal_special_editor_id'] = $editor_id;
$to_insert['journal_special_id'] = $special_id; $to_insert['journal_special_id'] = $special_id;
@@ -101,13 +129,13 @@ class Special extends Controller {
$res = $this->journal_special_to_editor_obj->insert($to_insert); $res = $this->journal_special_to_editor_obj->insert($to_insert);
if($special_id&&$editor_id&&$res){ if($special_id&&$editor_id&&$res){
Db::commit(); Db::commit();
return jsonSuccess([]); return jsonSuccess(['journal_special_id' => intval($special_id), 'hasEditor' => 1]);
}else{ }else{
Db::rollback(); Db::rollback();
return jsonError('system error'); return jsonError('system error');
} }
} }
/** /**
* @title 客座期刊特邀编辑(添加) * @title 客座期刊特邀编辑(添加)
* @description 客座期刊特邀编辑(添加) * @description 客座期刊特邀编辑(添加)
@@ -535,6 +563,59 @@ class Special extends Controller {
} }
return $frag; return $frag;
} }
/**
* @title 通过期刊+标题+截止日期查询专刊ID
* @description 供外部系统在 addSpecial 成功但未返回ID时反查
* @url /api/Special/getSpecialIdByUnique
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:title type:string require:1 desc:专刊标题
* @param name:deadline type:string require:1 desc:截止日期
*/
public function getSpecialIdByUnique() {
$data = $this->request->post();
$journalId = intval(isset($data['journal_id']) ? $data['journal_id'] : 0);
$title = trim(isset($data['title']) ? $data['title'] : '');
$deadline = trim(isset($data['deadline']) ? $data['deadline'] : '');
if ($journalId <= 0 || $title === '' || $deadline === '') {
return json(['code' => 1, 'msg' => 'journal_id/title/deadline required']);
}
// 优先精确匹配包含非1状态避免“刚创建未发布”查不到
$special = $this->journal_special_obj
->where('journal_id', $journalId)
->where('title', $title)
->where('deadline', $deadline)
->where('state', '<>', 1)
->order('journal_special_id desc')
->find();
if (!$special) {
// 次优:同标题最新一条(仍排除删除态)
$special = $this->journal_special_obj
->where('journal_id', $journalId)
->where('title', $title)
->where('state', '<>', 1)
->order('journal_special_id desc')
->find();
}
if (!$special) {
return json(['code' => 1, 'msg' => 'special not found']);
}
return json([
'code' => 0,
'msg' => 'success',
'data' => [
'journal_special_id' => intval($special['journal_special_id']),
'title' => isset($special['title']) ? $special['title'] : '',
'deadline' => isset($special['deadline']) ? $special['deadline'] : '',
'state' => intval(isset($special['state']) ? $special['state'] : 0),
],
]);
}
/** /**

View File

@@ -94,7 +94,7 @@ class Special extends Controller {
->where('j_journal_special_to_editor.state',0) ->where('j_journal_special_to_editor.state',0)
->select(); ->select();
foreach ($caches as $val){ foreach ($caches as $val){
$frag = $frag == ''?$val['first_name'].' '.$val['last_name']:','.$val['first_name'].' '.$val['last_name']; $frag = $frag == '' ? $val['first_name'].' '.$val['last_name'] : $frag.', '.$val['first_name'].' '.$val['last_name'];
} }
$list[$k]['editor'] = $frag; $list[$k]['editor'] = $frag;
@@ -179,6 +179,36 @@ class Special extends Controller {
$re['applys'] = $applys; $re['applys'] = $applys;
return jsonSuccess($re); return jsonSuccess($re);
} }
/**
* 按期刊+邮箱查询客座编辑是否已存在
* @url /master/Special/getSpecialEditorByEmail
*/
public function getSpecialEditorByEmail(){
$data = $this->request->post();
$rule = new Validate([
'journal_id' => 'require|number',
'email' => 'require',
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$email = trim($data['email']);
$exist = $this->journal_special_editor_obj
->where('journal_id', intval($data['journal_id']))
->where('email', $email)
->find();
if (!$exist) {
return jsonSuccess([
'journal_special_editor_id' => 0,
'email' => $email,
]);
}
return jsonSuccess([
'journal_special_editor_id' => intval($exist['journal_special_editor_id']),
'email' => $email,
]);
}
/** /**
* @title 客座期刊(编辑客座期刊基础信息) * @title 客座期刊(编辑客座期刊基础信息)
@@ -204,7 +234,12 @@ class Special extends Controller {
$update['icon'] = $data['icon']; $update['icon'] = $data['icon'];
$update['abstract'] = $data['abstract']; $update['abstract'] = $data['abstract'];
$update['keywords'] = $data['keywords']; $update['keywords'] = $data['keywords'];
$update['deadline'] = $data['deadline']; if (isset($data['deadline'])) {
$update['deadline'] = $data['deadline'];
}
if (isset($data['hasEditor'])) {
$update['hasEditor'] = (intval($data['hasEditor']) === 1) ? 1 : 0;
}
$this->journal_special_obj->where('journal_special_id',$data['journal_special_id'])->update($update); $this->journal_special_obj->where('journal_special_id',$data['journal_special_id'])->update($update);
return jsonSuccess([]); return jsonSuccess([]);
} }
@@ -239,8 +274,31 @@ class Special extends Controller {
if(!$rule->check($data)){ if(!$rule->check($data)){
return jsonError($rule->getError()); return jsonError($rule->getError());
} }
$insert['journal_id'] = $data['journal_id']; $email = trim($data['email']);
$insert['email'] = trim($data['email']); $journalId = intval($data['journal_id']);
$exist = $this->journal_special_editor_obj
->where('journal_id', $journalId)
->where('email', $email)
->find();
if ($exist) {
$editorId = intval($exist['journal_special_editor_id']);
$update = [
'first_name' => trim($data['first_name']),
'last_name' => trim($data['last_name']),
'address' => trim($data['address']),
'interests' => isset($data['interests'])?trim($data['interests']):'',
'website' => isset($data['website'])?trim($data['website']):'',
'orcid' => isset($data['orcid'])?trim($data['orcid']):'',
];
if (isset($data['specialIcon']) && trim($data['specialIcon']) !== '') {
$update['icon'] = trim($data['specialIcon']);
}
$this->journal_special_editor_obj->where('journal_special_editor_id', $editorId)->update($update);
return jsonSuccess(['journal_special_editor_id' => $editorId]);
}
$insert['journal_id'] = $journalId;
$insert['email'] = $email;
$insert['first_name'] = trim($data['first_name']); $insert['first_name'] = trim($data['first_name']);
$insert['last_name'] = trim($data['last_name']); $insert['last_name'] = trim($data['last_name']);
$insert['address'] = trim($data['address']); $insert['address'] = trim($data['address']);
@@ -248,8 +306,11 @@ class Special extends Controller {
$insert['website'] = isset($data['website'])?trim($data['website']):''; $insert['website'] = isset($data['website'])?trim($data['website']):'';
$insert['orcid'] = isset($data['orcid'])?trim($data['orcid']):''; $insert['orcid'] = isset($data['orcid'])?trim($data['orcid']):'';
$insert['icon'] = isset($data['specialIcon'])?trim($data['specialIcon']):''; $insert['icon'] = isset($data['specialIcon'])?trim($data['specialIcon']):'';
$this->journal_special_editor_obj->insert($insert); $editorId = $this->journal_special_editor_obj->insertGetId($insert);
return jsonSuccess([]); if (!$editorId) {
return jsonError('add special editor failed');
}
return jsonSuccess(['journal_special_editor_id' => intval($editorId)]);
} }
/** /**
@@ -348,12 +409,28 @@ class Special extends Controller {
*/ */
public function addSpecialToEditor(){ public function addSpecialToEditor(){
$data = $this->request->post(); $data = $this->request->post();
$insert['journal_special_id'] = $data['journal_special_id']; $specialId = intval($data['journal_special_id']);
$insert['journal_special_editor_id'] = $data['journal_special_editor_id']; $editorId = intval($data['journal_special_editor_id']);
$insert['journal_id'] = $data['journal_id']; $journalId = intval($data['journal_id']);
$exist = $this->journal_special_to_editor_obj
->where('journal_special_id', $specialId)
->where('journal_special_editor_id', $editorId)
->find();
if ($exist) {
if (intval($exist['state']) !== 0) {
$this->journal_special_to_editor_obj
->where('journal_special_to_editor_id', $exist['journal_special_to_editor_id'])
->update(['state' => 0]);
}
return jsonSuccess([]);
}
$insert['journal_special_id'] = $specialId;
$insert['journal_special_editor_id'] = $editorId;
$insert['journal_id'] = $journalId;
$this->journal_special_to_editor_obj->insert($insert); $this->journal_special_to_editor_obj->insert($insert);
return jsonSuccess([]); return jsonSuccess([]);
} }
@@ -375,6 +452,68 @@ class Special extends Controller {
->update(['state'=>1]); ->update(['state'=>1]);
return jsonSuccess([]); return jsonSuccess([]);
} }
/**
* @title 客座期刊编辑(按邮箱解除客座期刊与作者的对应关系)
* @description 客座期刊编辑(按邮箱解除客座期刊与作者的对应关系)
* @author wangjinlei
* @url /master/Special/delSpecialToEditorByEmail
* @method POST
*
* @param name:journal_special_id type:int require:1 desc:客座期刊id
* @param name:email type:string require:1 desc:客座编辑邮箱
*/
public function delSpecialToEditorByEmail(){
$data = $this->request->post();
$rule = new Validate([
'journal_special_id' => 'require|number',
'email' => 'require',
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$specialId = intval($data['journal_special_id']);
$email = trim($data['email']);
$editorIds = $this->journal_special_editor_obj
->where('email', $email)
->where('state', 0)
->column('journal_special_editor_id');
if(empty($editorIds)){
return jsonError('editor not found');
}
$this->journal_special_to_editor_obj
->where('journal_special_id', $specialId)
->where('journal_special_editor_id', 'in', $editorIds)
->where('state', '<>', 1)
->update(['state' => 1]);
return jsonSuccess([]);
}
/**
* @title 客座期刊编辑(解除专刊下全部客座编辑绑定)
* @description 客座期刊编辑(解除专刊下全部客座编辑绑定)
* @author wangjinlei
* @url /master/Special/delAllSpecialToEditor
* @method POST
*
* @param name:journal_special_id type:int require:1 desc:客座期刊id
*/
public function delAllSpecialToEditor(){
$data = $this->request->post();
$rule = new Validate([
'journal_special_id' => 'require|number',
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->journal_special_to_editor_obj
->where('journal_special_id', $data['journal_special_id'])
->where('state', '<>', 1)
->update(['state' => 1]);
return jsonSuccess([]);
}
/** /**
* @title 客座期刊编辑(通过申请) * @title 客座期刊编辑(通过申请)