diff --git a/application/api/controller/Admin.php b/application/api/controller/Admin.php index 3a859fa..333aeea 100644 --- a/application/api/controller/Admin.php +++ b/application/api/controller/Admin.php @@ -457,7 +457,7 @@ class Admin extends Controller { $maidata['content'] = $tt; $maidata['tmail'] = $journal_info['email']; $maidata['tpassword'] = $journal_info['epassword']; - Queue::push( 'app\api\job\mail@fire' , $maidata , "mail" ); + Queue::push( 'app\api\job\mail@fire' , $maidata , "tmail" ); } return json(['sudata' => $su_data, 'erdata' => $er_data]); } diff --git a/application/api/controller/Auto.php b/application/api/controller/Auto.php index 3b5937e..7e1124f 100644 --- a/application/api/controller/Auto.php +++ b/application/api/controller/Auto.php @@ -75,11 +75,11 @@ class Auto extends Controller { public function testmail() { $maidata['email'] = '751475802@qq.com'; - $maidata['title'] = 'test'.date('Ymd His', time()); + $maidata['title'] = 'testdsdsasaddsasdaadsasd'.date('Ymd His', time()); $maidata['content'] = 'dsadsaas'; $maidata['tmail'] = 'tmrcancer@tmrjournals.com'; $maidata['tpassword'] = 'Wu999999tmrcance'; - Queue::push('app\api\job\mail@fire', $maidata, "mail"); + Queue::push('app\api\job\mail@fire', $maidata, "tmail"); } public function mytest(){ diff --git a/application/api/controller/Img.php b/application/api/controller/Img.php new file mode 100644 index 0000000..39c9b4d --- /dev/null +++ b/application/api/controller/Img.php @@ -0,0 +1,259 @@ +request->post(); + +// $data['url'] = 'zhengshu/import/20210610/e7a3ae0879619862f0f5584d674ffc69.xlsx'; +// $data['course'] = 'ZYMR'; + //读取excel + $path = ROOT_PATH . 'public' . DS . $data['url']; + $arr = self::readExcel($path); + + foreach ($arr as $v) { + if ($v['username'] == '') { + continue; + } + $datae['name'] = $v['username']; + $datae['course'] = $data['course']; + + Queue::push('app\api\job\img@fire', $datae, "img"); + } + +// $this->imgCL($arr,$data['course']); + } + +// public function t(){ +// Queue::push( 'app\api\job\img@fire',[], "img" ); +// } + + /** + * 接收导入文件 + * @return type + */ + public function up_import() { + $file = request()->file('importExcel'); + if ($file) { + $info = $file->move(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'import'); + if ($info) { + return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]); + } else { + return json(['code' => 1, 'msg' => $file->getError()]); + } + } + } + + /** + * 获取excel数据 + */ + public function getExcelData() { + //接收数据 + $data = $this->request->post(); + $has = $this->getImgs($data['course']); + $frag = []; + if ($data['url'] != '') { + $path = ROOT_PATH . 'public' . DS . $data['url']; + $frag = self::readExcel($path); + } + $re['list'] = array_merge($frag, $has); + $re['count'] = count($frag); + $re['has'] = count($has); + return json($re); + } + + /** + * 获取目前科目下的文件总数 + */ + public function getAllNum(){ + $data = $this->request->post(); + $path = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img/'.$data['course'].DS; + $res = scandir($path); + $dirs = []; + foreach ($res as $v) { + if ($v == '.' || $v == '..') { + continue; + } + $dirs[] = ['dirname' => $v]; + } + return json(count($dirs)); + } + + /** + * 获取课程列表 + */ + public function getCourse() { + $base = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img/'; + $res = scandir($base); + $dirs = []; + foreach ($res as $v) { + if ($v == '.' || $v == '..') { + continue; + } + $dirs[] = ['dirname' => $v]; + } + return json($dirs); + } + + /** + * 获取文件下的证书文件 + */ + private function getImgs($course) { + $dir = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img/' . $course . DS; + $res = scandir($dir); + $imgs = []; + foreach ($res as $v) { + if ($v == '.' || $v == '..') { + continue; + } + $imgs[] = ['username' => substr($v, 0, strrpos($v, '.')), 'has' => '已出证']; + } + return $imgs; + } + + public function ttt() { + $v = '12_王金磊.png'; + echo substr($v, 0, strrpos($v, '_')); + } + + /** + * 处理图片主方法 + */ + private function imgCL($arr, $course) { + $cous = $this->getImgs($course); + foreach ($arr as $k => $v) { + if ($v['username'] == '') { + continue; + } + $lim = []; + if (preg_match("/^[\x7f-\xff]+$/", $v['username']) && strlen($v['username']) == 9) { + $lim = [640, 890]; + } else if (preg_match("/^[\x7f-\xff]+$/", $v['username']) && strlen($v['username']) == 6) { + $lim = [670, 890]; + } else { + $left = (730 - ((35 * strlen($v['username'])) / 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($v['username'], $ziti, 50, '#000000', $lim) + ->text('NO.ZYMR' . (20210619001 + $k + count($cous)), $ziti, 25, '#000000', [573, 650]) + ->save(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $course . DS . (1 + $k + count($cous)) . '_' . $v['username'] . '.png'); + } + } + + /** + * + * 清空 + */ + public function clear() { + $data = $this->request->post(); + $path = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img/' . $data['course'] . DS; + $dh = opendir($path); + while ($file = readdir($dh)) { + if ($file != "." && $file != "..") { + $fullpath = $path . "/" . $file; +// if (!is_dir($fullpath)) { + unlink($fullpath); +// } else { +// deldir($fullpath); +// } + } + } + closedir($dh); + return jsonSuccess(['code'=>0]); + } + + //压缩文件 + public function getZip() { + $data = $this->request->post(); + $zipName = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'zip' . DS . $data['course'] . '.zip'; + $zip = new \ZipArchive; //使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 + + if (is_file($zipName)) { + $zip->open($zipName, \ZIPARCHIVE::OVERWRITE); + } else { + $zip->open($zipName, \ZIPARCHIVE::CREATE); + } + + + $dir = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $data['course'] . '/'; + $files = scandir($dir); + + foreach ($files as $val) { + if ($val == '.' || $val == '..') { + continue; + } + if (file_exists(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $data['course'] . '/' . $val)) { + //addFile函数首个参数如果带有路径,则压缩的文件里包含的是带有路径的文件压缩 + //若不希望带有路径,则需要该函数的第二个参数 + $zip->addFile(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $data['course'] . '/' . $val, basename(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $data['course'] . '/' . $val)); //第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下 + } + } + $zip->close(); //关闭 + + if (!file_exists($zipName)) { + exit("无法找到文件"); //即使创建,仍有可能失败 + } + $re['url'] = 'public/zhengshu' . DS . 'zip' . DS . $data['course'] . '.zip'; + + return jsonSuccess($re); + + //如果不要下载,下面这段删掉即可,如需返回压缩包下载链接,只需 return $zipName; +// header("Cache-Control: public"); +// header("Content-Description: File Transfer"); +// header('Content-disposition: attachment; filename='.basename($zipName)); //文件名 +// header("Content-Type: application/zip"); //zip格式的 +// header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件 +// header('Content-Length: '. filesize($zipName)); //告诉浏览器,文件大小 +// @readfile($zipName); + } + + /** + * 读取excel数据 + */ + private function readExcel($path) { + $extension = substr($path, strrpos($path, '.') + 1); + vendor("PHPExcel.PHPExcel"); + if ($extension == 'xlsx') { + $objReader = new \PHPExcel_Reader_Excel2007(); + $objPHPExcel = $objReader->load($path); + } else if ($extension == 'xls') { + $objReader = new \PHPExcel_Reader_Excel5(); + $objPHPExcel = $objReader->load($path); + } + $sheet = $objPHPExcel->getSheet(0); + $highestRow = $sheet->getHighestRow(); + $frag = []; + for ($i = 1; $i <= $highestRow; $i++) { + $aa['username'] = $objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue(); + $aa['has'] = '未出证'; + if($aa['username']==''){ + continue; + } + $frag[] = $aa; + } + return $frag; + } + +} diff --git a/application/api/job/img.php b/application/api/job/img.php new file mode 100644 index 0000000..ac54179 --- /dev/null +++ b/application/api/job/img.php @@ -0,0 +1,62 @@ +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; + } + +} diff --git a/application/api/job/mail.php b/application/api/job/mail.php index c22e604..f69f2fc 100644 --- a/application/api/job/mail.php +++ b/application/api/job/mail.php @@ -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(); +// } +// } + } /**