大更新,1投稿系统参考文献的类型增加功能,,,2官网数据库功能
This commit is contained in:
106
application/master/service/push/EmailDataPusher.php
Normal file
106
application/master/service/push/EmailDataPusher.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace app\master\service\push;
|
||||
|
||||
use think\Queue;
|
||||
|
||||
/**
|
||||
* 邮件送交推送器(通用数据库 / 万方等)
|
||||
* 打包整期 docx + PDF + 封面 zip,作为附件发邮件给数据库收件人。
|
||||
* 逻辑迁移自 Datebase::dataPush 的邮件部分 + createEmailFile。
|
||||
*/
|
||||
class EmailDataPusher extends AbstractPusher
|
||||
{
|
||||
public function code()
|
||||
{
|
||||
return 'email_data';
|
||||
}
|
||||
|
||||
public function label()
|
||||
{
|
||||
return '数据库邮件送交';
|
||||
}
|
||||
|
||||
public function pushStage($journal_stage_id, array $options = [])
|
||||
{
|
||||
$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();
|
||||
|
||||
// 幂等构建整期附件 zip
|
||||
$zipfile = ROOT_PATH . "public/dataFile/" . $journal_stage_id . '/' . $journal_stage_id . '.zip';
|
||||
if (!file_exists($zipfile)) {
|
||||
$this->buildIssueZip($journal_stage_id, $stage_info, $journal_info);
|
||||
}
|
||||
|
||||
// 收件人:渠道配置优先,否则用默认通用收件人
|
||||
$recipients = !empty($options['recipients']) ? $options['recipients'] : $this->conf('data_recipients', []);
|
||||
if (empty($recipients)) {
|
||||
return PushResult::fail('未配置收件人');
|
||||
}
|
||||
|
||||
$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";
|
||||
|
||||
foreach ($recipients 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");
|
||||
}
|
||||
|
||||
return PushResult::success('已向 ' . count($recipients) . ' 个收件人加入邮件队列');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建整期 zip(Contents.docx + 各文章 PDF + 封面)
|
||||
*/
|
||||
private function buildIssueZip($journal_stage_id, $stage_info, $journal_info)
|
||||
{
|
||||
$ts_base_url = $this->conf('ts_base_url');
|
||||
$pdfBase = $this->conf('article_pdf');
|
||||
$publicBase = $this->conf('public_base');
|
||||
|
||||
$url = $ts_base_url . "api/dataApi/createTemplate";
|
||||
$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 $v) {
|
||||
$cache["type"] = $v["type"];
|
||||
$cache["no"] = $v["npp"];
|
||||
$cache["title"] = $v["title"];
|
||||
$cache["author"] = $this->getAuthorNames($v['article_id']);
|
||||
$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, 0777, true);
|
||||
}
|
||||
$zip = new \ZipArchive;
|
||||
$zip->open($base_dir . '/' . $stage_info["journal_stage_id"] . '.zip', \ZipArchive::CREATE);
|
||||
copy($ts_base_url . '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 $v) {
|
||||
copy($pdfBase . $v['file_pdf'], $base_dir . '/' . $v["npp"] . ".pdf");
|
||||
$zip->addFile($base_dir . '/' . $v["npp"] . ".pdf", $v["npp"] . ".pdf");
|
||||
}
|
||||
copy($publicBase . $stage_info["stage_icon"], $base_dir . "/journal.jpg");
|
||||
$zip->addFile($base_dir . "/journal.jpg", "journal.jpg");
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user