This commit is contained in:
wangjinlei
2021-06-15 10:33:18 +08:00
parent 08ea33979d
commit 936978d35c
5 changed files with 335 additions and 12 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace app\api\job;
use think\queue\Job;
class img {
//put your code here
public function fire(Job $job, $data) {
// $this->tttt($data['name']);
$this->imgCL($data['name'], $data['course']);
$job->delete();
}
// public function tttt($name) {
// file_put_contents('d:/1.txt',$name.'--' , FILE_APPEND);
// }
/**
* 处理图片主方法
*/
public function imgCL($name, $course) {
$max = $this->getmax($course);
$lim = [];
if (preg_match("/^[\x7f-\xff]+$/", $name) && strlen($name) == 9) {
$lim = [640, 890];
} else if (preg_match("/^[\x7f-\xff]+$/", $name) && strlen($name) == 6) {
$lim = [670, 890];
} else {
$left = (730 - ((35 * strlen($name)) / 2));
$lim = [$left, 890];
}
$template = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'template.png';
$ziti = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'siyuan.ttf';
$image = \think\Image::open($template);
$image->text($name, $ziti, 50, '#000000', $lim)
->text('NO.ZYMR' . (20210619001 + $max), $ziti, 25, '#000000', [573, 650])
->save(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $course . DS . (1 + $max) . '_' . $name . '.png');
}
/**
* 获取当前证书流水号最大值
*/
private function getmax($course) {
$dir = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img/' . $course . DS;
$res = scandir($dir);
$big = 0;
foreach ($res as $v) {
if ($v == '.' || $v == '..') {
continue;
}
$cac = intval(substr($v, 0, stripos($v, '_')));
if ($cac > $big) {
$big = $cac;
}
}
return $big;
}
}

View File

@@ -10,20 +10,22 @@ class mail {
public function fire(Job $job, $data) {
$res = $this->send($data);
if($res){
file_put_contents('/usr/local/email.txt', 'log_time:'.date('Y-m-d H:i:s').' success:to '.$data['email'].PHP_EOL, FILE_APPEND);
$job->delete();
}else{
if($job->attempts()>3){
file_put_contents('/usr/local/email.txt', 'log_time:'.date('Y-m-d H:i:s').' error:to '.$data['email'].PHP_EOL, FILE_APPEND);
$job->delete();
// if($res){
// file_put_contents('/usr/local/email.txt', 'log_time:'.date('Y-m-d H:i:s').' success:to '.$data['email'].PHP_EOL, FILE_APPEND);
// $job->delete();
// }else{
// if($job->attempts()>3){
// file_put_contents('/usr/local/email.txt', 'log_time:'.date('Y-m-d H:i:s').' error:to '.$data['email'].PHP_EOL, FILE_APPEND);
// 第1种处理方式重新发布任务,该任务延迟10秒后再执行
//$job->release(10);
// 第2种处理方式原任务的基础上1分钟执行一次并增加尝试次数
//$job->failed();
// 第3种处理方式删除任务
$job->delete();
}
}
// $job->delete();
// }
// }
}
/**