1
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\master\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Queue;
|
||||
use PHPExcel;
|
||||
use sftp\Sftp;
|
||||
|
||||
/**
|
||||
* @title 数据库接口
|
||||
* @description 数据库接口
|
||||
* @group 数据库接口
|
||||
*/
|
||||
class Datebase extends Controller{
|
||||
|
||||
class Datebase extends Controller
|
||||
{
|
||||
|
||||
protected $admin_obj = '';
|
||||
protected $journal_obj = '';
|
||||
protected $article_obj = '';
|
||||
@@ -28,7 +32,8 @@ class Datebase extends Controller{
|
||||
protected $db_obj = '';
|
||||
protected $db_data_obj = '';
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
public function __construct(\think\Request $request = null)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->admin_obj = Db::name('admin');
|
||||
$this->journal_obj = Db::name('journal');
|
||||
@@ -47,7 +52,7 @@ class Datebase extends Controller{
|
||||
$this->db_obj = Db::name('db');
|
||||
$this->db_data_obj = Db::name('db_data');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 增加数据库
|
||||
* @description 增加数据库
|
||||
@@ -58,16 +63,17 @@ class Datebase extends Controller{
|
||||
* @param name:name type:string require:1 desc:数据库名字
|
||||
* @param name:intro type:string require:1 desc:简介
|
||||
*/
|
||||
public function addDb(){
|
||||
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 删除数据库
|
||||
@@ -77,19 +83,128 @@ class Datebase extends Controller{
|
||||
*
|
||||
* @param name:db_id type:int require:1 desc:数据库id
|
||||
*/
|
||||
public function delDb(){
|
||||
public function delDb()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$this->db_obj->where('db_id',$data['db_id'])->update(['state'=>1]);
|
||||
$this->db_obj->where('db_id', $data['db_id'])->update(['state' => 1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份数据推送至sftp
|
||||
*/
|
||||
public function bf_db_push(){
|
||||
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();
|
||||
$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, $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']);
|
||||
$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, '');
|
||||
}
|
||||
|
||||
//整理分期
|
||||
if (strpos(trim($v['npp']), '-') == false) {
|
||||
$objActSheet->setCellValue('L' . $k, '');
|
||||
$objActSheet->setCellValue('M' . $k, '');
|
||||
}else{
|
||||
$cc = explode('-',trim($v['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]);
|
||||
|
||||
// $baseDir = ROOT_PATH . 'public' . DS . 'davExcel' . DS ;
|
||||
// if (!is_dir($baseDir)) {
|
||||
// @mkdir($baseDir);
|
||||
// }
|
||||
$outfileTitle = $stage_info['journal_stage_id']."dav";
|
||||
$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 . $outfileTitle . ".xlsx"]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 获取数据库
|
||||
* @description 获取数据库
|
||||
@@ -99,13 +214,14 @@ class Datebase extends Controller{
|
||||
*
|
||||
* @return dblist:数据库列表array#
|
||||
*/
|
||||
public function getDbs(){
|
||||
$list = $this->db_obj->where('state',0)->select();
|
||||
|
||||
public function getDbs()
|
||||
{
|
||||
$list = $this->db_obj->where('state', 0)->select();
|
||||
|
||||
$re['dblist'] = $list;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 获取数据库主页
|
||||
* @description 获取数据库主页
|
||||
@@ -118,16 +234,17 @@ class Datebase extends Controller{
|
||||
*
|
||||
* @return dbInfo:数据库信息#
|
||||
*/
|
||||
public function getDbMain(){
|
||||
public function getDbMain()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$info = $this->db_obj->where('db_id',$data['db_id'])->find();
|
||||
|
||||
$info = $this->db_obj->where('db_id', $data['db_id'])->find();
|
||||
|
||||
//获取数据库完成情况(预留)
|
||||
|
||||
|
||||
$re['dbInfo'] = $info;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 增加数据库资料
|
||||
* @description 增加数据库资料
|
||||
@@ -139,7 +256,8 @@ class Datebase extends Controller{
|
||||
* @param name:name type:string require:1 desc:资料名称
|
||||
* @param name:url type:string require:1 desc:资料地址
|
||||
*/
|
||||
public function addData(){
|
||||
public function addData()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$insert['db_id'] = $data['db_id'];
|
||||
$insert['title'] = $data['name'];
|
||||
@@ -148,7 +266,7 @@ class Datebase extends Controller{
|
||||
$this->db_data_obj->insert($insert);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 删除数据库资料
|
||||
* @description 删除数据库资料
|
||||
@@ -158,12 +276,13 @@ class Datebase extends Controller{
|
||||
*
|
||||
* @param name:db_data_id type:int require:1 desc:数据库资料id
|
||||
*/
|
||||
public function delData(){
|
||||
public function delData()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$this->db_data_obj->where('db_data_id',$data['db_data_id'])->update(['state'=>1]);
|
||||
$this->db_data_obj->where('db_data_id', $data['db_data_id'])->update(['state' => 1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 获取数据库资料
|
||||
* @description 获取数据库资料
|
||||
@@ -179,20 +298,21 @@ class Datebase extends Controller{
|
||||
* @return count:总数据数
|
||||
* @return dataList:array#
|
||||
*/
|
||||
public function getDatas(){
|
||||
public function getDatas()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
|
||||
$db_info = $this->db_obj->where('db_id',$data['db_id'])->find();
|
||||
|
||||
$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();
|
||||
|
||||
$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 图片上传
|
||||
@@ -204,18 +324,19 @@ class Datebase extends Controller{
|
||||
*
|
||||
* @return upurl:图片地址
|
||||
*/
|
||||
public function up_file() {
|
||||
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())]);
|
||||
return json(['code' => 0, 'msg' => 'success', 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
||||
} else {
|
||||
return json(['code' => 1, 'msg' => $file->getError()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title 提交数据库
|
||||
* @description 提交数据库
|
||||
@@ -226,18 +347,18 @@ class Datebase extends Controller{
|
||||
* @param name:journal_stage_id type:int require:1 desc:分期id
|
||||
*
|
||||
*/
|
||||
public function dataPush(){
|
||||
public function dataPush()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
// $data["journal_stage_id"] = 305;
|
||||
$stage_info = $this->journal_stage_obj->where("journal_stage_id",$data["journal_stage_id"])->find();
|
||||
$stage_info = $this->journal_stage_obj->where("journal_stage_id", $data["journal_stage_id"])->find();
|
||||
$this->createEmailFile($data["journal_stage_id"]);
|
||||
// 发送ftp
|
||||
$this->createFtpFileInfo($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';
|
||||
$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,<br><br>";
|
||||
$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'].".<br><br>";
|
||||
$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'] . ".<br><br>";
|
||||
$tt .= "Yours Sincerely<br>";
|
||||
$tt .= "Dan Chen<br>";
|
||||
$tt .= "Manager<br>";
|
||||
@@ -249,16 +370,16 @@ class Datebase extends Controller{
|
||||
$elist = [];
|
||||
$elist[] = "jgatelicensing@informaticsglobal.com";
|
||||
$elist[] = "3601240974@qq.com";
|
||||
if($journal_info["journal_id"]==1){
|
||||
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[] = "849192806@qq.com"; //皮皮
|
||||
$elist[] = "751475802@qq.com"; //我
|
||||
$elist[] = "ELD@dia.govt.nz";
|
||||
|
||||
foreach ($elist as $v){
|
||||
foreach ($elist as $v) {
|
||||
$cdata['email'] = $v;
|
||||
$cdata['title'] = "Data submitted-TMR Publishing Group";
|
||||
$cdata["fromname"] = "Data submitted-TMR Publishing Group";
|
||||
@@ -267,31 +388,24 @@ class Datebase extends Controller{
|
||||
$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);
|
||||
// sendEmail_data($v, "Data submitted-TMR Publishing Group", "Data submitted-TMR Publishing Group", $tt, $journal_info['email'], $journal_info['epassword'],$zipfile);
|
||||
}
|
||||
|
||||
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
public function mycreat(){
|
||||
$data = $this->request->post();
|
||||
$this->createEmailFile($data['stage_id']);
|
||||
echo 'ok';
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function createEmailFile($journal_stage_id){
|
||||
|
||||
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"];
|
||||
$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)->order("npp")->select();
|
||||
foreach ($alist as $k => $v){
|
||||
$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["npp"] = $v["npp"];
|
||||
$cache["no"] = $v["npp"];
|
||||
$cache["title"] = $v["title"];
|
||||
$cache["author"] = $this->getAuthor($v);
|
||||
$adate[] = $cache;
|
||||
@@ -299,69 +413,67 @@ class Datebase extends Controller{
|
||||
$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)){
|
||||
$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){
|
||||
copy("https://www.tmrjournals.com/public/articlePDF/".$v['file_pdf'],$base_dir.'/'.$v["npp"].".pdf");
|
||||
$zip->addFile($base_dir.'/'.$v["npp"].".pdf",$v["npp"].".pdf");
|
||||
$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) {
|
||||
copy("https://www.tmrjournals.com/public/articlePDF/" . $v['file_pdf'], $base_dir . '/' . $v["npp"] . ".pdf");
|
||||
$zip->addFile($base_dir . '/' . $v["npp"] . ".pdf", $v["npp"] . ".pdf");
|
||||
}
|
||||
//添加封面图片
|
||||
copy("https://www.tmrjournals.com/public/journalicon/".$journal_info["icon"],$base_dir."/journal.jpg");
|
||||
$zip->addFile($base_dir."/journal.jpg","journal.jpg");
|
||||
copy("https://www.tmrjournals.com/public/journalicon/" . $journal_info["icon"], $base_dir . "/journal.jpg");
|
||||
$zip->addFile($base_dir . "/journal.jpg", "journal.jpg");
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function createFtpFileInfo($journal_stage_id){
|
||||
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();
|
||||
$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();
|
||||
$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){
|
||||
foreach ($articles as $k => $v) {
|
||||
$articles[$k]['abstract'] = strip_tags($v['abstract']);
|
||||
$articles[$k]['journalTitle'] = $journalInfo['title'];
|
||||
$articles[$k]['issn'] = $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.cn/public/articlePDF/'.$v['pdf'];
|
||||
$articles[$k]['linkToAbstract'] = 'https://www.tmrjournals.cn/article.html?J_num='.$v['journal_id'].'&a_id='.$v['article_id'];
|
||||
$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']."期";
|
||||
$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);
|
||||
$res = $this->createZip($articles, $baseDir, $outfileTitle);
|
||||
|
||||
$resJosn = json_decode($res,true);
|
||||
$resJosn = json_decode($res, true);
|
||||
|
||||
// zip生成成功后发送ftp
|
||||
if($resJosn['code'] == 0){
|
||||
$url = $baseDir.$outfileTitle.".zip";
|
||||
// 发送ftp
|
||||
$this->sendFtp($url,$outfileTitle);
|
||||
if ($resJosn['code'] == 0) {
|
||||
$url = $baseDir . $outfileTitle . ".zip";
|
||||
// 发送ftp
|
||||
$this->sendFtp($url, $outfileTitle);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getAuthor($article) {
|
||||
private function getAuthor($article)
|
||||
{
|
||||
$where['article_id'] = $article['article_id'];
|
||||
$where['state'] = 0;
|
||||
$list = $this->article_author_obj->where($where)->select();
|
||||
@@ -371,11 +483,12 @@ class Datebase extends Controller{
|
||||
}
|
||||
return $frag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 先生成excel - 再压缩zip - 删除excel
|
||||
private function createZip($articles,$baseDir,$outfileTitle){
|
||||
Vendor('PHPExcel.PHPExcel');//调用类库,路径是基于vendor文件夹的
|
||||
private function createZip($articles, $baseDir, $outfileTitle)
|
||||
{
|
||||
Vendor('PHPExcel.PHPExcel'); //调用类库,路径是基于vendor文件夹的
|
||||
Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
|
||||
Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
|
||||
$objExcel = new \PHPExcel();
|
||||
@@ -384,37 +497,37 @@ class Datebase extends Controller{
|
||||
|
||||
$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');
|
||||
$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]");
|
||||
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']);
|
||||
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);
|
||||
$width = array(10, 15, 20, 25, 30);
|
||||
//设置表格的宽度
|
||||
$objActSheet->getColumnDimension('A')->setWidth($width[4]);
|
||||
$objActSheet->getColumnDimension('B')->setWidth($width[2]);
|
||||
@@ -431,47 +544,59 @@ class Datebase extends Controller{
|
||||
$objActSheet->getColumnDimension('M')->setWidth($width[4]);
|
||||
$objActSheet->getColumnDimension('N')->setWidth($width[2]);
|
||||
$objActSheet->getColumnDimension('O')->setWidth($width[1]);
|
||||
if(!is_dir($baseDir)){
|
||||
if (!is_dir($baseDir)) {
|
||||
@mkdir($baseDir);
|
||||
}
|
||||
$res = $objWriter->save($baseDir.$outfileTitle.".xlsx");
|
||||
$res = $objWriter->save($baseDir . $outfileTitle . ".xlsx");
|
||||
|
||||
// 生成zip
|
||||
$path = $baseDir.$outfileTitle.".xlsx";
|
||||
$fileName = $outfileTitle.".zip";
|
||||
$path = $baseDir . $outfileTitle . ".xlsx";
|
||||
$fileName = $outfileTitle . ".zip";
|
||||
$zip = new \ZipArchive;
|
||||
$zip->open($baseDir.$fileName,\ZipArchive::CREATE);
|
||||
$zip->addFile($path,basename($path));
|
||||
$zip->open($baseDir . $fileName, \ZipArchive::CREATE);
|
||||
$zip->addFile($path, basename($path));
|
||||
$zip->close();
|
||||
unlink($baseDir.$outfileTitle.".xlsx");
|
||||
unlink($baseDir . $outfileTitle . ".xlsx");
|
||||
|
||||
if (!file_exists($baseDir.$fileName)) {
|
||||
return json_encode(['code'=>1,'msg'=>'无法找到文件']);
|
||||
if (!file_exists($baseDir . $fileName)) {
|
||||
return json_encode(['code' => 1, 'msg' => '无法找到文件']);
|
||||
}
|
||||
return json_encode(['code'=>0,'msg'=>'成功','data'=>$baseDir.$fileName]);
|
||||
return json_encode(['code' => 0, 'msg' => '成功', 'data' => $baseDir . $fileName]);
|
||||
}
|
||||
|
||||
public function phpinfo(){
|
||||
|
||||
phpinfo();
|
||||
}
|
||||
|
||||
public function testsftp(){
|
||||
$config = [];
|
||||
$config['host'] = 'sftp://ftp.portico.org';
|
||||
$config['port'] = 22;
|
||||
$config['username'] = "TMR";
|
||||
$config['password'] = "h6EHD8";
|
||||
$sftp_obj = new Sftp($config);
|
||||
var_dump($sftp_obj);
|
||||
}
|
||||
|
||||
// 连接ftp
|
||||
private function sendFtp($url,$title){
|
||||
$ftp=[
|
||||
'server'=>'FTP.cnki.net',
|
||||
'user'=>'glo616cnki',
|
||||
'pass'=>'glo616cnki'
|
||||
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){ //连接失败
|
||||
if (!$res) { //连接失败
|
||||
exit('连接失败');
|
||||
}
|
||||
$name = iconv("UTF-8","GBK",$title.'.zip');
|
||||
$data = ftp_put($con,'/'.$name,$url,FTP_BINARY);
|
||||
if(!$data){ // 上传失败
|
||||
$name = iconv("UTF-8", "GBK", $title . '.zip');
|
||||
$data = ftp_put($con, '/' . $name, $url, FTP_BINARY);
|
||||
if (!$data) { // 上传失败
|
||||
exit('上传失败');
|
||||
}
|
||||
ftp_close($con);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user