request->post();
$rule = new Validate([
'article_id' => 'require|number'
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
// $data['article_id'] = 1144;
$check = $this->production_article_obj->where('article_id', $data['article_id'])->where('state', 0)->find();
if ($check) {
return jsonError('Instance already exists');
}
$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 = $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'];
// return jsonSuccess($file_runs);
//整理信息
$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'] = $data['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 getWebMains(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/getArticleMainsForSubmission";
$pro['article_id'] = $data['article_id'];
$res = object_to_array(json_decode(myPost($url,$pro)));
$re['mains'] = $res['data']['mains'];
$re['article'] = $res['data']['article'];
return jsonSuccess($re);
}
public function addWebMain(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>'require',
"pre_id"=>"require",
"type"=>"require",
"content"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/addArticleMainAddForSubmission";
$res = object_to_array(json_decode(myPost($url,$data)));
return jsonSuccess([]);
}
public function addWebMains(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>'require',
"pre_id"=>"require",
"contents"=>"require|array"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/addArticleMainsAddForSubmission";
$program['article_id'] = $data['article_id'];
$program['pre_id'] = $data['pre_id'];
$program['contents'] = json_encode($data['contents']);
$res = object_to_array(json_decode(myPost($url,$program)));
return jsonSuccess($res);
}
/**添加主题内容的空白行
* @return void
*/
public function addWebMainEmpty(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require",
"pre_id"=>"require",
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/addArticleMainAddEmptyForSubmission";
$res = object_to_array(json_decode(myPost($url,$data)));
return jsonSuccess([]);
}
/**清空web的主体内容
* @return void
*/
public function clearWebMains(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/clearArticleMainForSubmission";
$res = object_to_array(json_decode(myPost($url,$data)));
return jsonSuccess([]);
}
public function delWebMain(){
$data = $this->request->post();
$rule = new Validate([
"article_main_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/delArticleMainForSubmission";
$res = object_to_array(json_decode(myPost($url,$data)));
return jsonSuccess([]);
}
public function delWebMains(){
$data = $this->request->post();
$rule = new Validate([
"ids"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$program['ids'] = json_encode($data['ids']);
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/delArticleMainsForSubmission";
$res = object_to_array(json_decode(myPost($url,$program)));
return jsonSuccess([]);
}
public function editWebMain(){
$data = $this->request->post();
$rule = new Validate([
"article_main_id"=>"require",
"type"=>"require",
"content"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/editArticleMainForSubmission";
$res = object_to_array(json_decode(myPost($url,$data)));
return jsonSuccess([]);
}
/**
* 获取全部生成实例的main内容
* @return \think\response\Json|void
* @author wangjinlei
*/
public function getProductionMains(){
$data = $this->request->post();
$rule = new Validate([
"p_article_id" => "require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$p_info = $this->production_article_obj->where('p_article_id',$data['p_article_id'])->find();
$frag = $this->getProductionMainImgs($data['p_article_id']);
if(count($frag)==0){
return jsonError("create error");
}
$re['mains'] = $frag;
$re['production'] = $p_info;
return jsonSuccess($re);
}
/**
* @return void
*/
public function getProductionMainsByDoi(){
$data = $this->request->post();
$rule = new Validate([
'doi'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$a = explode('/',$data['doi']);
$pro_info = $this->production_article_obj->where('doi',$a[1])->where('state',2)->find();
if(!$pro_info){
return jsonError("production error");
}
if(isset($data['file'])&&$data['file']!=""){
$frag = $this->getProductionMainImgsByNew($pro_info['p_article_id'],$data['file']);
}else{
$frag = $this->getProductionMainImgs($pro_info['p_article_id']);
}
if(count($frag)==0){
return jsonError("create error");
}
$re['mains'] = $frag;
$re['production'] = $pro_info;
return jsonSuccess($re);
}
/**
* 删除main内容的某一行
* @return void
*
*/
public function delProductionMain(){
$data = $this->request->post();
$rule = new Validate([
'p_main_id' => 'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->production_article_main_obj->where('p_main_id',$data['p_main_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
/**添加主体文章图片
* @return void
*/
public function addProductionMainImg(){
$data = $this->request->post();
$rule = new Validate([
'p_article_id'=>'require',
"pre_type"=>"require",
"body"=>"require",
"content"=>"require",
"width"=>"require",
"note"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$insert['p_article_id'] = $data['p_article_id'];
if($data['pre_type']=="main"){
$insert['p_main_id'] = $data['body'];
}else{
$insert['pre_id'] = $data['body'];
}
$insert['content'] = $data['content'];
$insert['width'] = $data['width'];
$insert['note'] = $data['note'];
$this->production_article_main_img_obj->insert($insert);
return jsonSuccess([]);
}
/**删除mainimg
* @return void
*/
public function delProductionMainImg(){
$data = $this->request->post();
$rule = new Validate([
'p_main_img_id'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$p_img_info = $this->production_article_main_img_obj->where('p_main_img_id',$data['p_main_img_id'])->find();
$next_info = $this->production_article_main_img_obj->where('pre_id',$p_img_info['p_main_img_id'])->find();
if($next_info){
if($p_img_info['p_main_id']==0){
$this->production_article_main_img_obj->where('p_main_img_id',$next_info['p_main_img_id'])->update(['pre_id'=>$p_img_info['pre_id']]);
}else{
$this->production_article_main_img_obj->where('p_main_img_id',$next_info['p_main_img_id'])->update(['p_main_id'=>$p_img_info['p_main_id']]);
}
}
$this->production_article_main_img_obj->where('p_main_img_id',$data['p_main_img_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
/**编辑mainimg
* @return void
*/
public function editProductionMainImg(){
$data = $this->request->post();
$rule = new Validate([
'p_main_img_id'=>'require',
"width"=>"require",
"content"=>"require",
"note"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$update['width']=$data['width'];
$update['content']=$data['content'];
$update['note'] = $data['note'];
$this->production_article_main_img_obj->where('p_main_img_id',$data['p_main_img_id'])->update($update);
return jsonSuccess([]);
}
/**
* 编辑main内容
* @return \think\response\Json|void
*
*/
public function editProductionMain(){
$data = $this->request->post();
$rule = new Validate([
'p_main_id' => 'require',
'content'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$update['content'] = trim($data['content']);
$this->production_article_main_obj->where('p_main_id',$data['p_main_id'])->update($update);
return jsonSuccess([]);
}
public function pushMainToWeb(){
$data = $this->request->post();
$rule = new Validate([
'article_id'=>"require",
"p_article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Article/addArticleMainForSubmission";
$pro['article_id'] = $data['article_id'];
$pro['p_article_id'] = $data['p_article_id'];
$res = object_to_array(json_decode(myPost($url,$pro)));
// if($res['code']==1){
// return jsonError("Repeated submission");
// }
return jsonSuccess([]);
}
/**main内容gpt程序校对
* @return void
*
*/
public function mainGptcheck(){
$data = $this->request->post();
$rule = new Validate([
'p_main_id'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$main_info = $this->production_article_main_obj->where('p_main_id',$data['p_main_id'])->find();
if(mb_strlen($main_info['content'])<20){
return trim($main_info['content']);
}
$res = object_to_array(json_decode(pushGpt('请将以下内容按照医学期刊的标准校对,不要改变原意,主要是对格式和拼写的校对,将这四个标签保留,将校对好的内容返回 :'.trim($main_info['content']))));
$r = $res['choices'][0]['message']['content'];
$re['content'] = $r;
return jsonSuccess($re);
}
public function getPublicMains(){
}
/**
* 删除生产实例
*/
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',
'acknowledgment' => 'require',
'keywords' => 'require',
'author_contribution' => 'require',
'abbr' => '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'] = isset($data['icon']) ? trim($data['icon']) : '';
$update['tradition_tag'] = isset($data['tradition_tag']) ? trim($data['tradition_tag']) : '';
$update['tradition'] = isset($data['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'] = isset($data['abbreviation']) ? trim($data['abbreviation']) : '';
$update['acknowledgment'] = trim($data['acknowledgment']);
$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'] = $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());
}
$this->refuseReferIndex($data['p_article_id']);
$dois = $this->production_article_refer_obj->where("p_article_id", $data['p_article_id'])->where("refer_doi","<>","")->where("state",0)->group("refer_doi")->having("count(*)>1")->column("refer_doi");
$list = $this->production_article_refer_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->order("index")->select();
foreach ($list as $k => $v){
if(in_array($v['refer_doi'],$dois)){
$list[$k]['is_repeat'] = 1;
}else{
$list[$k]['is_repeat'] = 0;
}
}
$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());
}
$updata['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');
}else{
$journalids[] = $data['journal_id'];
}
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
$list = $this->production_article_obj
->field('t_production_article.*,t_article.accept_sn')
->join('t_article', 't_article.article_id = t_production_article.article_id', 'left')
->where('t_production_article.journal_id', 'in', $journalids)
->where('t_production_article.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 editArticleLast()
{
$data = $this->request->post();
$rule = new Validate([
'p_article_id' => 'require|number',
'abstract' => 'require',
'doi' => 'require',
'pub_date' => 'require'
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$updata['abstract'] = trim($data['abstract']);
$updata['doi'] = $data['doi'];
$updata['pub_date'] = $data['pub_date'];
$this->production_article_obj->where('p_article_id', $data['p_article_id'])->update($updata);
return jsonSuccess([]);
}
/**
* 推送文章到官网系统
*/
public function pushArticleToSystem()
{
$data = $this->request->post();
$rule = new Validate([
'p_article_id' => 'require'
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find();
if ($p_info['state'] != 0) {
return jsonError("Non repeatable submission");
}
if ($p_info['proof_state'] != 2) {
return jsonError('Warning: It is a violation to publish your article online without completing PROOF.
The ONLINE step will only continue if you have completed the PROOF step.');
}
$article_info = $this->article_obj->where('article_id', $p_info['article_id'])->find();
$journal_info = $this->journal_obj->where('journal_id', $article_info['journal_id'])->find();
$authors = $this->production_article_author_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
$report_authors = [];
foreach ($authors as $k => $v) {
$cache = $this->production_article_author_to_organ_obj
->field('t_production_article_organ.organ_name')
->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();
$authors[$k]['organs'] = $cache;
if($v['is_report']==1){
$c_user = $this->user_obj->where('email',$v['email'])->find();
$cac['user_id'] = $c_user['user_id'];
$report_authors[] = $cac;
}
}
$organs = $this->production_article_organ_obj->where('p_article_id', $data['p_article_id'])->where('state', 0)->select();
//check信息是否完整
if (count($authors) == 0 || $p_info['journal_stage_id'] == '' || $p_info['doi'] == '' || $p_info['abstract'] == '' || $p_info['npp'] == '') {
return jsonError('Incomplete information');
}
//发送推送请求
// $url = "http://www.journal.com/master/Article/addArticleForSubmission";
$url = 'http://journalapi.tmrjournals.com/public/index.php/master/Article/addArticleForSubmission';
$pra = [];
$pra['p_article_id'] = $data['p_article_id'];
$pra['title'] = $p_info['title'];
$pra['journal_stage_id'] = $p_info['journal_stage_id'];
$pra['issn'] = $journal_info['issn'];
$pra['ltai'] = $p_info['ltai'];
$pra['type'] = $p_info['type'];
$pra['doi'] = $p_info['doi'];
$pra['tradition_tag'] = $p_info['tradition_tag'];
$pra['tradition'] = $p_info['tradition'];
$pra['mhoo'] = $p_info['mhoo'];
$pra['abstract'] = $p_info['abstract'];
$pra['pub_date'] = $p_info['pub_date'];
$pra['abbr'] = $p_info['abbr'];
$pra['icon'] = $p_info['icon'];
$pra['lx_online'] = $journal_info['cycle']==0?0:1;
if ($p_info['file_sub'] != '') {
$pra['file_sub'] = $p_info['file_sub'];
}
if ($p_info['file_sub2'] != '') {
$pra['file_sub2'] = $p_info['file_sub2'];
}
if ($p_info['file_cdf'] != '') {
$pra['file_cdf'] = $p_info['file_cdf'];
}
if ($p_info['endnote'] != '') {
$pra['endnote'] = $p_info['endnote'];
}
if ($p_info['bibtex'] != '') {
$pra['bibtex'] = $p_info['bibtex'];
}
if ($p_info['file_original'] != ''){
$pra['file_original'] = $p_info['file_original'];
}
$pra['file_pdf'] = $p_info['file_pdf'];
$pra['keywords'] = $p_info['keywords'];
$pra['npp'] = $p_info['npp'];
$pra['authors'] = json_encode($authors);
$pra['organs'] = json_encode($organs);
$res = object_to_array(json_decode(myPost($url, $pra)));
if ($res['code'] == 0) {
$r_update['state'] = 2;
$r_update['w_article_id'] = isset($res['data']['article_id'])?$res['data']['article_id']:0;
$this->production_article_obj->where('p_article_id', $data['p_article_id'])->update($r_update);
foreach($report_authors as $v){
$iua['user_id'] = $v['user_id'];
$iua['w_article_id'] = $res['data']['article_id'];
$iua['w_article_doi'] = '10.53388/'.$p_info['doi'];
$iua['journal_title'] = $journal_info['title'];
$this->user_author_obj->insert($iua);
}
return jsonSuccess([]);
} else {
return jsonError('system error:' . $res['msg']);
}
}
public function getPdfByHtml(){
$data = $this->request->post();
$html = $data['html'];
$path = ROOT_PATH . 'public' . DS . 'testpdf' . DS;
$intFontSize = 10.5;
// $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
// $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'default_font_size' => $intFontSize,
'useSubstitutions' => true, //中文支持关键
'useAdobeCJK' => true,
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
'margin_header' => 0,
'margin_footer' => 0,
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/custom/font/directory',
]),
'fontdata' => $fontData + [
'宋体' => [
'R' => 'Sun-ExtA.ttf',
'I' => 'Sun-ExtB.ttf',
]
],
'default_font' => '宋体' //CSS中写的汉字宋体就这么写要是别的自定义的就写自己的 自定义字体关键
]);
$strContent = $html;
$mpdf->WriteHTML($strContent);
$strFileName_New = time() . rand(100, 999) . '.pdf';
$mpdf->Output($path .$strFileName_New, 'f');
return jsonSuccess(['url'=>$strFileName_New]);
}
public function creatpdf()
{
$path = ROOT_PATH . 'public' . DS . 'testpdf' . DS;
$mpdf = new Mpdf(['mode' => 'utf-8', 'format' => 'A4']);
$mpdf->SetDisplayMode('fullpage');
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
$fileUrl = $path . '1234.pdf';
$mpdf->WriteHTML(file_get_contents($path . 'meaut1.html'));
$mpdf->Output($fileUrl, "D");
}
public function creatpdf1()
{
$path = ROOT_PATH . 'public' . DS . 'testpdf' . DS;
$intFontSize = 10.5;
// $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
// $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'default_font_size' => $intFontSize,
'useSubstitutions' => true, //中文支持关键
'useAdobeCJK' => true,
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
'margin_header' => 0,
'margin_footer' => 0,
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/custom/font/directory',
]),
'fontdata' => $fontData + [
'宋体' => [
'R' => 'Sun-ExtA.ttf',
'I' => 'Sun-ExtB.ttf',
]
],
'default_font' => '宋体' //CSS中写的汉字宋体就这么写要是别的自定义的就写自己的 自定义字体关键
]);
//自定义标签样式设置也可以直接修改DefaultCss.php中的默认设置
// $mpdf->defaultCSS["BODY"]['FONT-SIZE'] = '10.5pt';
// $mpdf->defaultCSS["BODY"]['LINE-HEIGHT'] = '1.6em';
// $mpdf->defaultCSS["P"]['MARGIN'] = '0 0';
// $mpdf->defaultCSS["P"]['PADDING'] = '0';
// $mpdf->defaultCSS["H1"]['FONT-SIZE'] = '16pt';
// $mpdf->defaultCSS["H1"]['MARGIN'] = '0 0';
// $mpdf->defaultCSS["H2"]['FONT-SIZE'] = '10.5pt';
// $mpdf->defaultCSS["H2"]['MARGIN'] = '0em 0';
// $mpdf->defaultCSS["H4"]['FONT-SIZE'] = '14pt';
// $mpdf->defaultCSS["H4"]['MARGIN'] = '0 0';
// $mpdf->defaultCSS["H5"]['FONT-SIZE'] = '10.5pt';
// $mpdf->defaultCSS["H5"]['FONT-WEIGHT'] = 'normal';
// $mpdf->defaultCSS["H5"]['MARGIN'] = '-3.4em 0 0 0';
// $mpdf->defaultCSS['SPAN'] = [
// 'PADDINT-LEFT' => '14px',
// 'PADDINT-RIGHT' => '14px',
// 'PADDINT-TOP' => '0px',
// 'PADDINT-BOTTOM' => '0px'
// ];
$strContent =file_get_contents($path . 'meaut33.html');
$mpdf->WriteHTML($strContent);
$strFileName_New = $path .time() . rand(100, 999) . '.pdf';
$mpdf->Output($strFileName_New, true); //第二个参数true是直接下载 不设置默认仅保存
}
// public function bekjournal($str)
// {
// preg_match("/[0-9]{4}/", $str, $math);
// $year = $math[0];
// $frag[0] = trim(substr($str, 0, stripos($str, $year)));
// $frag[1] = substr($str, stripos($str, $year));
// return $frag;
// }
public function prgeAuthor($author)
{
$a = explode(',', $author);
if (count($a) < 7) {
return $author . '.';
} else {
return trim($a[0]) . ', ' . trim($a[1]) . ', ' . trim($a[2]) . ', et al.';
}
}
// public function testTypeSetting(){
// $data['p_article_id'] = 7;
// $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 .= trim($v['first_name']) . ' ' . trim($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($rs);
// $url = "http://localhost:8081/typeset/webtest";
// $res = object_to_array(json_decode(myPost1($url, $typesetInfo)));
// dump($res);
// }
/**
* 排版主方法入口
*/
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 .= trim($v['first_name']) . ' ' . trim($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)->order("index")->select();
// $refers = [];
// foreach ($rs as $v) {
// $refers[] = $v['refer_frag'];
// }
// $typesetInfo['refers'] = json_encode($refers);
$typesetInfo['refers'] = json_encode($rs);
$url = $this->ts_base_url."api/typeset/webGetDocx";
// $url = "http://localhost:8081/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 = date('Ymd') . DS . $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 doTypeSettingNew(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$p_info = $this->production_article_obj->where("article_id",$data['article_id'])->whereIn("state",[0,2])->find();
if(!$p_info){
return jsonError("error");
}
$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($p_info['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', $p_info['p_article_id'])->where('is_report', 1)->where('state', 0)->select();
$corrauthor = '';
$corremail = '';
foreach ($corr_authors as $v) {
$corrauthor .= trim($v['first_name']) . ' ' . trim($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)->order("index")->select();
$typesetInfo['refers'] = json_encode($rs);
$main_list = $this->article_main_obj->where("article_id",$data['article_id'])->whereIn("state",[0,2])->order("sort")->select();
$mainList = [];
$images = [];
$tables = [];
foreach ($main_list as $k =>$item){
$main_string = "";
if($item['type']==1){
$info = $this->article_main_image_obj->where("ami_id",$item['ami_id'])->find();
$arr['image'] = $info['url'];
$arr['note'] = $info['note'];
$images[$info['ami_id']] = $arr;
$main_string = "";
}else if($item['type']==2){
$info = $this->article_main_table_obj->where("amt_id",$item['amt_id'])->find();
$arr_table['title'] = $info['title'];
$arr_table['table_data'] = $info['table_data'];
$arr_table['note'] = $info['note'];
$tables[$info['amt_id']] = $arr_table;
$main_string = "
" : trim($v['first_name']) . ' ' . trim($v['last_name']) . ''; $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) ->order('t_production_article_author_to_organ.p_article_organ_id') ->select(); foreach ($cac as $val) { $cache_str .= (intval(search_array_val($address, $val['organ_name'])) + 1) . ", "; } $cache_str = trim($cache_str); $cache_str = substr($cache_str, 0, -1); if ($first_num > 1 && $v['is_first'] == 1) { $cache_str .= '#'; } if ($v['is_report'] == 1) { $cache_str .= '*'; } $cache_str .= ''; $author .= $cache_str; } //组装address $address_str = ''; foreach ($address as $k => $v) { $address_str .= ($k + 1) . ' ' . $v . ' '; } $frag['author'] = $author; $frag['address'] = $address_str; $frag['addressList'] = $address; return $frag; } /** * 更改文章pdf文件 */ public function updateArticlePDF() { $data = $this->request->post(); $rule = new Validate([ 'p_article_id' => 'require', 'pdf' => 'require' ]); if (!$rule->check($data)) { return jsonError($rule->getError()); } $update['file_pdf'] = $data['pdf']; $this->production_article_obj->where('p_article_id', $data['p_article_id'])->update($update); return jsonSuccess([]); } /** * 上传pdf文件 */ public function up_pdf_file() { $file = request()->file('pdf'); if ($file) { $info = $file->move(ROOT_PATH . 'public' . DS . 'pdf'); if ($info) { return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]); } else { return json(['code' => 1, 'msg' => $file->getError()]); } } } /**上传最终版文章word文件 * @return \think\response\Json|void */ public function up_last_artFile(){ $file = request()->file('completedManuscirpt'); if ($file) { $info = $file->move(ROOT_PATH . 'public' . DS . 'completedManuscirpt'); if ($info) { return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]); } else { return json(['code' => 1, 'msg' => $file->getError()]); } } } /** * 上传pdf文件 */ public function up_mainimg_file() { $file = request()->file('mainimg'); if ($file) { $info = $file->move(ROOT_PATH . 'public' . DS . 'mainimg'); if ($info) { return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]); } else { return json(['code' => 1, 'msg' => $file->getError()]); } } } }