From fc655f7aaa56e905df223d217f1db25c45abfb3a Mon Sep 17 00:00:00 2001 From: wyn <1074145239@qq.com> Date: Mon, 3 Aug 2026 11:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=93=E5=88=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Special.php | 105 ++++++++++++-- application/master/controller/Special.php | 161 ++++++++++++++++++++-- 2 files changed, 243 insertions(+), 23 deletions(-) diff --git a/application/api/controller/Special.php b/application/api/controller/Special.php index 5b87c74..580a40c 100644 --- a/application/api/controller/Special.php +++ b/application/api/controller/Special.php @@ -82,18 +82,46 @@ class Special extends Controller { $special_insert['intro'] = $data['intro']; $special_insert['keywords'] = $data['keywords']; $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_id = $this->journal_special_obj->insertGetId($special_insert); - //处理客座编辑 - $editor_insert['journal_id'] = $data['journal_id']; - $editor_insert['email'] = $data['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']; - $editor_id = $this->journal_special_editor_obj->insertGetId($editor_insert); + if (!$special_id) { + Db::rollback(); + return jsonError('system error'); + } + + // hasEditor 非 1:只创建专刊,不保存客座编辑信息 + if (!$hasEditor) { + Db::commit(); + return jsonSuccess(['journal_special_id' => intval($special_id), 'hasEditor' => 0]); + } + + //处理客座编辑:同期刊下相同邮箱已存在则复用,否则新建 + $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_id'] = $special_id; @@ -101,13 +129,13 @@ class Special extends Controller { $res = $this->journal_special_to_editor_obj->insert($to_insert); if($special_id&&$editor_id&&$res){ Db::commit(); - return jsonSuccess([]); + return jsonSuccess(['journal_special_id' => intval($special_id), 'hasEditor' => 1]); }else{ Db::rollback(); return jsonError('system error'); } } - + /** * @title 客座期刊特邀编辑(添加) * @description 客座期刊特邀编辑(添加) @@ -535,6 +563,59 @@ class Special extends Controller { } 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), + ], + ]); + } /** diff --git a/application/master/controller/Special.php b/application/master/controller/Special.php index b7ffaf4..8e7164f 100644 --- a/application/master/controller/Special.php +++ b/application/master/controller/Special.php @@ -94,7 +94,7 @@ class Special extends Controller { ->where('j_journal_special_to_editor.state',0) ->select(); 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; @@ -179,6 +179,36 @@ class Special extends Controller { $re['applys'] = $applys; 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 客座期刊(编辑客座期刊基础信息) @@ -204,7 +234,12 @@ class Special extends Controller { $update['icon'] = $data['icon']; $update['abstract'] = $data['abstract']; $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); return jsonSuccess([]); } @@ -239,8 +274,31 @@ class Special extends Controller { if(!$rule->check($data)){ return jsonError($rule->getError()); } - $insert['journal_id'] = $data['journal_id']; - $insert['email'] = trim($data['email']); + $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['last_name'] = trim($data['last_name']); $insert['address'] = trim($data['address']); @@ -248,8 +306,11 @@ class Special extends Controller { $insert['website'] = isset($data['website'])?trim($data['website']):''; $insert['orcid'] = isset($data['orcid'])?trim($data['orcid']):''; $insert['icon'] = isset($data['specialIcon'])?trim($data['specialIcon']):''; - $this->journal_special_editor_obj->insert($insert); - return jsonSuccess([]); + $editorId = $this->journal_special_editor_obj->insertGetId($insert); + 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(){ $data = $this->request->post(); - $insert['journal_special_id'] = $data['journal_special_id']; - $insert['journal_special_editor_id'] = $data['journal_special_editor_id']; - $insert['journal_id'] = $data['journal_id']; - + $specialId = intval($data['journal_special_id']); + $editorId = intval($data['journal_special_editor_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); - + return jsonSuccess([]); } @@ -375,6 +452,68 @@ class Special extends Controller { ->update(['state'=>1]); 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 客座期刊编辑(通过申请)