328 lines
12 KiB
PHP
328 lines
12 KiB
PHP
<?php
|
||
namespace app\master\controller;
|
||
use think\Controller;
|
||
use think\Db;
|
||
use think\Queue;
|
||
/**
|
||
* @title 数据库接口
|
||
* @description 数据库接口
|
||
* @group 数据库接口
|
||
*/
|
||
class Datebase extends Controller{
|
||
|
||
protected $admin_obj = '';
|
||
protected $journal_obj = '';
|
||
protected $article_obj = '';
|
||
protected $journal_topic_obj = '';
|
||
protected $article_author_obj = '';
|
||
protected $journal_stage_obj = '';
|
||
protected $journal_line_obj = '';
|
||
protected $journal_notices_obj = '';
|
||
protected $journal_abs_obj = '';
|
||
protected $article_to_topic_obj = '';
|
||
protected $article_to_line_obj = '';
|
||
protected $journal_cfp_obj = '';
|
||
protected $journal_paper_obj = '';
|
||
protected $journal_paper_art_obj = '';
|
||
protected $db_obj = '';
|
||
protected $db_data_obj = '';
|
||
|
||
public function __construct(\think\Request $request = null) {
|
||
parent::__construct($request);
|
||
$this->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([]);
|
||
}
|
||
|
||
/**
|
||
* @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();
|
||
// $data["journal_stage_id"] = 294;
|
||
$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,<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>";
|
||
$tt .= "TMR Publishing Group | Editorial Office | New Zealand<br>";
|
||
$tt .= "Telephone: +64 02108293806<br>";
|
||
$tt .= "Email: publisher@tmrjournals.com<br>";
|
||
$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";//我
|
||
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);
|
||
}
|
||
|
||
return jsonSuccess([]);
|
||
|
||
}
|
||
|
||
|
||
|
||
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)->order("npp")->select();
|
||
foreach ($alist as $k => $v){
|
||
$cache["type"] = $v["type"];
|
||
$cache["npp"] = $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){
|
||
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");
|
||
$zip->close();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|