901 lines
33 KiB
PHP
901 lines
33 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\Queue;
|
|
use think\Validate;
|
|
|
|
/**
|
|
* @title 公共管理相关
|
|
* @description 公共管理相关
|
|
*/
|
|
class Production extends Controller
|
|
{
|
|
protected $article_obj = '';
|
|
protected $user_obj = '';
|
|
protected $user_act_obj = '';
|
|
protected $journal_obj = '';
|
|
protected $user_log_obj = '';
|
|
protected $user_reviewer_info_obj = '';
|
|
protected $reviewer_major_obj = '';
|
|
protected $reviewer_to_journal_obj = '';
|
|
protected $article_reviewer_question_obj = '';
|
|
protected $article_msg_obj = '';
|
|
protected $article_file_obj = '';
|
|
protected $article_reviewer_obj = '';
|
|
protected $article_author_obj = '';
|
|
protected $article_transfer_obj = '';
|
|
protected $chief_to_journal_obj = '';
|
|
protected $login_auto_obj = '';
|
|
protected $major_obj = "";
|
|
protected $major_to_journal_obj = '';
|
|
protected $reviewer_from_author_obj = '';
|
|
protected $article_dialog_obj = '';
|
|
protected $article_proposal_obj = '';
|
|
protected $user_black_obj = '';
|
|
protected $user_reviewer_recommend_obj = '';
|
|
protected $ts_obj = '';
|
|
protected $ts_refer_obj = '';
|
|
protected $ts_frag_obj = '';
|
|
protected $online_obj = '';
|
|
protected $production_article_obj = '';
|
|
protected $production_article_author_obj = '';
|
|
protected $production_article_organ_obj = '';
|
|
protected $production_article_refer_obj = '';
|
|
protected $production_article_author_to_organ_obj = '';
|
|
protected $production_article_frag_obj = '';
|
|
|
|
public function __construct(\think\Request $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->user_obj = Db::name('user');
|
|
$this->user_act_obj = Db::name('user_act');
|
|
$this->article_obj = Db::name('article');
|
|
$this->journal_obj = Db::name('journal');
|
|
$this->user_log_obj = Db::name('user_log');
|
|
$this->user_reviewer_info_obj = Db::name("user_reviewer_info");
|
|
$this->reviewer_major_obj = Db::name('reviewer_major');
|
|
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
|
|
$this->article_reviewer_question_obj = Db::name('article_reviewer_question');
|
|
$this->article_msg_obj = Db::name('article_msg');
|
|
$this->article_file_obj = Db::name('article_file');
|
|
$this->article_reviewer_obj = Db::name('article_reviewer');
|
|
$this->article_author_obj = Db::name('article_author');
|
|
$this->article_transfer_obj = Db::name('article_transfer');
|
|
$this->chief_to_journal_obj = Db::name('chief_to_journal');
|
|
$this->login_auto_obj = Db::name('login_auto');
|
|
$this->major_obj = Db::name("major");
|
|
$this->major_to_journal_obj = Db::name('major_to_journal');
|
|
$this->reviewer_from_author_obj = Db::name("reviewer_from_author");
|
|
$this->article_dialog_obj = Db::name('article_dialog');
|
|
$this->article_proposal_obj = Db::name('article_proposal');
|
|
$this->user_black_obj = Db::name('user_black');
|
|
$this->user_reviewer_recommend_obj = Db::name('user_reviewer_recommend');
|
|
$this->ts_obj = Db::name('ts');
|
|
$this->ts_refer_obj = Db::name('ts_refer');
|
|
$this->ts_frag_obj = Db::name('ts_frag');
|
|
$this->online_obj = Db::name('online');
|
|
$this->production_article_obj = Db::name('production_article');
|
|
$this->production_article_author_obj = Db::name('production_article_author');
|
|
$this->production_article_organ_obj = Db::name('production_article_organ');
|
|
$this->production_article_refer_obj = Db::name('production_article_refer');
|
|
$this->production_article_author_to_organ_obj = Db::name('production_article_author_to_organ');
|
|
$this->production_article_frag_obj = Db::name('production_article_frag');
|
|
}
|
|
|
|
/**
|
|
* 添加生产实例
|
|
*/
|
|
public function addProduction()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$check = $this->production_article_obj->where('article_id', $data['article_id'])->where('state', 0)->find();
|
|
if ($check) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
|
|
$article_info = $this->article_obj->where('article_id', $data['article_id'])->find();
|
|
$files = $this->article_file_obj
|
|
->where('article_id', $article_info['article_id'])
|
|
->where('type_name', 'manuscirpt')
|
|
->order('ctime desc')
|
|
->limit(1)
|
|
->select();
|
|
if (count($files) == 0) {
|
|
return jsonError('No Manuscript');
|
|
}
|
|
$url = "http://ts.tmrjournals.com/api/typeset/webReaddoc";
|
|
$program['fileRoute'] = "https://submission.tmrjournals.com/public/" . $files[0]['file_url'];
|
|
$res = object_to_array(json_decode(myPost($url, $program)));
|
|
|
|
$file_runs = $res['data'];
|
|
|
|
//整理信息
|
|
$frag = [];
|
|
$aa = [];
|
|
$frag['title'] = $article_info['title'];
|
|
$start_refer = false;
|
|
foreach ($file_runs as $k => $v) {
|
|
if ($start_refer && $v != '') {
|
|
if (strlen($v) > 500) {
|
|
$start_refer = false;
|
|
$frag['main'][] = $v;
|
|
continue;
|
|
}
|
|
$frag['references'][] = $v;
|
|
continue;
|
|
}
|
|
$g_val = trim(preg_replace('/\<.*?\>/', '', $v));
|
|
$aa[] = $g_val;
|
|
|
|
if ((strpos(strtolower(trim($g_val)), "keyword") == 0 || strpos(strtolower(trim($g_val)), "keyword") == 1) && !isset($frag['keywords'])) {
|
|
$frag['keywords'] = $v;
|
|
continue;
|
|
}
|
|
if (strtolower($g_val) == 'reference:' || strtolower($g_val) == 'references:' || strtolower($g_val) == 'references' || strtolower($g_val) == 'reference') {
|
|
$start_refer = true;
|
|
continue;
|
|
}
|
|
$frag['main'][] = $v;
|
|
}
|
|
|
|
$insert['main'] = isset($frag['main']) ? json_encode($frag['main']) : '';
|
|
$insert['article_id'] = $data['article_id'];
|
|
$insert['journal_id'] = $article_info['journal_id'];
|
|
$insert['ctime'] = time();
|
|
$this->production_article_obj->insert($insert);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 删除生产实例
|
|
*/
|
|
public function delProduction()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$this->production_article_obj->where('p_article_id', $data['p_article_id'])->update(['state' => 1]);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 编辑生产实例
|
|
*/
|
|
public function editProduction()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number',
|
|
'journal_stage_id' => 'require',
|
|
'title' => 'require',
|
|
'type' => 'require',
|
|
'icon' => 'require',
|
|
'tradition_tag' => 'require',
|
|
'tradition' => 'require',
|
|
'abstract' => 'require',
|
|
'acknowledgment' => 'require',
|
|
'abbreviation' =>'require',
|
|
'keywords' => 'require',
|
|
'author_contribution'=>'require',
|
|
'fund' => 'require',
|
|
'abbr' => 'require',
|
|
'pub_date' => 'require',
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find();
|
|
$journal_info = $this->journal_obj->where('journal_id', $p_info['journal_id'])->find();
|
|
|
|
|
|
$update['title'] = trim($data['title']);
|
|
$update['journal_stage_id'] = $data['journal_stage_id'];
|
|
$update['type'] = trim($data['type']);
|
|
$update['icon'] = trim($data['icon']);
|
|
$update['tradition_tag'] = trim($data['tradition_tag']);
|
|
$update['tradition'] = trim($data['tradition']);
|
|
$update['author_contribution'] = trim($data['author_contribution']);
|
|
$update['mhoo'] = isset($data['mhoo']) ? trim($data['mhoo']) : '';
|
|
$update['ltai'] = isset($data['ltai']) ? trim($data['ltai']) : '';
|
|
$update['abstract'] = trim($data['abstract']);
|
|
$update['keywords'] = trim($data['keywords']);
|
|
$update['abbreviation'] = trim($data['abbreviation']);
|
|
$update['acknowledgment'] = trim($data['acknowledgment']);
|
|
$update['fund'] = trim($data['fund']);
|
|
$update['abbr'] = trim($data['abbr']);
|
|
$update['pub_date'] = trim($data['pub_date']);
|
|
$update['npp'] = isset($data['npp'])?$data['npp']:'';
|
|
|
|
//生成doi号
|
|
$doi = '';
|
|
if ($p_info['doi'] == '') {
|
|
$url = 'http://journalapi.tmrjournals.com/public/index.php/master/Journal/getStageDetail';
|
|
$cs['journal_stage_id'] = $data['journal_stage_id'];
|
|
$list = object_to_array(json_decode(myPost($url, $cs)));
|
|
$re = $list['data']['stage'];
|
|
$doi = $this->createdoi($re['stage_year'], $re['stage_vol'], $journal_info['abbr']);
|
|
}else{
|
|
$doi = $p_info['doi'];
|
|
}
|
|
$update['doi'] = $doi;
|
|
|
|
|
|
|
|
$this->production_article_obj->where('p_article_id', $data['p_article_id'])->update($update);
|
|
return jsonSuccess($update);
|
|
}
|
|
|
|
/**
|
|
* 获取文章排版结果列表
|
|
*/
|
|
public function getArticleFrags(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$list = $this->production_article_frag_obj->where('p_article_id',$data['p_article_id'])->where('state',0)->select();
|
|
|
|
$re['frags'] = $list;
|
|
return jsonSuccess($re);
|
|
|
|
}
|
|
|
|
/**
|
|
* 编辑文章主要内容
|
|
*/
|
|
public function editMainContent(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number',
|
|
'main'=>'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$update['main'] = json_encode($data['main']);
|
|
$this->production_article_obj->where('p_article_id',$data['p_article_id'])->update($update);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
|
|
private function createdoi($year, $vol, $abbr)
|
|
{
|
|
$frag = '';
|
|
$doi = $abbr . $year . $vol . rand(1000, 9999);
|
|
$frag = $doi;
|
|
$check = $this->production_article_obj->where('doi', $doi)->find();
|
|
if ($check) {
|
|
$frag = $this->createdoi($year, $vol, $abbr);
|
|
}
|
|
return $frag;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取引用文献列表
|
|
*/
|
|
public function getReferList(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$list = $this->production_article_refer_obj->where('p_article_id',$data['p_article_id'])->where('state',0)->select();
|
|
$re['refers'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
/**
|
|
* 修改参考文献的最终结果
|
|
*/
|
|
public function editReferFrag()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_refer_id' => 'require',
|
|
'refer_frag' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$update['refer_frag'] = trim($data['refer_frag']);
|
|
$updata['cs'] = 1;
|
|
$this->production_article_refer_obj->where('p_refer_id',$data['p_refer_id'])->update($updata);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 获取生产实例列表
|
|
*/
|
|
public function getProductionList()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'editor_id' => 'require|number',
|
|
'journal_id' => 'require',
|
|
'pageIndex' => 'require',
|
|
'pageSize' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$journalids = [];
|
|
if ($data['journal_id'] == 0) {
|
|
$journalids = $this->journal_obj->where('editor_id', $data['editor_id'])->column('journal_id');
|
|
}
|
|
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
|
|
$list = $this->production_article_obj->where('journal_id', 'in', $journalids)->where('state', 0)->limit($limit_start, $data['pageSize'])->select();
|
|
$count = $this->production_article_obj->where('journal_id', 'in', $journalids)->where('state', 0)->count();
|
|
$re['productions'] = $list;
|
|
$re['count'] = $count;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
|
|
/**
|
|
* 排版主方法入口
|
|
*/
|
|
public function doTypeSetting()
|
|
{
|
|
$data = $this->request->post();
|
|
// 验证规则
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$p_info = $this->production_article_obj->where('p_article_id',$data['p_article_id'])->find();
|
|
$article_info = $this->article_obj->where('article_id', $p_info['article_id'])->find();
|
|
$journal_info = $this->journal_obj->where('journal_id', $p_info['journal_id'])->find();
|
|
$editor_info = $this->user_obj->where('user_id', $journal_info['editor_id'])->find();
|
|
|
|
$typesetInfo = [];
|
|
$typesetInfo['info_title'] = $p_info['title'];
|
|
$typesetInfo['info_type'] = $p_info['type'];
|
|
$typesetInfo['doi'] = $p_info['doi'];
|
|
$typesetInfo['topic'] = '';
|
|
$typesetInfo['mainText'] = $p_info['main'];
|
|
|
|
$au_res = $this->authorFormate($data['p_article_id']);
|
|
|
|
$typesetInfo['author'] = $au_res['author'];
|
|
$typesetInfo['authorAddress'] = $au_res['address'];
|
|
$typesetInfo['authorContribution'] = $p_info['author_contribution'];
|
|
|
|
//查询通讯作者
|
|
$corr_authors = $this->production_article_author_obj->where('p_article_id',$data['p_article_id'])->where('is_report',1)->where('state',0)->select();
|
|
$corrauthor = '';
|
|
$corremail = '';
|
|
foreach($corr_authors as $v){
|
|
$corrauthor .= $v['first_name']. ' '.$v['last_name'].'. ';
|
|
$corremail .= $v['email'].'. ';
|
|
}
|
|
$typesetInfo['authorCorresponding'] = substr(trim($corrauthor),0,-1);
|
|
$typesetInfo['authorCorrespondingEmail'] = substr(trim($corremail),0,-1);
|
|
$typesetInfo['traditon'] = $p_info['tradition'];
|
|
$typesetInfo['journal'] = $journal_info['title'];
|
|
$typesetInfo['jabbr'] = $journal_info['jabbr'];
|
|
|
|
//查询分期
|
|
$url = 'http://journalapi.tmrjournals.com/public/index.php/master/Journal/getStageDetail';
|
|
$cs['journal_stage_id'] = $p_info['journal_stage_id'];
|
|
$list = object_to_array(json_decode(myPost($url, $cs)));
|
|
$stage_re = $list['data']['stage'];
|
|
|
|
$typesetInfo['stage'] = $stage_re['stage_year'].';'.$stage_re['stage_vol'].'('.$stage_re['stage_no'].'):'.$p_info['npp'];//2022;6(1):17
|
|
$typesetInfo['little_author'] = $p_info['abbr'];
|
|
$typesetInfo['website'] = $journal_info['website'];
|
|
$typesetInfo['acknowledgment'] = $p_info['acknowledgment'];
|
|
$typesetInfo['received_date'] = date("d F Y", $article_info['ctime']);;
|
|
$typesetInfo['accepted_date'] = date("d F Y", $article_info['rtime']);
|
|
$typesetInfo['online_date'] = $p_info['pub_date'];//这里可能会有问题
|
|
$typesetInfo['abbreviation'] = $p_info['abbreviation'];
|
|
$typesetInfo['abstractText'] = $p_info['abstract'];
|
|
$typesetInfo['keywords'] = $p_info['keywords'];
|
|
$typesetInfo['userAccount'] = $editor_info['nickname'];
|
|
|
|
//获取文件
|
|
$files = $this->article_file_obj
|
|
->where('article_id', $article_info['article_id'])
|
|
->where('type_name', 'manuscirpt')
|
|
->order('ctime desc')
|
|
->limit(1)
|
|
->select();
|
|
if (count($files) == 0) {
|
|
return jsonError('No Manuscript');
|
|
}
|
|
$typesetInfo['filename'] = "http://api.tmrjournals.com/public/" . $files[0]['file_url'];
|
|
|
|
$rs = $this->production_article_refer_obj->where('p_article_id',$p_info['p_article_id'])->where('state',0)->select();
|
|
$refers = [];
|
|
foreach ($rs as $v) {
|
|
$refers[] = $v['refer_frag'];
|
|
}
|
|
|
|
$typesetInfo['refers'] = json_encode($refers);
|
|
|
|
$url = "http://ts.tmrjournals.com/api/typeset/webGetDocx";
|
|
$res = object_to_array(json_decode(myPost1($url, $typesetInfo)));
|
|
|
|
if (!isset($res['data']['file']) || $res['data']['file'] == '') {
|
|
return jsonError('create error');
|
|
}
|
|
$file_res = $res['data']['file'];
|
|
$tf_insert['p_article_id'] = $p_info['p_article_id'];
|
|
$tf_insert['url'] = $file_res;
|
|
$tf_insert['ctime'] = time();
|
|
$this->production_article_frag_obj->insert($tf_insert);
|
|
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 获取生产实例详情
|
|
*/
|
|
public function getProductionDetail()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find();
|
|
$list = $this->production_article_author_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
|
|
foreach ($list as $k => $v) {
|
|
$list[$k]['organs'] = $this->production_article_author_to_organ_obj
|
|
->field("t_production_article_organ.*")
|
|
->join("t_production_article_organ", 't_production_article_organ.p_article_organ_id = t_production_article_author_to_organ.p_article_organ_id', 'left')
|
|
->where('p_article_author_id', $v['p_article_author_id'])
|
|
->select();
|
|
}
|
|
$re['production'] = $p_info;
|
|
$re['author'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
|
|
/**
|
|
* 添加作者机构
|
|
*/
|
|
public function addAuthorOrgan()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number',
|
|
'organ_name' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find();
|
|
$insert['p_article_id'] = $data['p_article_id'];
|
|
$insert['article_id'] = $p_info['article_id'];
|
|
$insert['organ_name'] = trim($data['organ_name']);
|
|
|
|
$this->production_article_organ_obj->insert($insert);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 删除作者机构
|
|
*/
|
|
public function delAuthorOrgan()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_organ_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
|
|
$this->production_article_organ_obj->where('p_article_organ_id', $data['p_article_organ_id'])->update(['state' => 1]);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 编辑作者机构信息
|
|
*/
|
|
public function editAuthorOrgan()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_organ_id' => 'require|number',
|
|
'organ_name' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$this->production_article_organ_obj->where('p_article_organ_id', $data['p_article_organ_id'])->update(['organ_name' => $data['organ_name']]);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 获取机构列表
|
|
*/
|
|
public function getOrganList()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
|
|
$list = $this->production_article_organ_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
|
|
$re['organs'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
/**
|
|
* 添加作者
|
|
*/
|
|
public function addAuthor()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number',
|
|
'first_name' => 'require',
|
|
'last_name' => 'require',
|
|
'author_country' => 'require',
|
|
'is_first' => 'require',
|
|
'is_report' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find();
|
|
$insert['p_article_id'] = $data['p_article_id'];
|
|
$insert['article_id'] = $p_info['article_id'];
|
|
$insert['author_name'] = $data['first_name'] . ' ' . $data['last_name'];
|
|
$insert['first_name'] = $data['first_name'];
|
|
$insert['last_name'] = $data['last_name'];
|
|
$insert['orcid'] = isset($data['orcid']) ? $data['orcid'] : '';
|
|
$insert['author_country'] = $data['author_country'];
|
|
$insert['is_first'] = $data['is_first'];
|
|
$insert['is_report'] = $data['is_report'];
|
|
$insert['email'] = isset($data['email']) ? trim($data['email']) : '';
|
|
|
|
Db::startTrans();
|
|
$pa_id = $this->production_article_author_obj->insertGetId($insert);
|
|
$or_res = true;
|
|
if (isset($data['organs']) && is_array($data['organs'])) {
|
|
foreach ($data['organs'] as $v) {
|
|
$cache_ins['p_article_id'] = $data['p_article_id'];
|
|
$cache_ins['p_article_author_id'] = $pa_id;
|
|
$cache_ins['p_article_organ_id'] = $v;
|
|
$or_res = $this->production_article_author_to_organ_obj->insert($cache_ins) ? true : false;
|
|
}
|
|
}
|
|
if ($pa_id && $or_res) {
|
|
Db::commit();
|
|
return jsonSuccess([]);
|
|
} else {
|
|
Db::rollback();
|
|
return jsonError("system error");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新引用条目
|
|
*/
|
|
public function freshRefers()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require',
|
|
'refers' => 'require|array'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
|
|
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->find();
|
|
//清空之前的引用条目
|
|
$this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->update(['state' => 1]);
|
|
|
|
foreach ($data['refers'] as $k => $v) {
|
|
$cache_insert['p_article_id'] = $p_info['p_article_id'];
|
|
$cache_insert['refer_content'] = $v;
|
|
$cache_insert['ctime'] = time();
|
|
$this->production_article_refer_obj->insert($cache_insert);
|
|
}
|
|
|
|
$this->referToDoi($data['p_article_id']);
|
|
$this->doiTofrag($data['p_article_id']);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 参考文献识别doi
|
|
*/
|
|
public function referToDoi($p_article_id)
|
|
{
|
|
$p_info = $this->production_article_obj->where('p_article_id', $p_article_id)->find();
|
|
$refers = $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where('state', 0)->select();
|
|
foreach ($refers as $v) { //处理doi
|
|
if (strripos($v['refer_content'], 'doi:') == false && strripos($v['refer_content'], 'doi.org/') == false) {
|
|
continue;
|
|
}
|
|
$doi = '';
|
|
if (strripos($v['refer_content'], 'doi.org/') != false) {
|
|
$cache_arr = explode(' ', trim(substr($v['refer_content'], strripos($v['refer_content'], 'doi.org/') + 8)));
|
|
if (substr($cache_arr[0], -1) == '.') {
|
|
$doi = substr($cache_arr[0], 0, -1);
|
|
} else {
|
|
$doi = $cache_arr[0];
|
|
}
|
|
} else {
|
|
$cache_arr = explode(' ', trim(substr($v['refer_content'], strripos($v['refer_content'], 'doi:') + 4)));
|
|
if (substr($cache_arr[0], -1) == '.') {
|
|
$doi = substr($cache_arr[0], 0, -1);
|
|
} else {
|
|
$doi = $cache_arr[0];
|
|
}
|
|
}
|
|
$this->production_article_refer_obj->where('p_refer_id', $v['p_refer_id'])->update(['refer_doi' => $doi]);
|
|
}
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
public function doiTofrag($p_article_id)
|
|
{
|
|
$p_info = $this->production_article_obj->where('p_article_id', $p_article_id)->find();
|
|
$refers = $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where('state', 0)->select();
|
|
foreach ($refers as $v) {
|
|
if ($v['refer_doi'] == '') {
|
|
$this->production_article_refer_obj->where('p_refer_id', $v['p_refer_id'])->update(['refer_frag' => $v['refer_content']]);
|
|
} else {
|
|
Queue::push('app\api\job\ts@fire1', $v, 'ts');
|
|
}
|
|
}
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 验证参考文献是否全部通过
|
|
*/
|
|
public function checkRefer()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$list = $this->production_article_refer_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
|
|
if (!$list) {
|
|
return jsonError('references error');
|
|
}
|
|
$frag = 1;
|
|
foreach ($list as $v) {
|
|
if ($v['cs'] == 0) {
|
|
$frag = 0;
|
|
break;
|
|
}
|
|
}
|
|
if ($frag == 0) {
|
|
return jsonError('references check error');
|
|
} else {
|
|
return jsonSuccess([]);
|
|
}
|
|
}
|
|
|
|
|
|
public function getFragBF()
|
|
{
|
|
$data = $this->request->post();
|
|
// 验证规则
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require|number'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$list = $this->production_article_refer_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
|
|
$z = count($list);
|
|
$m = 0;
|
|
foreach ($list as $v) {
|
|
if ($v['refer_frag'] != '') {
|
|
$m++;
|
|
}
|
|
}
|
|
|
|
if ($z == 0) {
|
|
return jsonError('system error!');
|
|
}
|
|
|
|
$f = intval($m * 100 / $z);
|
|
|
|
$re['bf'] = $f;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
/**
|
|
* 删除作者
|
|
*/
|
|
public function delAuthor()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_author_id' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$this->production_article_author_obj->where('p_article_author_id', $data['p_article_author_id'])->update(['state' => 1]);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 获取作者列表
|
|
*/
|
|
public function getAuthorlist()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
$list = $this->production_article_author_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
|
|
foreach ($list as $k => $v) {
|
|
$list[$k]['organs'] = $this->production_article_author_to_organ_obj
|
|
->field("t_production_article_organ.*")
|
|
->join("t_production_article_organ", 't_production_article_organ.p_article_organ_id = t_production_article_author_to_organ.p_article_organ_id', 'left')
|
|
->where('p_article_author_id', $v['p_article_author_id'])
|
|
->select();
|
|
}
|
|
$re['authors'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
/**
|
|
* 更改附加文件
|
|
*/
|
|
public function editArticleFile()
|
|
{
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'p_article_id' => 'require',
|
|
'filetype' => 'require'
|
|
]);
|
|
if (!$rule->check($data)) {
|
|
return jsonError($rule->getError());
|
|
}
|
|
if ($data['filetype'] == 'PDF') {
|
|
$updata['file_pdf'] = $data['fileURL'];
|
|
} elseif ($data['filetype'] == 'HTML') {
|
|
$updata['file_html'] = $data['fileURL'];
|
|
} elseif ($data['filetype'] == 'SUB') {
|
|
$updata['file_sub'] = $data['fileURL'];
|
|
} elseif ($data['filetype'] == 'SUB2') {
|
|
$updata['file_sub2'] = $data['fileURL'];
|
|
} elseif ($data['filetype'] == 'endNote') {
|
|
$updata['endnote'] = $data['fileURL'];
|
|
} elseif ($data['filetype'] == 'bibTex') {
|
|
$updata['bibtex'] = $data['fileURL'];
|
|
} elseif ($data['filetype'] == 'CDF') {
|
|
$updata['file_cdf'] = $data['fileURL'];
|
|
}
|
|
$this->production_article_obj->where('p_article_id', $data['p_article_id'])->update($updata);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 上传文章图片文件
|
|
*/
|
|
public function up_articlepic_file()
|
|
{
|
|
$file = request()->file('articleicon');
|
|
if ($file) {
|
|
$info = $file->move(ROOT_PATH . 'public' . DS . 'articleicon');
|
|
if ($info) {
|
|
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
|
} else {
|
|
return json(['code' => 1, 'msg' => $file->getError()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 文章文件上传
|
|
*
|
|
* @param name:name type:string require:1 desc:文件域名称(articleSUB/articleSUB2/bibTex/endNote/articleCDF)
|
|
* @param name:type type:string require:1 desc:pathinfo(articleSUB/articleSUB2/bibTex/endNote/articleCDF)
|
|
*
|
|
* @return upurl:图片地址
|
|
*/
|
|
public function up_article_file($type)
|
|
{
|
|
$file = request()->file($type);
|
|
if ($file) {
|
|
$info = $file->move(ROOT_PATH . 'public' . DS . $type);
|
|
if ($info) {
|
|
return json(['code' => 0, 'msg' => 'success', 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
|
} else {
|
|
return json(['code' => 1, 'msg' => $file->getError()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function authorFormate($p_article_id)
|
|
{
|
|
// $authors = $this->article_author_obj->where('article_id', $article_id)->where('state', 0)->select();
|
|
|
|
$authors = $this->production_article_author_obj->where('p_article_id',$p_article_id)->where('state',0)->select();
|
|
//组装地址数组
|
|
$address = [];
|
|
foreach ($authors as $v) {
|
|
$cac = $this->production_article_author_to_organ_obj
|
|
->field('t_production_article_organ.*')
|
|
->join('t_production_article_organ','t_production_article_organ.p_article_organ_id = t_production_article_author_to_organ.p_article_organ_id','left')
|
|
->where('t_production_article_author_to_organ.p_article_author_id',$v['p_article_author_id'])
|
|
->where('t_production_article_author_to_organ.state',0)
|
|
->select();
|
|
foreach($cac as $val){
|
|
if(!in_array($val['organ_name'],$address)){
|
|
$address[] = $val['organ_name'];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//构建数组字符串
|
|
$author = '';
|
|
foreach ($authors as $v) {
|
|
$cache_str = $v['first_name'] . ' ' . $v['last_name'] . '<q>';
|
|
$cac = $this->production_article_author_to_organ_obj
|
|
->field('t_production_article_organ.*')
|
|
->join('t_production_article_organ','t_production_article_organ.p_article_organ_id = t_production_article_author_to_organ.p_article_organ_id','left')
|
|
->where('t_production_article_author_to_organ.p_article_author_id',$v['p_article_author_id'])
|
|
->where('t_production_article_author_to_organ.state',0)
|
|
->select();
|
|
foreach ($cac as $val) {
|
|
$cache_str .= (intval(search_array_val($address, $val['organ_name'])) + 1) . " ";
|
|
}
|
|
if ($v['is_first'] == 1) {
|
|
$cache_str .= '*';
|
|
}
|
|
if ($v['is_report'] == 1) {
|
|
$cache_str .= '#';
|
|
}
|
|
$cache_str = trim($cache_str);
|
|
$cache_str .= '</q>';
|
|
$author .= $cache_str;
|
|
}
|
|
//组装address
|
|
$address_str = '';
|
|
foreach ($address as $k => $v) {
|
|
$address_str .= ($k + 1) . ' ' . $v . ' ';
|
|
}
|
|
$frag['author'] = $author;
|
|
$frag['address'] = $address_str;
|
|
return $frag;
|
|
}
|
|
}
|