20201112
This commit is contained in:
62
application/api/job/img.php
Normal file
62
application/api/job/img.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user