978 lines
41 KiB
PHP
978 lines
41 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Controller;
|
||
use think\Db;
|
||
use hashids\hashids;
|
||
|
||
class Base extends Controller
|
||
{
|
||
|
||
protected $ts_base_url = "http://ts.tmrjournals.com/";
|
||
|
||
protected $user_obj = '';
|
||
protected $captcha_obj = '';
|
||
protected $article_obj = '';
|
||
protected $user_act_obj = '';
|
||
protected $admin_obj = '';
|
||
protected $user_reviewer_obj = '';
|
||
protected $journal_obj = '';
|
||
protected $reviewer_major_obj = '';
|
||
protected $reviewer_to_journal_obj = '';
|
||
protected $user_reviewer_info_obj = '';
|
||
protected $user_msg_obj = '';
|
||
protected $chief_to_journal_obj = '';
|
||
protected $board_to_journal_obj = '';
|
||
protected $reviewer_from_author_obj = '';
|
||
protected $article_author_obj = '';
|
||
protected $user_black_obj = '';
|
||
protected $user_to_special_obj = '';
|
||
protected $user_register_check_obj = '';
|
||
protected $user_cert_obj = '';
|
||
protected $apply_board_obj = '';
|
||
protected $apply_yboard_obj = '';
|
||
protected $user_score_log_obj = '';
|
||
protected $user_index_log_obj = '';
|
||
protected $article_reviewer_obj = '';
|
||
protected $user_ash_obj = '';
|
||
protected $major_obj = '';
|
||
protected $user_to_yboard_obj = '';
|
||
protected $user_author_obj = '';
|
||
protected $country_obj = '';
|
||
protected $user_log_obj = '';
|
||
protected $article_reviewer_question_obj = '';
|
||
protected $article_msg_obj = '';
|
||
protected $article_file_obj = '';
|
||
protected $article_transfer_obj = '';
|
||
protected $login_auto_obj = '';
|
||
protected $major_to_journal_obj = '';
|
||
protected $article_dialog_obj = '';
|
||
protected $article_proposal_obj = '';
|
||
protected $article_response_to_reviewer_obj = '';
|
||
protected $user_reviewer_recommend_obj = '';
|
||
protected $email_log_obj = '';
|
||
protected $email_template_obj = '';
|
||
protected $production_article_obj = '';
|
||
protected $company_top_obj = '';
|
||
protected $user_cv_obj = '';
|
||
protected $ts_obj = '';
|
||
protected $ts_refer_obj = '';
|
||
protected $ts_frag_obj = '';
|
||
protected $online_obj = '';
|
||
protected $article_reviewer_file_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 = '';
|
||
protected $production_article_main_obj = '';
|
||
protected $production_article_main_img_obj = '';
|
||
protected $apply_reviewer_obj = '';
|
||
protected $promotion_obj = '';
|
||
protected $promotion_email_obj = '';
|
||
protected $article_reviewer_repeat_obj = '';
|
||
protected $board_group_obj = "";
|
||
protected $committee_to_journal_obj = '';
|
||
protected $editor_to_journal_obj = '';
|
||
protected $email_account_obj="";
|
||
protected $article_image_obj="";
|
||
protected $article_table_obj="";
|
||
protected $article_main_obj="";
|
||
protected $article_main_image_obj = "";
|
||
protected $article_main_table_obj = '';
|
||
protected $order_obj = "";
|
||
|
||
|
||
public function __construct(\think\Request $request = null)
|
||
{
|
||
parent::__construct($request);
|
||
$this->user_obj = Db::name('user');
|
||
$this->captcha_obj = Db::name('captcha');
|
||
$this->article_obj = Db::name('article');
|
||
$this->user_act_obj = Db::name('user_act');
|
||
$this->admin_obj = Db::name('admin');
|
||
$this->user_reviewer_obj = Db::name('user_reviewer_apply');
|
||
$this->journal_obj = Db::name('journal');
|
||
$this->reviewer_major_obj = Db::name('reviewer_major');
|
||
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
|
||
$this->user_reviewer_info_obj = Db::name('user_reviewer_info');
|
||
$this->user_msg_obj = Db::name('user_msg');
|
||
$this->chief_to_journal_obj = Db::name('chief_to_journal');
|
||
$this->board_to_journal_obj = Db::name('board_to_journal');
|
||
$this->reviewer_from_author_obj = Db::name('reviewer_from_author');
|
||
$this->article_author_obj = Db::name('article_author');
|
||
$this->user_black_obj = Db::name('user_black');
|
||
$this->user_to_special_obj = Db::name('user_to_special');
|
||
$this->user_register_check_obj = Db::name('user_register_check');
|
||
$this->user_cert_obj = Db::name('user_cert');
|
||
$this->apply_board_obj = Db::name('apply_board');
|
||
$this->apply_yboard_obj = Db::name('apply_yboard');
|
||
$this->user_author_obj = Db::name('user_author');
|
||
$this->user_score_log_obj = Db::name('user_score_log');
|
||
$this->user_index_log_obj = Db::name('user_index_log');
|
||
$this->article_reviewer_obj = Db::name('article_reviewer');
|
||
$this->user_ash_obj = Db::name('user_ash');
|
||
$this->major_obj = Db::name('major');
|
||
$this->user_to_yboard_obj = Db::name('user_to_yboard');
|
||
$this->country_obj = Db::name('country');
|
||
$this->user_log_obj = Db::name('user_log');
|
||
$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_transfer_obj = Db::name('article_transfer');
|
||
$this->login_auto_obj = Db::name('login_auto');
|
||
$this->major_to_journal_obj = Db::name('major_to_journal');
|
||
$this->article_dialog_obj = Db::name('article_dialog');
|
||
$this->article_proposal_obj = Db::name('article_proposal');
|
||
$this->article_response_to_reviewer_obj = Db::name('article_response_to_reviewer');
|
||
$this->user_reviewer_recommend_obj = Db::name('user_reviewer_recommend');
|
||
$this->email_log_obj = Db::name('email_log');
|
||
$this->email_template_obj = Db::name('email_template');
|
||
$this->production_article_obj = Db::name('production_article');
|
||
$this->company_top_obj = Db::name('company_top');
|
||
$this->user_cv_obj = Db::name('user_cv');
|
||
$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->article_reviewer_file_obj = Db::name('article_reviewer_file');
|
||
$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');
|
||
$this->production_article_main_obj = Db::name('production_article_main');
|
||
$this->production_article_main_img_obj = Db::name("production_article_main_img");
|
||
$this->apply_reviewer_obj = Db::name("apply_reviewer");
|
||
$this->promotion_obj = Db::name("promotion");
|
||
$this->promotion_email_obj = Db::name("promotion_email");
|
||
$this->article_reviewer_repeat_obj = Db::name("article_reviewer_repeat");
|
||
$this->board_group_obj = Db::name("board_group");
|
||
$this->committee_to_journal_obj = Db::name("committee_to_journal");
|
||
$this->editor_to_journal_obj = Db::name("editor_to_journal");
|
||
$this->email_account_obj = Db::name("email_account");
|
||
$this->article_image_obj = Db::name("article_image");
|
||
$this->article_table_obj = Db::name("article_table");
|
||
$this->article_main_obj = Db::name("article_main");
|
||
$this->article_main_image_obj = Db::name("article_main_image");
|
||
$this->article_main_table_obj = Db::name("article_main_table");
|
||
$this->order_obj = Db::name("order");
|
||
}
|
||
|
||
|
||
public function pdfAddProof($article_id)
|
||
{
|
||
$p_info = $this->production_article_obj->where('article_id', $article_id)->where('state', 0)->find();
|
||
vendor('fpdf.fpdf');
|
||
vendor('fpdi/fpdi');
|
||
$pdf = new \FPDI();
|
||
$pageCount = $pdf->setSourceFile(ROOT_PATH . 'public' . DS . $p_info['file_pdf']);
|
||
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
|
||
$templateId = $pdf->importPage($pageNo);
|
||
$size = $pdf->getTemplateSize($templateId);
|
||
if ($size['w'] > $size['h']) $pdf->AddPage('L', array($size['w'], $size['h']));
|
||
else $pdf->AddPage('P', array($size['w'], $size['h']));
|
||
$pdf->image(ROOT_PATH . 'public' . DS . 'pdf' . DS . 'bg2.png', 55, 25, 80);
|
||
$pdf->image(ROOT_PATH . 'public' . DS . 'pdf' . DS . 'bg2.png', 55, 155, 80);
|
||
$pdf->useTemplate($templateId);
|
||
}
|
||
$pdf->Output(ROOT_PATH . 'public' . DS . 'proofPDF' . DS . $article_id . '.pdf');
|
||
if ($p_info['file_sub'] != '' && substr($p_info['file_sub'], strripos($p_info['file_sub'], '.') + 1) == 'pdf') {
|
||
$pdf1 = new \FPDI();
|
||
$pageCount1 = $pdf1->setSourceFile(ROOT_PATH . 'public' . DS . "articleSUB" . DS . $p_info['file_sub']);
|
||
for ($pageNo = 1; $pageNo <= $pageCount1; $pageNo++) {
|
||
$templateId1 = $pdf1->importPage($pageNo);
|
||
$size = $pdf1->getTemplateSize($templateId1);
|
||
if ($size['w'] > $size['h']) $pdf1->AddPage('L', array($size['w'], $size['h']));
|
||
else $pdf1->AddPage('P', array($size['w'], $size['h']));
|
||
$pdf1->image(ROOT_PATH . 'public' . DS . 'pdf' . DS . 'bg2.png', 55, 25, 80);
|
||
$pdf1->image(ROOT_PATH . 'public' . DS . 'pdf' . DS . 'bg2.png', 55, 155, 80);
|
||
$pdf1->useTemplate($templateId1);
|
||
}
|
||
$pdf1->Output(ROOT_PATH . 'public' . DS . 'proofPDF' . DS . $article_id . 'SUB.pdf');
|
||
}
|
||
}
|
||
|
||
public function createYboardCert($user_info, $journal_info, $start_time, $year)
|
||
{
|
||
if (!is_dir(ROOT_PATH . 'public' . DS . 'cert' . DS . $journal_info['journal_id'])) {
|
||
mkdir(ROOT_PATH . 'public' . DS . 'cert' . DS . $journal_info['journal_id']);
|
||
}
|
||
$sj_num = rand(1000, 9999);
|
||
$template = ROOT_PATH . 'public' . DS . 'cert' . DS . 'yboard_template.png';
|
||
$ziti = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'siyuan.ttf';
|
||
$ziti1 = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'Georgia0.ttf';
|
||
$image = \think\Image::open($template);
|
||
$ys = date("F Y", $start_time) . " to " . date("F Y", strtotime("+ " . $year . " year", $start_time));
|
||
$image->text($user_info['realname'], $ziti, 45, '#000000', [1060, 750])
|
||
->text($ys, $ziti1, 32, '#C49A6C', [1370, 1015])
|
||
->text(date("Y.m.d", $start_time), $ziti, 25, '#000000', [500, 1280])
|
||
->text($journal_info['title'], $ziti1, 36, '#C49A6C', [860, 930])
|
||
->save(ROOT_PATH . 'public' . DS . 'cert' . DS . $journal_info['journal_id'] . DS . $user_info['user_id'] . '_yboard_' . date('Y', $start_time) . $sj_num . '.png');
|
||
return $journal_info['journal_id'] . DS . $user_info['user_id'] . '_yboard_' . date('Y', $start_time) . $sj_num . '.png';
|
||
}
|
||
|
||
public function majorids($major_id)
|
||
{
|
||
$frag[] = $major_id;
|
||
$list = $this->major_obj->where('pid', $major_id)->select();
|
||
foreach ($list as $v) {
|
||
$cache = self::majorids($v['major_id']);
|
||
$frag = array_merge($frag, $cache);
|
||
}
|
||
return $frag;
|
||
}
|
||
|
||
public function delOneRefer($p_refer_id)
|
||
{
|
||
|
||
$refer_info = $this->production_article_refer_obj->where('p_refer_id', $p_refer_id)->find();
|
||
if (!$refer_info) {
|
||
return "";
|
||
}
|
||
$this->production_article_refer_obj->where('p_article_id', $refer_info['p_article_id'])->where('index', ">", $refer_info['index'])->where('state', 0)->setDec('index');
|
||
$this->production_article_refer_obj->where('p_refer_id', $p_refer_id)->update(['state' => 1]);
|
||
}
|
||
|
||
|
||
public function getMajorShu($major)
|
||
{
|
||
if ($major == 0) {
|
||
return '';
|
||
}
|
||
$res = $this->major_obj->where('major_id', $major)->find();
|
||
if ($res['pid'] == 1) {
|
||
return $res['major_id'];
|
||
}
|
||
|
||
$p = self::getMajorShu($res['pid']);
|
||
return $p . ',' . $res['major_id'];
|
||
}
|
||
|
||
public function getMajorStr($major_id)
|
||
{
|
||
$frag = '';
|
||
$major_info = $this->major_obj->where('major_id', $major_id)->find();
|
||
if ($major_info == null) {
|
||
return '';
|
||
}
|
||
if ($major_info['major_level'] == 1) {
|
||
return 'Medicine';
|
||
} else {
|
||
$frag = $this->getMajorStr($major_info['pid']) . ' > ' . $major_info['major_title'];
|
||
}
|
||
return $frag;
|
||
}
|
||
|
||
public function getMajorOne($major_id)
|
||
{
|
||
$major_info = $this->major_obj->where('major_id', $major_id)->find();
|
||
return $major_info['major_title'];
|
||
}
|
||
|
||
|
||
public function save_article_file($article_id, $user_id, $username, $url, $type_name)
|
||
{
|
||
//首先确定数据库里面是否存在此数据
|
||
$res = $this->article_file_obj->where(['file_url' => $url])->find();
|
||
if ($res) { //编辑的时候不能重复存储
|
||
return true;
|
||
} else if ($type_name == 'picturesAndTables' && trim($url) == '') {
|
||
return true;
|
||
} else if ($type_name == 'coverLetter' && trim($url) == '') {
|
||
return true;
|
||
} else if ($type_name == 'totalpage' && trim($url) == '') {
|
||
return true;
|
||
} else if ($type_name == "supplementary" && trim($url) == '') {
|
||
return true;
|
||
}
|
||
$insert_data['article_id'] = $article_id;
|
||
$insert_data['user_id'] = $user_id;
|
||
$insert_data['username'] = $username;
|
||
$insert_data['file_url'] = $url;
|
||
$insert_data['type_name'] = $type_name;
|
||
$insert_data['ctime'] = time();
|
||
return $this->article_file_obj->insertGetId($insert_data);
|
||
}
|
||
|
||
|
||
public function getArticleAuthors($article_id)
|
||
{
|
||
$res = $this->article_author_obj->where('article_id', $article_id)->where('state', 0)->select();
|
||
$frag = '';
|
||
foreach ($res as $v) {
|
||
$frag .= $v['firstname'] . $v['lastname'] . ',';
|
||
}
|
||
return substr($frag, 0, -1);
|
||
}
|
||
|
||
public function MyaddEx()
|
||
{
|
||
$data = $this->request->post();
|
||
$this->addProductionEx($data['article_id']);
|
||
}
|
||
|
||
|
||
public function addProductionEx($article_id)
|
||
{
|
||
$check = $this->production_article_obj->where('article_id', $article_id)->where('state', 0)->find();
|
||
if ($check) {
|
||
return 'Instance already exists';
|
||
}
|
||
|
||
$article_info = $this->article_obj->where('article_id', $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 = $this->ts_base_url."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;
|
||
}
|
||
|
||
|
||
if (!isset($frag['main'])) {
|
||
return jsonError("manuscript file error!");
|
||
}
|
||
|
||
$insert['main'] = isset($frag['main']) ? json_encode($frag['main']) : '';
|
||
$insert['article_id'] = $article_id;
|
||
$insert['journal_id'] = $article_info['journal_id'];
|
||
$insert['ctime'] = time();
|
||
$p_article_id = $this->production_article_obj->insertGetId($insert);
|
||
|
||
|
||
//将主体内容写入数据库
|
||
foreach ($frag['main'] as $v) {
|
||
$ca['p_article_id'] = $p_article_id;
|
||
$ca['content'] = $v;
|
||
$ca['content_g'] = '';
|
||
$ca['ctime'] = time();
|
||
$this->production_article_main_obj->insert($ca);
|
||
}
|
||
return jsonSuccess([]);
|
||
}
|
||
|
||
|
||
|
||
public function addArticleMainEx($article_id){
|
||
$article_info = $this->article_obj->where('article_id', $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');
|
||
}
|
||
$dir = ROOT_PATH."public/articleImage/".$article_id;
|
||
if (!is_dir($dir)) {
|
||
mkdir($dir, 0777, true);
|
||
}
|
||
$url = $this->ts_base_url."api/typeset/readDocx";
|
||
$program['fileRoute'] = "https://submission.tmrjournals.com/public/" . $files[0]['file_url'];
|
||
$program['article_id'] = $article_id;
|
||
$res = object_to_array(json_decode(myPost($url, $program)));
|
||
$file_runs = $res['data'];
|
||
//需要处理很多事情
|
||
if(!isset($file_runs['mains'])){
|
||
return "system error";
|
||
}
|
||
$refer_start = false;
|
||
foreach ($file_runs['mains'] as $k=>$v){
|
||
if($this->isImageTag($v)){//img
|
||
preg_match("/\/public\/articleImage\/(.*?)'/", $v, $matches);
|
||
if (!isset($matches[1])) {continue;}
|
||
|
||
$insert_image['article_id'] = $article_id;
|
||
$insert_image['url'] = $matches[1];
|
||
$insert_image['ctime'] = time();
|
||
$c_id = $this->article_main_image_obj->insertGetId($insert_image);
|
||
|
||
$insert1['article_id'] = $article_id;
|
||
$insert1['type'] = 1;
|
||
$insert1['ami_id'] = $c_id;
|
||
$insert1['content'] = substr($v,0,-2)."imageId='".$c_id."' />";
|
||
$insert1['sort'] = $k+1;
|
||
$insert1['ctime'] = time();
|
||
$this->article_main_obj->insert($insert1);
|
||
|
||
}else{//文本
|
||
if($refer_start&&$v!=""){
|
||
if (strlen($v) > 500) {
|
||
$refer_start = false;
|
||
$cc_t = $this->formatMain($v);
|
||
$insert['article_id'] = $article_id;
|
||
$insert['type'] = 0;
|
||
$insert['content'] = $cc_t;
|
||
$insert['sort'] = $k+1;
|
||
$insert['ctime'] = time();
|
||
$this->article_main_obj->insert($insert);
|
||
continue;
|
||
}
|
||
continue ;
|
||
}
|
||
if (strtolower($v) == 'reference:' || strtolower($v)=="<b>references</b>"||strtolower($v) == 'references:' || strtolower($v) == 'references' || strtolower($v) == 'reference') {
|
||
$refer_start = true;
|
||
continue;
|
||
}
|
||
|
||
$c_t = $this->formatMain($v);
|
||
$insert['article_id'] = $article_id;
|
||
$insert['type'] = 0;
|
||
$insert['content'] = $c_t;
|
||
$insert['sort'] = $k+1;
|
||
$insert['ctime'] = time();
|
||
$this->article_main_obj->insert($insert);
|
||
}
|
||
}
|
||
|
||
//处理表格
|
||
$tables = $this->article_table_obj->where("article_id",$article_id)->where("state",0)->select();
|
||
foreach ($tables as $table) {
|
||
$ins['article_id'] = $article_id;
|
||
$ins['type'] = 0;
|
||
$ins['table_data'] = $table['table'];
|
||
$ins['ctime'] = time();
|
||
$this->article_main_table_obj->insert($ins);
|
||
}
|
||
|
||
|
||
$pics = $this->article_file_obj->where("article_id",$article_id)->where("type_name","picturesAndTables")->where("state",0)->order("file_id desc")->limit(1)->select();
|
||
if(!isset($pics[0])){
|
||
return ;
|
||
}
|
||
$extension = pathinfo($pics[0]['file_url'], PATHINFO_EXTENSION);
|
||
if($extension=="zip"){
|
||
$file = ROOT_PATH."public/".$pics[0]['file_url'];
|
||
$zip = new \ZipArchive();
|
||
|
||
// 打开 ZIP 文件
|
||
if ($zip->open($file) === true) {
|
||
$fileCount = $zip->numFiles;
|
||
$num_rand = uniqid('', true); // 使用 uniqid 来生成更唯一的文件名
|
||
|
||
for ($i = 0; $i < $fileCount; $i++) {
|
||
$stat = $zip->statIndex($i);
|
||
$fileName = basename($stat['name']); // 获取文件名并去掉路径
|
||
$fileContent = $zip->getFromIndex($i);
|
||
$base_url = ROOT_PATH . "public/articleImage/" . $article_id . "/";
|
||
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
|
||
|
||
// 创建文件名并确保唯一性
|
||
$newFileName = "zipimg" . $num_rand . $i . '.' . $extension;
|
||
|
||
if (in_array(strtolower($extension), ['jpg', 'jpeg', 'png'])) {
|
||
// 处理图片文件
|
||
file_put_contents($base_url . $newFileName, $fileContent);
|
||
$insert['article_id'] = $article_id;
|
||
$insert['url'] = $article_id . "/" . $newFileName;
|
||
$insert['ctime'] = time();
|
||
$this->article_main_image_obj->insert($insert);
|
||
} elseif (in_array(strtolower($extension), ['tiff', 'tif'])) {
|
||
// 处理 TIFF 和 EMF 文件并转换为 JPG
|
||
file_put_contents($base_url . $newFileName, $fileContent);
|
||
$insert['article_id'] = $article_id;
|
||
$insert['url'] = $this->crossTifToPng($article_id . "/" . $newFileName);
|
||
$insert['ctime'] = time();
|
||
$this->article_main_image_obj->insert($insert);
|
||
} elseif ($extension == "docx") {
|
||
$word_dir = ROOT_PATH . "public/articleCache/" . $article_id;
|
||
if (!is_dir($word_dir)) {
|
||
mkdir($word_dir, 0777, true);
|
||
}
|
||
$word_file = uniqid('', true) . $fileName;
|
||
file_put_contents($word_dir . "/" . $word_file, $fileContent);
|
||
$url = $this->ts_base_url . "api/typeset/markImages";
|
||
$program['file'] = "https://submission.tmrjournals.com/public/articleCache/" . $article_id . "/" . $word_file;
|
||
$program['article_id'] = $article_id;
|
||
$res = object_to_array(json_decode(myPost($url, $program)));
|
||
if (!isset($res['data']['list'])) {
|
||
return;
|
||
}
|
||
$file_runs = $res['data']['list'];
|
||
foreach ($file_runs as $val) {
|
||
$ex = pathinfo($val,PATHINFO_EXTENSION);
|
||
$insert['article_id'] = $article_id;
|
||
$insert['url'] = ($ex=="tif"||$ex=="tiff")?crossTifToPng($val):$val;
|
||
$insert['ctime'] = time();
|
||
$this->article_main_image_obj->insert($insert);
|
||
}
|
||
}
|
||
}
|
||
// 关闭 ZIP 文件
|
||
$zip->close();
|
||
} else {
|
||
return json(['error' => 'Unable to open ZIP file.']);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public function crossTifToPng($tif_url){
|
||
$url = $this->ts_base_url . "api/typeset/crossImage";
|
||
$program['url'] = $tif_url;
|
||
$res = object_to_array(json_decode(myPost($url, $program)));
|
||
if (!isset($res['data']['file'])) {
|
||
return;
|
||
}
|
||
return $res['data']['file'];
|
||
}
|
||
|
||
public function isImageTag($str) {
|
||
// 正则表达式匹配 <img> 标签,忽略大小写
|
||
$pattern = '/^\s*<img\s+[^>]*\s*src=["\'][^"\']+["\'][^>]*>\s*$/i';
|
||
|
||
// 使用 preg_match 判断是否符合 img 标签的格式
|
||
if (preg_match($pattern, $str)) {
|
||
return true; // 是 img 标签
|
||
}
|
||
return false; // 不是 img 标签
|
||
}
|
||
|
||
public function removeExtraSpaces($str) {
|
||
// 使用正则表达式匹配两个及以上的连续空格,并替换为一个空格
|
||
return preg_replace('/\s{2,}/', ' ', $str);
|
||
}
|
||
|
||
|
||
public function formatMain($string){
|
||
return $this->blueIntegerChange($this->replaceChinesePunctuation($this->removeExtraSpaces($string)));
|
||
}
|
||
|
||
|
||
public function replaceChinesePunctuation($str) {
|
||
// 定义中文标点和对应的英文标点替换
|
||
$replacements = [
|
||
',' => ',', // 中文逗号 -> 英文逗号
|
||
'。' => '.', // 中文句号 -> 英文句号
|
||
'!' => '!', // 中文感叹号 -> 英文感叹号
|
||
'?' => '?', // 中文问号 -> 英文问号
|
||
':' => ':', // 中文冒号 -> 英文冒号
|
||
';' => ';', // 中文分号 -> 英文分号
|
||
'(' => '(', // 中文左括号 -> 英文左括号
|
||
')' => ')', // 中文右括号 -> 英文右括号
|
||
'【' => '[', // 中文左方括号 -> 英文左方括号
|
||
'】' => ']', // 中文右方括号 -> 英文右方括号
|
||
'《' => '<', // 中文左书名号 -> 英文左书名号
|
||
'》' => '>', // 中文右书名号 -> 英文右书名号
|
||
'、' => ',', // 中文顿号 -> 英文逗号
|
||
'——' => '--', // 中文破折号 -> 英文破折号
|
||
'·' => '.', // 中文间隔符 -> 英文点
|
||
];
|
||
|
||
// 替换所有中文标点
|
||
return str_replace(array_keys($replacements), array_values($replacements), $str);
|
||
}
|
||
|
||
|
||
public function blueIntegerChange($string){
|
||
return preg_replace_callback('/\[(\d+)\]/', function($matches) {
|
||
return '<blue>[' . $matches[1] . ']</blue>';
|
||
}, $string);
|
||
}
|
||
|
||
public function getBoardsForJournal($journal_id, $aar = false)
|
||
{
|
||
$ca_board = [];
|
||
$boards = $this->board_to_journal_obj
|
||
->field("t_board_to_journal.*,t_board_group.group_name,t_user.account,t_user.email,t_user.realname,t_user.icon,t_user.google_index,t_user.google_time,t_user.wos_index,t_user.wos_time,t_user_reviewer_info.*")
|
||
->join("t_board_group", "t_board_group.board_group_id = t_board_to_journal.board_group_id", "left")
|
||
->join("t_user", "t_user.user_id = t_board_to_journal.user_id", "left")
|
||
->join("t_user_reviewer_info", "t_user_reviewer_info.reviewer_id=t_board_to_journal.user_id", "left")
|
||
->where('t_board_to_journal.journal_id', $journal_id)
|
||
->where('t_board_to_journal.state', 0)
|
||
->select();
|
||
foreach ($boards as $val) {
|
||
if ($aar) {
|
||
$article1 = $this->article_obj->where('user_id', $val['user_id'])->where('journal_id', $val['journal_id'])->where('state', 5)->where('ctime', ">", strtotime("-1 year"))->select();
|
||
$article11 = $this->article_obj->where('user_id', $val['user_id'])->where('journal_id', $val['journal_id'])->where('ctime', ">", strtotime("-1 year"))->select();
|
||
$ids = $this->article_author_obj->where('email', $val['email'])->column("article_id");
|
||
$article2 = $this->article_obj->where('state', 5)->where('journal_id', $val['journal_id'])->where('article_id', "in", $ids)->select();
|
||
$article22 = $this->article_obj->where('journal_id', $val['journal_id'])->where('article_id', "in", $ids)->select();
|
||
$articles = my_array_merge($article1, $article2);
|
||
$articles_all = my_array_merge($article11, $article22);
|
||
$reviewes = $this->article_reviewer_obj->join("t_article", "t_article.article_id = t_article_reviewer.article_id", "left")->where('t_article_reviewer.reviewer_id', $val['user_id'])->where('t_article.journal_id', $journal_id)->where('t_article_reviewer.ctime', ">", strtotime("-1 year"))->where('t_article_reviewer.state', "in", [1, 2, 3])->select();
|
||
$val['articles'] = $articles;
|
||
$val['articles_all'] = $articles_all;
|
||
$val['reviewes'] = $reviewes;
|
||
}
|
||
|
||
if ($val['type'] == 0) {//主编
|
||
$ca_board['main'][] = $val;
|
||
} elseif ($val['type'] == 1) {//副主编
|
||
$ca_board['remain'][] = $val;
|
||
} else {//编委会成员
|
||
if ($val['board_group_id'] == 0) {
|
||
$ca_board['member']['nogroup'][] = $val;
|
||
} else {
|
||
$ca_board['member'][$val['group_name']][] = $val;
|
||
}
|
||
}
|
||
}
|
||
return $ca_board;
|
||
}
|
||
|
||
|
||
public function getCvs($user_id)
|
||
{
|
||
$list = $this->user_cv_obj->where('user_id', $user_id)->where('state', 0)->select();
|
||
return $list;
|
||
}
|
||
|
||
/**获取标准化用户库的人
|
||
* @return void
|
||
*/
|
||
public function getLibraryList($lib, $type, $body, $china_type, $pageIndex, $pageSize)
|
||
{
|
||
$frag = [];
|
||
if ($lib == "user") {//正式库
|
||
$where["t_user.state"] = 0;
|
||
$where["t_user.no_email"] = 0;
|
||
if ($type == "major") {
|
||
$where['t_user_reviewer_info.major'] = ["in", $this->majorids($body)];
|
||
} else {
|
||
$where['t_user_reviewer_info.field'] = ["like", "%" . $body . "%"];
|
||
}
|
||
if ($china_type == 1) {
|
||
$where['t_user_reviewer_info.country'] = "China";
|
||
} elseif ($china_type == 2) {
|
||
$where['t_user_reviewer_info.country'] = ["<>", "China"];
|
||
}
|
||
$list = $this->user_obj
|
||
->join("t_user_reviewer_info", "t_user_reviewer_info.reviewer_id = t_user.user_id", 'left')
|
||
->where($where)
|
||
->page($pageIndex, $pageSize)
|
||
->select();
|
||
//规整化数据整理
|
||
foreach ($list as $v) {
|
||
$ca['email'] = $v['email'];
|
||
$ca['name'] = $v['realname'] == "" ? $v['account'] : $v['realname'];
|
||
$ca['type'] = "user";
|
||
$ca['id'] = $v['user_id'];
|
||
$ca['major'] = $v['major'];
|
||
$frag[] = $ca;
|
||
}
|
||
} elseif ($lib == 'author') {//作者库
|
||
$exist = "select * from t_user_author where user_id = t_user.user_id";
|
||
$where["t_user.state"] = 0;
|
||
$where["t_user.no_email"] = 0;
|
||
if ($type == "major") {
|
||
$where['t_user_reviewer_info.major'] = ["in", $this->majorids($body)];
|
||
} else {
|
||
$where['t_user_reviewer_info.field'] = ["like", "%" . $body . "%"];
|
||
}
|
||
if ($china_type == 1) {
|
||
$where['t_user_reviewer_info.country'] = "China";
|
||
} elseif ($china_type == 2) {
|
||
$where['t_user_reviewer_info.country'] = ["<>", "China"];
|
||
}
|
||
$list = $this->user_obj
|
||
->join("t_user_reviewer_info", "t_user_reviewer_info.reviewer_id = t_user.user_id", 'left')
|
||
->where($where)
|
||
->whereExists($exist)
|
||
->page($pageIndex, $pageSize)
|
||
->select();
|
||
//规整化数据整理
|
||
foreach ($list as $v) {
|
||
$ca['email'] = $v['email'];
|
||
$ca['name'] = $v['realname'] == "" ? $v['account'] : $v['realname'];
|
||
$ca['type'] = "user";
|
||
$ca['id'] = $v['user_id'];
|
||
$ca['major'] = $v['major'];
|
||
$frag[] = $ca;
|
||
}
|
||
} else {//灰库
|
||
$list = [];
|
||
$where['state'] = 0;
|
||
$where['no_email'] = 0;
|
||
if ($type == "major") {
|
||
$where['major'] = ["in", $this->majorids($body)];
|
||
} else {
|
||
$where['field'] = ["like", "%" . $body . "%"];
|
||
}
|
||
if ($china_type == 1) {
|
||
$where['country'] = "China";
|
||
} elseif ($china_type == 2) {
|
||
$where['country'] = ["<>", "China"];
|
||
}
|
||
$list = $this->user_ash_obj
|
||
->where($where)
|
||
->page($pageIndex, $pageSize)
|
||
->select();
|
||
//规整化数据整理
|
||
foreach ($list as $v) {
|
||
$ca['email'] = $v['email'];
|
||
$ca['name'] = $v['name'];
|
||
$ca['type'] = "ash";
|
||
$ca['id'] = $v['ash_id'];
|
||
$ca['major'] = $v['major'];
|
||
$frag[] = $ca;
|
||
}
|
||
}
|
||
return $frag;
|
||
}
|
||
|
||
public function getJournalCycle($journal_id)
|
||
{
|
||
$journal_info = $this->journal_obj->where('journal_id', $journal_id)->find();
|
||
$frag = "";
|
||
if ($journal_info['cycle'] == 1) {
|
||
$frag = "Monthly";
|
||
} elseif ($journal_info['cycle'] == 2) {
|
||
$frag = "Bimonthly";
|
||
} elseif ($journal_info['cycle'] == 3) {
|
||
$frag = "Quarterly";
|
||
} else {
|
||
$frag = "Continuities";
|
||
}
|
||
return $frag;
|
||
}
|
||
|
||
public function creatUserCode($str)
|
||
{
|
||
$hashids = hashids::instance(8, "tmrjournals");
|
||
return $hashids->encode($str);
|
||
}
|
||
|
||
|
||
public function getProductionMainImgs($p_article_id)
|
||
{
|
||
$mains = $this->production_article_main_obj->where('p_article_id', $p_article_id)->where('state', 0)->select();
|
||
if (count($mains) == 0) {
|
||
$this->creatMainData($p_article_id);
|
||
$mains = $this->production_article_main_obj->where('p_article_id', $p_article_id)->where('state', 0)->select();
|
||
}
|
||
$frag = [];
|
||
foreach ($mains as $v) {
|
||
$frag[] = $v;
|
||
$ca = $this->production_article_main_img_obj->where('p_main_id', $v['p_main_id'])->where("state", 0)->find();
|
||
if ($ca) {
|
||
$frag[] = $ca;
|
||
$pre_id = $ca['p_main_img_id'];
|
||
while ($pre_id != 0) {
|
||
$cac = $this->production_article_main_img_obj->where('pre_id', $pre_id)->where('state', 0)->find();
|
||
if ($cac) {
|
||
$frag[] = $cac;
|
||
$pre_id = $cac['p_main_img_id'];
|
||
} else {
|
||
$pre_id = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $frag;
|
||
}
|
||
|
||
private function creatMainData($p_article_id)
|
||
{
|
||
$p_info = $this->production_article_obj->where('p_article_id', $p_article_id)->find();
|
||
$article_info = $this->article_obj->where('article_id', $p_info['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 = $this->ts_base_url."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;
|
||
}
|
||
if (!isset($frag['main'])) {
|
||
return jsonError("manuscript file error!");
|
||
}
|
||
|
||
|
||
//将主体内容写入数据库
|
||
foreach ($frag['main'] as $v) {
|
||
$ca['p_article_id'] = $p_article_id;
|
||
$ca['content'] = $v;
|
||
$ca['content_g'] = '';
|
||
$ca['ctime'] = time();
|
||
$this->production_article_main_obj->insert($ca);
|
||
}
|
||
}
|
||
|
||
public function refuseReferIndex($p_article_id)
|
||
{
|
||
$p_info = $this->production_article_refer_obj->where('p_article_id', $p_article_id)->where('state', 0)->where('index', ">", 0)->find();
|
||
if ($p_info) {
|
||
return;
|
||
}
|
||
$list = $this->production_article_refer_obj->where('p_article_id', $p_article_id)->where('state', 0)->select();
|
||
foreach ($list as $k => $v) {
|
||
$this->production_article_refer_obj->where('p_refer_id', $v['p_refer_id'])->update(['index' => $k]);
|
||
}
|
||
}
|
||
|
||
|
||
public function getProductionMainImgsByNew($p_article_id, $file)
|
||
{
|
||
$p_info = $this->production_article_obj->where('p_article_id', $p_article_id)->find();
|
||
$article_info = $this->article_obj->where('article_id', $p_info['article_id'])->find();
|
||
$url = $this->ts_base_url."api/typeset/webReaddoc";
|
||
$program['fileRoute'] = "https://submission.tmrjournals.com/public/completedManuscirpt/" . $file;
|
||
// $program['fileRoute'] = "https://submission.tmrjournals.com/public/completedManuscirpt/20230706/87628e769c4ee8a8414219b05c72a028.docx" ;
|
||
$res = object_to_array(json_decode(myPost($url, $program)));
|
||
$file_runs = $res['data'];
|
||
if (count($file_runs) == 0) {
|
||
return jsonError("File crawl failed");
|
||
}
|
||
//清空之前的
|
||
$this->production_article_main_obj->where('p_article_id', $p_article_id)->update(['state' => 1]);
|
||
|
||
//整理信息
|
||
$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;
|
||
}
|
||
if (!isset($frag['main'])) {
|
||
return jsonError("manuscript file error!");
|
||
}
|
||
|
||
//将主体内容写入数据库
|
||
foreach ($frag['main'] as $v) {
|
||
$ca['p_article_id'] = $p_article_id;
|
||
$ca['content'] = $v;
|
||
$ca['content_g'] = '';
|
||
$ca['ctime'] = time();
|
||
$this->production_article_main_obj->insert($ca);
|
||
}
|
||
|
||
$mains = $this->production_article_main_obj->where('p_article_id', $p_article_id)->where('state', 0)->select();
|
||
$f = [];
|
||
foreach ($mains as $v) {
|
||
$f[] = $v;
|
||
$ca = $this->production_article_main_img_obj->where('p_main_id', $v['p_main_id'])->where("state", 0)->find();
|
||
if ($ca) {
|
||
$f[] = $ca;
|
||
$pre_id = $ca['p_main_img_id'];
|
||
while ($pre_id != 0) {
|
||
$cac = $this->production_article_main_img_obj->where('pre_id', $pre_id)->where('state', 0)->find();
|
||
if ($cac) {
|
||
$f[] = $cac;
|
||
$pre_id = $cac['p_main_img_id'];
|
||
} else {
|
||
$pre_id = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $f;
|
||
}
|
||
|
||
|
||
/**创建空production实例,应对main和refers
|
||
* @return void
|
||
*/
|
||
public function createEmptyProduction($web_article)
|
||
{
|
||
|
||
$insert['title'] = $web_article['title'];
|
||
$insert['type'] = $web_article['type'];
|
||
$ree = explode("/", $web_article['doi']);
|
||
$insert['doi'] = isset($ree[1]) ? $ree[1] : '';
|
||
$insert['w_article_id'] = $web_article['article_id'];
|
||
$insert['proof_state'] = 2;
|
||
$insert['state'] = 2;
|
||
return $this->production_article_obj->insertGetId($insert);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
?>
|