admin_obj = Db::name('admin');
$this->journal_obj = Db::name('journal');
$this->article_obj = Db::name('article');
$this->journal_topic_obj = Db::name('journal_topic');
$this->article_author_obj = Db::name('article_author');
$this->journal_stage_obj = Db::name('journal_stage');
$this->journal_line_obj = Db::name('journal_line');
$this->journal_notices_obj = Db::name('journal_notices');
$this->journal_abs_obj = Db::name('journal_abstracting');
$this->article_to_topic_obj = Db::name('article_to_topic');
$this->article_to_line_obj = Db::name('article_to_line');
$this->journal_cfp_obj = Db::name('journal_cfp');
$this->journal_paper_obj = Db::name('journal_paper');
$this->journal_paper_art_obj = Db::name('journal_paper_art');
$this->db_obj = Db::name('db');
$this->db_data_obj = Db::name('db_data');
}
/**
* @title 增加数据库
* @description 增加数据库
* @author wangjinlei
* @url /master/Datebase/addDb
* @method POST
*
* @param name:name type:string require:1 desc:数据库名字
* @param name:intro type:string require:1 desc:简介
*/
public function addDb()
{
$data = $this->request->post();
$insert['name'] = $data['name'];
$insert['intro'] = $data['intro'];
$insert['ctime'] = time();
$this->db_obj->insert($insert);
return jsonSuccess([]);
}
/**
* @title 删除数据库
* @description 删除数据库
* @author wangjinlei
* @url /master/Datebase/delDb
* @method POST
*
* @param name:db_id type:int require:1 desc:数据库id
*/
public function delDb()
{
$data = $this->request->post();
$this->db_obj->where('db_id', $data['db_id'])->update(['state' => 1]);
return jsonSuccess([]);
}
public function push_db(){
$data = $this->request->post();
return $this->bf_db_push($data['stage']);
}
/**
* 备份数据推送至sftp
*/
public function bf_db_push($stage)
{
Vendor('PHPExcel.PHPExcel');
Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
$baseDir = ROOT_PATH . 'public' . DS . 'davExcel' . DS . $stage . DS;
if (!is_dir($baseDir)) {
@mkdir($baseDir);
}
$objExcel = new \PHPExcel();
//set document Property
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objActSheet = $objExcel->getActiveSheet();
$letter = explode(',', "A,B,C,D,E,F,G,H,I,J,K,L,M,N");
$arrHeader = array('Journal Title', 'Journal P-ISSN', 'Journal E-ISSN', 'Article DOI/ID', 'PDF File Name', 'Article Title', 'Authors', 'Publication Date', 'Volume', 'Issue', 'Supplement', 'First Page', 'Last Page', 'Copyright Statement');
//填充表头信息
$lenth = count($arrHeader);
for ($i = 0; $i < $lenth; $i++) {
$objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
// 设置表头高度
$objActSheet->getRowDimension('1')->setRowHeight(25);
};
//查找数据
$stage_info = $this->journal_stage_obj->where('journal_stage_id', $stage)->find();
$journal_info = $this->journal_obj->where('journal_id',$stage_info['journal_id'])->find();
$articles = $this->article_obj
->field('j_article.*,j_journal.title journalTitle,j_journal.issn')
->join("j_journal", "j_article.journal_id = j_journal.journal_id", 'left')
->where('j_article.journal_stage_id', $stage)
->where('j_article.state', 0)
->select();
//填充表格信息
foreach ($articles as $k => $v) {
$k += 2;
$objActSheet->setCellValue('A' . $k, choiseti1($v['article_id'],$v['journalTitle']));
$objActSheet->setCellValue('B' . $k, $v['issn']);
$objActSheet->setCellValue('C' . $k, '');
$objActSheet->setCellValue('D' . $k, $v['doi']);
$fpdf = explode("/", $v['file_pdf']);
$objActSheet->setCellValue('E' . $k, $fpdf[1]);
//下载pdf
copy('http://journalapi.tmrjournals.com/public/articlePDF/' . $v['file_pdf'], $baseDir . $fpdf[1]);
$objActSheet->setCellValue('F' . $k, $v['title']);
//构建作者
$cache_author = $this->article_author_obj->where('article_id', $v['article_id'])->where('state', 0)->column('author_name');
$objActSheet->setCellValue('G' . $k, implode(",", $cache_author));
$objActSheet->setCellValue('H' . $k, $v['pub_date']);
$objActSheet->setCellValue('I' . $k, $stage_info['stage_vol']);
//连续出版的issue为空
if(($journal_info['journal_id']==2&&$stage_info['stage_year']>=2022)||($journal_info['journal_id']==3&&$stage_info['stage_year']>=2022)||($journal_info['journal_id']==17&&$stage_info['stage_year']>=2019)){
$objActSheet->setCellValue('J' . $k, '');
}else{
$objActSheet->setCellValue('J' . $k, $stage_info['issue_date']);
}
if ($v['file_sub'] != '') {
$spdf = explode("/", $v['file_sub']);
//下载附加信息
copy('http://journalapi.tmrjournals.com/public/articleSUB/' . $v['file_sub'], $baseDir . $spdf[1]);
$objActSheet->setCellValue('K' . $k, $spdf[1]);
} else {
$objActSheet->setCellValue('K' . $k, '');
}
//整理分期
$npp = trim($v['npp']);
$npp = str_replace('–','-',$npp);
$npp = str_replace("—",'-',$npp);
if (strpos($npp, '-') == false) {
$objActSheet->setCellValue('L' . $k, '');
$objActSheet->setCellValue('M' . $k, '');
} else {
$cc = explode('-', trim($npp));
$objActSheet->setCellValue('L' . $k, $cc[0]);
$objActSheet->setCellValue('M' . $k, $cc[1]);
}
$objActSheet->setCellValue('N' . $k, "© " . $stage_info['stage_year'] . " By Author(s). Published by TMR Publishing Group Limited. This is an open access article under the CC-BY license. (http://creativecommons.org/licenses/BY/4.0/)");
// 表格高度
$objActSheet->getRowDimension($k)->setRowHeight(25);
}
$width = array(10, 15, 20, 25, 30);
//设置表格的宽度
$objActSheet->getColumnDimension('A')->setWidth($width[2]);
$objActSheet->getColumnDimension('B')->setWidth($width[1]);
$objActSheet->getColumnDimension('C')->setWidth($width[1]);
$objActSheet->getColumnDimension('D')->setWidth($width[2]);
$objActSheet->getColumnDimension('E')->setWidth($width[4]);
$objActSheet->getColumnDimension('F')->setWidth($width[4]);
$objActSheet->getColumnDimension('G')->setWidth($width[4]);
$objActSheet->getColumnDimension('H')->setWidth($width[2]);
$objActSheet->getColumnDimension('I')->setWidth($width[1]);
$objActSheet->getColumnDimension('J')->setWidth($width[1]);
$objActSheet->getColumnDimension('K')->setWidth($width[4]);
$objActSheet->getColumnDimension('L')->setWidth($width[1]);
$objActSheet->getColumnDimension('M')->setWidth($width[1]);
$objActSheet->getColumnDimension('N')->setWidth($width[4]);
$outfileTitle = $stage_info['journal_stage_id'] . "dav";
$res = $objWriter->save($baseDir . $outfileTitle . ".xlsx");
$this->push_sftp($stage);
return json_encode(['code' => 0, 'msg' => '成功']);
}
// public function ls_push(){
// $stages = $this->journal_stage_obj->where('state',0)->where('is_publish',1)
// ->where('journal_stage_id',">",360)
// ->where('journal_stage_id',"<=",360)
// ->select();
// foreach($stages as $v){
// $this->push_sftp($v['journal_stage_id']);
// file_put_contents('/home/wwwroot/journalapi.tmrjournals.com/public/system/1.txt','****'.$v['journal_stage_id'],FILE_APPEND);
// }
// }
public function getaaa(){
$num = $this->request->post('num');
$list = $this->article_obj->where('j_article.state',0)->join("j_journal_stage","j_journal_stage.journal_stage_id = j_article.journal_stage_id",'left')
->page($num,1000)->field("j_article.article_id,j_journal_stage.stage_year")->select();
$re['list'] = $list;
return jsonSuccess($re);
}
private function push_sftp($stage)
{
$stage_info = $this->journal_stage_obj->where('journal_stage_id',$stage)->find();
$journal_info = $this->journal_obj->where('journal_id',$stage_info['journal_id'])->find();
//链接sftp服务器
$config['host'] = 'ftp.portico.org';
$config['port'] = 22;
$config['username'] = "TMR";
$config['password'] = "h6EHD8";
$sftp_obj = new Sftp($config);
//判断目录是否存在,不存在创建
$j_base = $sftp_obj->ssh2_dir_exits("/SPREADSHEET/".$journal_info['issn']);
if(!$j_base){
$sftp_obj->ssh2_sftp_mchkdir("/SPREADSHEET/".$journal_info['issn']);
}
$m_base = $sftp_obj->ssh2_dir_exits("/SPREADSHEET/".$journal_info['issn'].'/'.$stage_info['stage_year'].'-'.$stage_info['stage_vol'].'-'.$stage_info['stage_no']);
if(!$m_base){
$sftp_obj->ssh2_sftp_mchkdir("/SPREADSHEET/".$journal_info['issn'].'/'.$stage_info['stage_year'].'-'.$stage_info['stage_vol'].'-'.$stage_info['stage_no']);
}
//读取文件夹内的内容
$files = scandir(ROOT_PATH . 'public' . DS . 'davExcel' . DS . $stage);
foreach($files as $v){
if($v=='.'||$v=='..'){
continue;
}
$cdata['local'] = ROOT_PATH . 'public' . DS . 'davExcel' . DS . $stage.DS.$v;
$cdata['remote'] = "/SPREADSHEET/".$journal_info['issn'].'/'.$stage_info['stage_year'].'-'.$stage_info['stage_vol'].'-'.$stage_info['stage_no']."/".$v;
Queue::push('app\api\job\mysftp@push', $cdata, "mysftp");
}
}
/**
* 推送邮件至青年科学家
*/
public function pushEmailToYboard(){
$data = $this->request->post();
$rule = new Validate([
'num'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$url = "http://api.tmrjournals.com/public/index.php/api/User/getAshUserForPushEmail";
$p['num'] = $data['num'];
$res = object_to_array(json_decode(myPost($url,$p)));
$list = $res['data']['list'];
// $list = [];
// $list[] = ['country'=>"China1","email"=>'751475802@qq.com'];
// $list[] = ['country'=>"China1","email"=>'849192806@qq.com'];
// $list[] = ['country'=>"China1","email"=>'376837995@qq.com'];
foreach($list as $v){
$dd = "";
$title = 'Traditional Medicine Research will get the first Impact Factor (WOS) in 2023';
$dd .= "
";
// if($v['country']=='China'){
// $title = "2023年度Traditional Medicine Research青年编委招募通知";
// $dd .= "传统医学研究 Traditional Medicine Research(ISSN 2413-3973)创刊于2016年,专注于发表具有明确历史记载、民族特色和地域特色的传统医药学研究和相关社会科学研究。我们非常高兴地宣布:
";
// $dd .= "1、期刊已于2023年第8卷第1期起由双月刊改为月刊
2、根据科睿唯安最新政策 【科睿唯安宣布2023年度《期刊引证报告》新变化】
Traditional Medicine Research期刊将在2023年获得首个Impact Factor
3、2023年,期刊仍然免除版面费
";
// $dd .= "官网:https://www.tmrjournals.com/tmr
邮箱:tmr@tmrjournals.com
";
// $dd .= "为了进一步提升期刊国际影响力、促进青年科学家学术交流、增加编委人才储备,编委会研究决定开始2023年第二批青年编委遴选工作。青年编委会由45岁以下、具有博士学位或副高以上职称的青年学者组成。
";
// $dd .= "任期: 每期任期1年。每年根据年度任务完成情况筛选下一年度青年编委。
";
// $dd .= "青年编委遴选标准
";
// $dd .= "年龄45岁以下,博士学历或副高以上职称,特别优秀者可以酌情放宽。
第一作者或通讯作者发表SCI文章5篇以上,有国家及国际科研项目者优先考虑。
对英文学术论文有一定编辑或审稿能力。
";
// $dd .= "权益
// 遴选后即颁发精美青年编委证书,聘期1年。
// 个人及团队投稿享受语言处理费75折。
// 优秀青年编委可作为本刊编委会的后备人选(每年遴选4-6人进入编委会)。
// 可以申请组建专刊,扩大您及您团队的影响力。
// 可享有参加培训、指导论文写作、联合科研合作的权利。
";
// $dd .= "工作
// 根据青年编委的研究领域,每年需要审稿3-5篇。
// 运用自身优势,在所在高校、医院积极宣传杂志,将优秀的稿件推荐给周围的学者。
// 为杂志的发展方向及风格提出意见和建议。有条件者可小型论坛、会议等。
";
// $dd .= "申请流程:
// 第一步:登录TMR出版集团投稿与稿件追踪系统 并完善个人信息
// https://submission.tmrjournals.com
// 第二步:点击 Young Scientist Board 申请
// 申请过程中有任何问题请联系: tmr@tmrjournals.com
// 报名截止时间:2023年6月15日
// 流程:提交申请—编委会审定—邮件通知—公示
// 现任青年编委无需提交申请材料,编辑部会根据年终考核评估情况自动遴选。
";
// }else{
// $title = "2023 Traditional Medicine Research Young Scientist Board Volunteer Opportunity";
// $dd .= "Traditional Medicine Research (ISSN 2413-3973) was founded in 2016 and is dedicated to publishing research on traditional medicine and related social sciences that have clear historical records, ethnic characteristics, and regional features. We are pleased to announce that:
";
// $dd .= "Starting from Volume 8, Issue 1 in 2023, the journal will change from a bimonthly to a monthly publication.
// According to the latest policy of Clarivate Analytics, Traditional Medicine Research will receive its first Impact Factor in 2023.
// In 2023, the journal will continue to waive publication fees.
";
// $dd .= "Website: https://www.tmrjournals.com/tmr
Email: tmr@tmrjournals.com
";
// $dd .= "In order to further enhance the international influence of the journal, promote academic exchanges among young scientists, and increase the reserve of editorial board members, the editorial board has decided to launch the second round of selection for Young Scientist Board members in 2023. The Young Scientist Board will consist of scholars under the age of 45 with a doctoral degree or an associate professorship.
";
// $dd .= "Term: The term is one year. The next year's Young Scientist Board will be selected based on the completion of the annual tasks.
";
// $dd .= "Selection Criteria for Young Scientist Board Members:
";
// $dd .= "Applicants must be under 45 years old, have a doctoral degree or an associate professorship, and exceptional candidates may be considered.
// Priority will be given to applicants who have published at least five SCI articles as first or corresponding authors and have national or international research projects.
// Applicants should have certain editing or reviewing abilities in English academic papers.
";
// $dd .= "Benefits:
// Selected candidates will receive a certificate of excellence as a Young Scientist Board member for a term of one year.
// Personal and team submissions will enjoy a 25% discount on language processing fees.
// Outstanding Young Scientist Board members can serve as reserve candidates for the editorial board (4-6 candidates will be selected each year).
// Selected candidates can apply to organize a special issue to expand their influence.
// Selected candidates will have the right to participate in training, guidance for paper writing, and joint research cooperation.
";
// $dd .= "Responsibilities:
// Based on the research field of Young Scientist Board members, they are required to review 3-5 papers per year.
// Actively promote the journal at their universities and hospitals, and recommend excellent papers to colleagues.
// Provide opinions and suggestions for the development direction and style of the journal. Those who are qualified can participate in small forums, conferences, etc.
";
// $dd .= 'Application Process:
// Step 1: Log in to the TMR Publishing Group submission and manuscript tracking system and complete personal information.
// https://submission.tmrjournals.com
// Step 2: Click on the "Young Scientist Board" application.
// If there are any questions during the application process, please contact: tmr@tmrjournals.com
// Application deadline: June 15, 2023.
// Process: Submit application - Editorial board approval - Email notification - Public announcement.
// Current Young Scientist Board members do not need to submit application materials. The editorial department will automatically select based on their annual assessment.
';
// }
$maidata['email'] = $v['email'];
$maidata['title'] = $title;
$maidata['content'] = $dd;
Queue::push('app\api\job\mail@propa', $maidata, "mail");
}
$re['list'] = $list;
return jsonSuccess($re);
}
/**
* @title 获取数据库
* @description 获取数据库
* @author wangjinlei
* @url /master/Datebase/getDbs
* @method POST
*
* @return dblist:数据库列表array#
*/
public function getDbs()
{
$list = $this->db_obj->where('state', 0)->select();
$re['dblist'] = $list;
return jsonSuccess($re);
}
/**
* @title 获取数据库主页
* @description 获取数据库主页
* @author wangjinlei
* @url /master/Datebase/getDbMain
* @method POST
*
* @param name:db_id type:int require:1 desc:数据库id
* @param name:journal_id type:int require:1 desc:期刊id
*
* @return dbInfo:数据库信息#
*/
public function getDbMain()
{
$data = $this->request->post();
$info = $this->db_obj->where('db_id', $data['db_id'])->find();
//获取数据库完成情况(预留)
$re['dbInfo'] = $info;
return jsonSuccess($re);
}
/**
* @title 增加数据库资料
* @description 增加数据库资料
* @author wangjinlei
* @url /master/Datebase/addData
* @method POST
*
* @param name:db_id type:int require:1 desc:数据库id
* @param name:name type:string require:1 desc:资料名称
* @param name:url type:string require:1 desc:资料地址
*/
public function addData()
{
$data = $this->request->post();
$insert['db_id'] = $data['db_id'];
$insert['title'] = $data['name'];
$insert['url'] = $data['url'];
$insert['ctime'] = time();
$this->db_data_obj->insert($insert);
return jsonSuccess([]);
}
/**
* @title 删除数据库资料
* @description 删除数据库资料
* @author wangjinlei
* @url /master/Datebase/delData
* @method POST
*
* @param name:db_data_id type:int require:1 desc:数据库资料id
*/
public function delData()
{
$data = $this->request->post();
$this->db_data_obj->where('db_data_id', $data['db_data_id'])->update(['state' => 1]);
return jsonSuccess([]);
}
/**
* @title 获取数据库资料
* @description 获取数据库资料
* @author wangjinlei
* @url /master/Datebase/getDatas
* @method POST
*
* @param name:db_id type:int require:1 desc:数据库id
* @param name:pageIndex type:int require:1 desc:当前页码数
* @param name:pageSize type:int require:1 desc:单页数据条数
*
* @return dbinfo:数据库信息#
* @return count:总数据数
* @return dataList:array#
*/
public function getDatas()
{
$data = $this->request->post();
$db_info = $this->db_obj->where('db_id', $data['db_id'])->find();
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
$list = $this->db_data_obj->where('db_id', $data['db_id'])->where('state', 0)->limit($limit_start, $data['pageSize'])->select();
$count = $this->db_data_obj->where('db_id', $data['db_id'])->count();
$re['dbinfo'] = $db_info;
$re['dataList'] = $list;
$re['count'] = $count;
return jsonSuccess($re);
}
/**
* @title 图片上传
* @description 图片上传
* @author wangjinlei
* @url /master/Datebase/up_file
* @method POST
*
* @param name:name type:string require:1 default:dbdata desc:文件域名称
*
* @return upurl:图片地址
*/
public function up_file()
{
$file = request()->file('dbdata');
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'dbdata');
if ($info) {
return json(['code' => 0, 'msg' => 'success', 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
/**
* @title 提交数据库
* @description 提交数据库
* @author wangjinlei
* @url /master/Datebase/dataPush
* @method POST
*
* @param name:journal_stage_id type:int require:1 desc:分期id
*
*/
public function dataPush()
{
$data = $this->request->post();
$stage_info = $this->journal_stage_obj->where("journal_stage_id", $data["journal_stage_id"])->find();
$this->createEmailFile($data["journal_stage_id"]);
$journal_info = $this->journal_obj->where("journal_id", $stage_info["journal_id"])->find();
$zipfile = ROOT_PATH . "public/dataFile/" . $data["journal_stage_id"] . '/' . $data["journal_stage_id"] . '.zip';
$tt = "Dear Database,
";
$tt .= "Please find the PDF files in attachment of published issue (Vol. " . $stage_info['stage_vol'] . ", No." . $stage_info['stage_no'] . ") of " . $journal_info['title'] . ".
";
$tt .= "Yours Sincerely
";
$tt .= "Dan Chen
";
$tt .= "Manager
";
$tt .= "TMR Publishing Group | Editorial Office | New Zealand
";
$tt .= "Telephone: +64 02108293806
";
$tt .= "Email: publisher@tmrjournals.com
";
$tt .= "Website:www.tmrjournals.com";
$elist = [];
$elist[] = "jgatelicensing@informaticsglobal.com";
// $elist[] = "3601240974@qq.com";
if ($journal_info["journal_id"] == 1) {
$elist[] = "958518573@qq.com";
$elist[] = "swyy2@wanfangdata.com.cn";
}
$elist[] = "3097953993@qq.com";
$elist[] = "849192806@qq.com"; //皮皮
$elist[] = "751475802@qq.com"; //我
$elist[] = "ELD@dia.govt.nz";
foreach ($elist as $v) {
$cdata['email'] = $v;
$cdata['title'] = "Data submitted-TMR Publishing Group";
$cdata["fromname"] = "Data submitted-TMR Publishing Group";
$cdata["content"] = $tt;
$cdata["temail"] = $journal_info['email'];
$cdata["tpassword"] = $journal_info['epassword'];
$cdata["fj"] = $zipfile;
Queue::push('app\api\job\mail@puchAndFJ', $cdata, "mail");
// sendEmail_data($v, "Data submitted-TMR Publishing Group", "Data submitted-TMR Publishing Group", $tt, $journal_info['email'], $journal_info['epassword'],$zipfile);
}
//发送sftp
$this->bf_db_push($data["journal_stage_id"]);
// 发送ftp
$this->createFtpFileInfo($data["journal_stage_id"]);
return jsonSuccess([]);
}
public function Mycreate(){
$data = $this->request->post();
$url = "http://ts.tmrjournals.com/api/dataApi/createTemplate";
$stage_info = $this->journal_stage_obj->where("journal_stage_id", $data['journal_stage_id'])->find();
$re['issue'] = $stage_info['issue_date'] . ", Volume " . $stage_info['stage_vol'] . " Issue " . $stage_info["stage_no"];
$adate = [];
$alist = $this->article_obj->where("journal_stage_id", $data['journal_stage_id'])->where("state", 0)->order("sort")->select();
// $alist = $this->article_obj->where("journal_stage_id", $data['journal_stage_id'])->where("state", 0)->select();
foreach ($alist as $k => $v) {
$cache["type"] = $v["type"];
$cache["no"] = $v["npp"];
$cache["title"] = $v["title"];
$cache["author"] = $this->getAuthor($v);
$adate[] = $cache;
}
$re["date_list"] = json_encode($adate);
$res = myPost($url, $re);
$r = object_to_array(json_decode($res));
$file = $r['data']["file"];//创建目录加压缩操作
$base_dir = ROOT_PATH . "public/dataFile/" . $stage_info["journal_stage_id"];
if (!is_dir($base_dir)) {
@mkdir($base_dir);
}
copy('http://ts.tmrjournals.com/upload/' . $file, $base_dir . '/' . $stage_info["journal_stage_id"] . ".docx");
echo 'success !';
}
private function createEmailFile($journal_stage_id)
{
$url = "http://ts.tmrjournals.com/api/dataApi/createTemplate";
//查找分期信息
$stage_info = $this->journal_stage_obj->where("journal_stage_id", $journal_stage_id)->find();
$journal_info = $this->journal_obj->where("journal_id", $stage_info["journal_id"])->find();
$re['issue'] = $stage_info['issue_date'] . ", Volume " . $stage_info['stage_vol'] . " Issue " . $stage_info["stage_no"];
$adate = [];
$alist = $this->article_obj->where("journal_stage_id", $journal_stage_id)->where("state", 0)->orderRaw("npp + 0")->select();
foreach ($alist as $k => $v) {
$cache["type"] = $v["type"];
$cache["no"] = $v["npp"];
$cache["title"] = $v["title"];
$cache["author"] = $this->getAuthor($v);
$adate[] = $cache;
}
$re["date_list"] = json_encode($adate);
$res = myPost($url, $re);
$r = object_to_array(json_decode($res));
$file = $r['data']["file"];
//创建目录加压缩操作
$base_dir = ROOT_PATH . "public/dataFile/" . $stage_info["journal_stage_id"];
if (!is_dir($base_dir)) {
@mkdir($base_dir);
}
$zip = new \ZipArchive;
$zip->open($base_dir . '/' . $stage_info["journal_stage_id"] . '.zip', \ZipArchive::CREATE);
copy('http://ts.tmrjournals.com/upload/' . $file, $base_dir . '/' . $stage_info["journal_stage_id"] . ".docx");
$zip->addFile($base_dir . '/' . $stage_info["journal_stage_id"] . ".docx", "Contents.docx");
foreach ($alist as $k => $v) {
// echo "https://www.tmrjournals.com/public/articlePDF/" . $v['file_pdf'];
// copy("https://www.tmrjournals.com/public/articlePDF/" . $v['file_pdf'], $base_dir . '/' . $v["npp"] . ".pdf");
copy("http://journalapi.tmrjournals.com/public/articlePDF/" . $v['file_pdf'], $base_dir . '/' . $v["npp"] . ".pdf");
$zip->addFile($base_dir . '/' . $v["npp"] . ".pdf", $v["npp"] . ".pdf");
}
//添加封面图片
copy("http://journalapi.tmrjournals.com/public/" . $stage_info["stage_icon"], $base_dir . "/journal.jpg");
$zip->addFile($base_dir . "/journal.jpg", "journal.jpg");
$zip->close();
}
public function puttt(){
$this->createFtpFileInfo(481);
}
private function createFtpFileInfo($journal_stage_id)
{
//查找分期信息
$stage_info = $this->journal_stage_obj->where("journal_stage_id", $journal_stage_id)->find();
$journalInfo = $this->journal_obj->where('journal_id', $stage_info['journal_id'])->find();
//获取分期文章
$articles = $this->article_obj->where(['journal_stage_id' => $journal_stage_id, 'state' => 0])->field('title as articleTitle,abbr as author,pub_date as date,keywords as keyWords,doi,abstract,file_pdf as pdf,article_id,journal_id')->select();
foreach ($articles as $k => $v) {
$articles[$k]['abstract'] = strip_tags($v['abstract']);
$articles[$k]['journalTitle'] = $journalInfo['title'];
$articles[$k]['issn'] = $journalInfo['issn'];
$articles[$k]['vol'] = $stage_info['stage_vol'];
$articles[$k]['issue'] = $stage_info['stage_no'];
$articles[$k]['pdf'] = 'https://www.tmrjournals.com/public/articlePDF/' . $v['pdf'];
$articles[$k]['linkToAbstract'] = 'https://www.tmrjournals.com/article.html?J_num=' . $v['journal_id'] . '&a_id=' . $v['article_id'];
$articles[$k]['publisher'] = 'TMR publishing group';
$articles[$k]['reference'] = '';
$articles[$k]['eissn'] = '';
}
$baseDir = ROOT_PATH . 'public' . DS . 'ftpFile' . DS;
$outfileTitle = $journalInfo['title'] . "-" . $stage_info['stage_vol'] . "卷" . $stage_info['stage_no'] . "期";
// 生成zip
$res = $this->createZip($articles, $baseDir, $outfileTitle);
$resJosn = json_decode($res, true);
// zip生成成功后发送ftp
if ($resJosn['code'] == 0) {
$url = $baseDir . $outfileTitle . ".zip";
// 发送ftp
$this->sendFtp($url, $outfileTitle);
}
}
private function getAuthor($article)
{
$where['article_id'] = $article['article_id'];
$where['state'] = 0;
$list = $this->article_author_obj->where($where)->select();
$frag = '';
foreach ($list as $k => $v) {
$frag = $frag == '' ? '' . $v['author_name'] : $frag . ', ' . $v['author_name'];
}
return $frag;
}
// 先生成excel - 再压缩zip - 删除excel
private function createZip($articles, $baseDir, $outfileTitle)
{
Vendor('PHPExcel.PHPExcel'); //调用类库,路径是基于vendor文件夹的
Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
$objExcel = new \PHPExcel();
//set document Property
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objActSheet = $objExcel->getActiveSheet();
$key = ord("A");
$letter = explode(',', "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O");
$arrHeader = array('Article Title', 'Author', 'Publishing Date', 'Key Words', 'Journal Title', 'ISSN', 'EISSN', 'Volume', 'Issue', 'Link to Full-Text Articles (PDF)', 'Abstract', 'DOI', 'Link to Abstract', 'Publisher', 'Reference');
//填充表头信息
$lenth = count($arrHeader);
for ($i = 0; $i < $lenth; $i++) {
$objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
// 设置表头高度
$objActSheet->getRowDimension('1')->setRowHeight(25);
};
//填充表格信息
foreach ($articles as $k => $v) {
$k += 2;
$objActSheet->setCellValue('A' . $k, $v['articleTitle']);
$objActSheet->setCellValue('B' . $k, $v['author']);
$objActSheet->setCellValue('C' . $k, $v['date']);
$objActSheet->setCellValue('D' . $k, $v['keyWords']);
$objActSheet->setCellValue('E' . $k, $v['journalTitle']);
$objActSheet->setCellValue('F' . $k, $v['issn']);
$objActSheet->setCellValue('G' . $k, $v['eissn']);
$objActSheet->setCellValue('H' . $k, $v['vol']);
$objActSheet->setCellValue('I' . $k, $v['issue']);
$objActSheet->setCellValue('J' . $k, $v['pdf']);
$objActSheet->setCellValue('K' . $k, $v['abstract']);
$objActSheet->setCellValue('L' . $k, $v['doi']);
$objActSheet->setCellValue('M' . $k, $v['linkToAbstract']);
$objActSheet->setCellValue('N' . $k, $v['publisher']);
$objActSheet->setCellValue('O' . $k, $v['reference']);
// 表格高度
$objActSheet->getRowDimension($k)->setRowHeight(25);
}
$width = array(10, 15, 20, 25, 30);
//设置表格的宽度
$objActSheet->getColumnDimension('A')->setWidth($width[4]);
$objActSheet->getColumnDimension('B')->setWidth($width[2]);
$objActSheet->getColumnDimension('C')->setWidth($width[1]);
$objActSheet->getColumnDimension('D')->setWidth($width[4]);
$objActSheet->getColumnDimension('E')->setWidth($width[4]);
$objActSheet->getColumnDimension('F')->setWidth($width[2]);
$objActSheet->getColumnDimension('G')->setWidth($width[3]);
$objActSheet->getColumnDimension('H')->setWidth($width[1]);
$objActSheet->getColumnDimension('I')->setWidth($width[1]);
$objActSheet->getColumnDimension('J')->setWidth($width[4]);
$objActSheet->getColumnDimension('K')->setWidth($width[3]);
$objActSheet->getColumnDimension('L')->setWidth($width[3]);
$objActSheet->getColumnDimension('M')->setWidth($width[4]);
$objActSheet->getColumnDimension('N')->setWidth($width[2]);
$objActSheet->getColumnDimension('O')->setWidth($width[1]);
if (!is_dir($baseDir)) {
@mkdir($baseDir);
}
$res = $objWriter->save($baseDir . $outfileTitle . ".xlsx");
// 生成zip
$path = $baseDir . $outfileTitle . ".xlsx";
$fileName = $outfileTitle . ".zip";
$zip = new \ZipArchive;
$zip->open($baseDir . $fileName, \ZipArchive::CREATE);
$zip->addFile($path, basename($path));
$zip->close();
unlink($baseDir . $outfileTitle . ".xlsx");
if (!file_exists($baseDir . $fileName)) {
return json_encode(['code' => 1, 'msg' => '无法找到文件']);
}
return json_encode(['code' => 0, 'msg' => '成功', 'data' => $baseDir . $fileName]);
}
public function phpinfo()
{
phpinfo();
}
// 连接ftp
private function sendFtp($url, $title)
{
$ftp = [
'server' => 'FTP.cnki.net',
'user' => 'glo616cnki',
'pass' => 'glo616cnki'
];
$con = ftp_connect($ftp['server']);
$res = ftp_login($con, $ftp['user'], $ftp['pass']);
if (!$res) { //连接失败
exit('连接失败');
}
$name = iconv("UTF-8", "GBK", $title . '.zip');
ftp_pasv($con, true);
$data = ftp_put($con, '/' . $name, $url, FTP_BINARY);
if (!$data) { // 上传失败
exit('上传失败');
}
ftp_close($con);
}
}