1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Support\Traits;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Models\Base\CategorySetting;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Storage;
- use PhpOffice\PhpWord\Element\Table;
- use PhpOffice\PhpWord\SimpleType\JcTable;
- use PhpOffice\PhpWord\TemplateProcessor;
- trait MakeWord
- {
- /**
- * 获取目录
- * @param $model
- * @return string
- */
- public static function getDirectory($model, $isAllPath = true)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- if (!$isAllPath) return "jlb/{$model->id}/{$time}";
- $directory = Storage::disk('public')->path("jlb/{$model->id}/{$time}");
- return $directory;
- }
- /**
- * 是否存在
- * @param $model
- * @return bool
- */
- public static function isExists($model)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $directory = Storage::disk('public')->path("jlb/{$model->id}/{$time}");
- $filename = $directory . '.zip';
- return file_exists($filename);
- }
- /**
- * 是否存在
- * @param $model
- * @return bool
- */
- public static function isZipExists($directory)
- {
- $filename = Storage::disk('public')->path($directory . '.zip');
- return file_exists($filename);
- }
- /**
- * 下载文件
- * @param $model
- * @return false|void
- */
- public static function downZip($model)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $directory = Storage::disk('public')->path("jlb/{$model->id}/{$time}");
- $filename = $directory . '.zip';
- if (!file_exists($filename)) {
- //下载文件
- return false;
- }
- $name = "{$model->project_name}_{$time}.zip";
- // 设置头部以便下载
- header('Content-Type: application/zip');
- header('Content-Disposition: attachment; filename="' . $name . '"');
- header('Content-Length: ' . filesize($filename));
- // 读取 ZIP 文件并输出到浏览器
- readfile($filename);
- }
- /**
- * 删除文件夹
- * @param $model
- * @return true
- */
- public static function clearDirectory($model)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $storage_directory = "jlb/{$model->id}/{$time}";
- Storage::disk('public')->deleteDirectory($storage_directory);
- return true;
- }
- /**
- * 打包文件
- * @param $model
- * @return true
- */
- public static function packDirectory($model)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $zipname = Storage::disk('public')->path("jlb/{$model->id}/{$time}.zip");
- $storage_directory = "jlb/{$model->id}/{$time}";
- $zip = new \ZipArchive();
- $zip->open($zipname, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
- // 如果你想要递归获取所有子目录中的文件,可以使用 directories 方法
- $files = Storage::disk('public')->allFiles($storage_directory);
- // 输出文件列表
- foreach ($files as $file) {
- $zip->addFile(Storage::disk('public')->path($file), str_replace($storage_directory . '/', '', $file)); // 使用 basename() 保留原始文件名
- }
- $zip->close();
- return true;
- }
- /**
- * 打包
- * @param $zipname
- * @param $storage_directory
- * @return true
- */
- public static function pack($zipname, $storage_directory)
- {
- $zip = new \ZipArchive();
- $zip->open($zipname, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
- // 如果你想要递归获取所有子目录中的文件,可以使用 directories 方法
- $files = Storage::disk('public')->allFiles($storage_directory);
- // 输出文件列表
- foreach ($files as $file) {
- $zip->addFile(Storage::disk('public')->path($file), str_replace($storage_directory . '/', '', $file)); // 使用 basename() 保留原始文件名
- }
- $zip->close();
- return true;
- }
- /**
- * 打包并下载文件
- * @param $zipname
- * @param $storage_directory
- * @return false|void
- */
- public static function packDownZip($zipname, $directory)
- {
- $filename = Storage::disk('public')->path($directory);
- if (!file_exists($filename)) {
- //下载文件
- return false;
- }
- $filename = $filename . '.zip';
- //是否存在 zip
- if (!file_exists($filename)) {
- self::pack($filename, $directory);
- }
- // // 设置头部以便下载
- header('Content-Type: application/zip');
- header('Content-Disposition: attachment; filename="' . $zipname . '"');
- header('Content-Length: ' . filesize($filename));
- // 读取 ZIP 文件并输出到浏览器
- readfile($filename);
- }
- /**
- * 生成 word
- * @param $model
- * @param $template_type
- * @return true|null|false
- */
- public static function makeWord($model, $template_type)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $directory = Storage::disk('public')->path("jlb/{$model->id}/{$time}");
- $path = base_path("public/template/ant/template_{$template_type}.docx");
- $is = file_exists($path);
- if (!$is) {
- abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '模板文件找不到');
- return false;
- }
- $br = '<w:br />';
- try {
- $template = new TemplateProcessor($path);
- //1、基本信息
- $template->setValue('dan_name', $model->danger_cell);
- $template->setValue('start_date', Carbon::parse($model->day)->format("Y年 m月 d日"));
- $template->setValue('end_date', Carbon::parse($model->end_day)->format("Y年 m月 d日"));
- $template->setValue('project_name', $model->project_name);
- $template->setValue('project_level_name', $model->project_level_name);
- $types = [
- '土坝', '土石坝', '其它坝', '土堤', '土石堤', '其它堤'
- ];
- $projectArr = [];
- foreach ($types as $type) {
- if ($model->project_type_name == $type) {
- $projectArr[] = "☑{$type}";
- continue;
- }
- $projectArr[] = "□{$type}";
- }
- $template->setValue('project_type', arr2str($projectArr, ' '));
- //周边环境
- $environment = '';
- if ($model->is_environment && is_array($model->environment)) {
- $environment .= '(1)周围环境:';
- $es = [];
- foreach ($model->environment as $item) {
- $cs = [];
- if (!is_array($item['select'])) continue;
- foreach ($item['select'] as $val) {
- if ($val['checked']) {
- $cs[] = $val['name'];
- }
- }
- if (count($cs)) {
- $es[] = "{$item['name']}:" . arr2str($cs, '、');
- }
- }
- $environment .= arr2str($es, ';');
- $environment .= $br;
- } else {
- $environment .= '(1)周围环境:无';
- $environment .= $br;
- }
- if ($model->is_turang) {
- $environment .= "(2)土壤信息:";
- $ts = [];
- if ($model->turang_day) {
- $ts[] = '采集日期:' . Carbon::parse($model->turang_day)->format('Y-m-d');
- }
- if ($model->turang_buwei) {
- $ts[] = '采集部位:' . $model->turang_buwei;
- }
- if ($model->turang_ph) {
- $ts[] = 'ph值:' . $model->turang_ph;
- }
- if ($model->turang_wendu) {
- $ts[] = "温度:{$model->turang_wendu}°C";
- }
- if ($model->turang_shidu) {
- $ts[] = "湿度:{$model->turang_shidu}RH";
- }
- $environment .= arr2str($ts, ';');
- $environment .= $br;
- } else {
- $environment .= '(2)土壤信息:无';
- $environment .= $br;
- }
- if ($model->is_danger_plants && is_array($model->danger_plants)) {
- $ps = [];
- foreach ($model->danger_plants['select'] as $item) {
- if ($item['checked']) {
- $ps[] = $item['name'];
- }
- }
- if ($model->danger_plants['others']) $ps[] = $model->danger_plants['others'];
- $environment .= '(3)蚁患区主要植被:' . arr2str($ps, '、');
- $environment .= $br;
- } else {
- $environment .= '(3)蚁患区主要植被:无';
- $environment .= $br;
- }
- if ($model->is_area_plants && is_array($model->area_plants)) {
- $ps = [];
- foreach ($model->area_plants['select'] as $item) {
- if ($item['checked']) {
- $ps[] = $item['name'];
- }
- }
- if ($model->area_plants['others']) $ps[] = $model->area_plants['others'];
- $environment .= '(4)蚁源区主要植被:' . arr2str($ps, '、');
- $environment .= $br;
- } else {
- $environment .= '(4)蚁源区主要植被:无';
- $environment .= $br;
- }
- if ($model->turang_body) {
- $environment .= '(5)情况描述:' . $model->turang_body;
- } else {
- $environment .= '(5)情况描述:无';
- }
- $template->setValue('environment', $environment);
- //2、白蚁危害
- $danger_types = $model->danger_types;
- $dangerArr = [];
- // $isBaiyi = false;
- if (is_array($danger_types) && array_key_exists('select', $danger_types)) {
- foreach ($danger_types['select'] as $item) {
- if ($item['checked']) {
- $dangerArr[] = "☑{$item['name']}";
- // $isBaiyi = true;
- continue;
- }
- $dangerArr[] = "□{$item['name']}";
- }
- if ($danger_types['others']) $dangerArr[2] = $dangerArr[2] . ':' . $danger_types['others'];
- }
- // if ($isBaiyi) {
- // array_unshift($dangerArr, "☑无白蚁");
- // } else {
- // array_unshift($dangerArr, "□无白蚁");
- // }
- $template->setValue('danger_type', arr2str($dangerArr, ' '));
- $danger = '';
- $danger_area = '';
- $danger .= "是否有蚁患:" . ($model->is_ant_danger ? '是' : '否') . $br;
- if ($model->is_ant_danger) {
- if ($model->danger_area) {
- $danger .= "面积:{$model->danger_area}m²;{$br}";
- }
- if ($model->danger_feature && is_array($model->danger_feature_extend)) {
- $danger .= '外露特征:';
- $dangerArr = [];
- foreach ($model->danger_feature_extend as $item) {
- if ($item['nums']) {
- $dangerArr[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $danger .= arr2str($dangerArr, '、');
- $danger .= $br;
- }
- if ($model->danger_hole) {
- $danger .= "分飞孔:{$model->danger_hole}个;";
- $danger .= $br;
- }
- }
- if ($model->danger_animal && is_array($model->danger_animal_extend)) {
- $danger .= '其他害堤动物外露特征:';
- $dangerArr = [];
- foreach ($model->danger_animal_extend as $item) {
- if ($item['nums']) {
- $dangerArr[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $danger .= arr2str($dangerArr, '、');
- // $danger .= $br;
- } else {
- $danger .= '其他害堤动物外露特征:无';
- // $danger .= $br;
- }
- $danger_area .= "是否有蚁患:" . ($model->is_ant_area ? '是' : '否') . $br;
- if ($model->is_ant_area) {
- if ($model->area_area) {
- $danger_area .= "面积:{$model->area_area}m²;{$br}";
- }
- if ($model->area_feature && is_array($model->area_feature_extend)) {
- $danger_area .= '外露特征:';
- $dangerArr = [];
- foreach ($model->area_feature_extend as $item) {
- if ($item['nums']) {
- $dangerArr[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $danger_area .= arr2str($dangerArr, '、');
- $danger_area .= $br;
- }
- if ($model->area_hole) {
- $danger_area .= "分飞孔:{$model->area_hole}个;";
- $danger_area .= $br;
- }
- if ($model->pd_sanjin) {
- $danger_area .= "散浸:{$model->pd_sanjin}处;";
- $danger_area .= $br;
- }
- if ($model->pd_shipo) {
- $danger_area .= "湿坡:{$model->pd_shipo}处;";
- $danger_area .= $br;
- }
- if ($model->pd_loudong) {
- $danger_area .= "漏洞:{$model->pd_loudong}处;";
- $danger_area .= $br;
- }
- if ($model->pd_diewo) {
- $danger_area .= "跌窝:{$model->pd_diewo}处;";
- $danger_area .= $br;
- }
- if ($model->pd_tuopo) {
- $danger_area .= "脱坡:{$model->pd_tuopo}处;";
- $danger_area .= $br;
- }
- $danger_area .= $br;
- }
- //其他区域
- $other = '';
- $settings = CategorySetting::settings();
- $yingxiang = '';
- foreach ($settings['data']['yingxiang'] as $setting) {
- if ($setting['id'] == $model->is_project_danger) $yingxiang = $setting['name'];
- }
- $other .= "对水工建筑物影响:{$yingxiang};" . $br;
- $other .= "是否有白蚁造成危害:" . ($model->is_ant_cause_danger ? '是' : '否') . ";" . $br;
- $other .= "是否有纷飞监测:" . ($model->is_fenfei ? '是' : '否') . ";";
- $template->setValue('other', $other);
- $danger = trim($danger, $br);
- $template->setValue('danger', $danger);
- $danger_area = trim($danger_area, $br);
- $template->setValue('danger_area', $danger_area);
- $template->setValue('danwei', $model->department);
- $template->setValue('admin_name', $model->admin ? $model->admin->name : '');
- $template->setValue('jianchashijian', Carbon::parse($model->created_at)->format('Y年 m月 d日'));
- $template->setValue('danger_level', $model->danger_level);
- $template->setValue('dan_cell', $model->danger_cell_code);
- switch ($template_type) {
- case 1:
- $filename = "3.白蚁危害检查表.docx";
- File::isDirectory($directory) or File::makeDirectory($directory, 0777, true, true);
- $file_path = "{$directory}/{$filename}";
- $template->saveAs($file_path);
- //附件
- $shiyitu = $model->shiyitu;
- if (is_array($shiyitu)) {
- $directory = "jlb/{$model->id}/{$time}";
- if (count($shiyitu) === 1) {
- foreach ($shiyitu as $k => $item) {
- $exception = File::extension($item['url']);
- $filename = $directory . "/4.白蚁危害分布图.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- } else {
- foreach ($shiyitu as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/4.白蚁危害分布图/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- }
- break;
- case 2:
- $filename = "2.白蚁危害等级评定表.docx";
- File::isDirectory($directory) or File::makeDirectory($directory, 0777, true, true);
- $file_path = "{$directory}/{$filename}";
- $template->saveAs($file_path);
- break;
- }
- } catch (\Exception $exception) {
- log_record('记录表生产出错', $exception);
- abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '文件生成失败');
- }
- return true;
- }
- /**
- * 生成报告
- * @param $model
- * @return false|void
- */
- public static function makeBaoGao($model)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $directory = Storage::disk('public')->path("jlb/{$model->id}/{$time}");
- $template_type = 3;
- $path = base_path("public/template/ant/template_{$template_type}.docx");
- $is = file_exists($path);
- if (!$is) {
- abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '模板文件找不到');
- return false;
- }
- $br = '<w:br />';
- try {
- $template = new TemplateProcessor($path);
- //1、基本信息
- $template->setValue('project_name', $model->project_name);
- //工程概况
- $gaikuangArr = [];
- $day = Carbon::parse($model->day)->format('Y年m月d日');
- $address = '';
- if ($model->province) $address .= $model->province;
- if ($model->city) $address .= $model->city;
- if ($model->area) $address .= $model->area;
- if ($model->zhen) $address .= $model->zhen;
- if ($model->cun) $address .= $model->cun;
- $dan_name = $model->danger_cell;
- $gaikuangArr[] = "{$day},我单位对{$dan_name}进行白蚁等害堤动物定期普查。该工程位于{$address},为{$model->project_level_name}{$model->project_type_name},坝型为{$model->project_dam_type_name}";
- if ($model->altitude) {
- $gaikuangArr[] = "工程所在地海拔{$model->altitude}m";
- }
- if ($model->rain) {
- $gaikuangArr[] = "年平均降雨量{$model->rain}mm";
- }
- if ($model->max_temperature) {
- $gaikuangArr[] = "年平均气温{$model->max_temperature}℃";
- }
- $cs = [];
- $is_qt = false;
- if ($model->is_environment && is_array($model->environment)) {
- foreach ($model->environment as $item) {
- foreach ($item['select'] as $val) {
- if ($val['checked']) {
- if ($val['name'] == '其它' || $val['name'] == '其他') {
- // $cs[] = $val['name'];
- $is_qt = true;
- } else {
- $cs[] = $val['name'];
- }
- }
- }
- }
- $cs = array_unique($cs);
- }
- if (count($cs)) {
- $gaikuangArr[] = '工程周边主要为' . arr2str($cs, '、') . '等地形';
- }
- //2024年6月3日,我单位对铜仁市沿河土家族自治县青杠溪水库进行白蚁等害堤动物定期普查。该工程位于贵州省铜仁市沿河土家族自治县甘溪镇关林村,为小(二)型土石坝,工程所在地海拔558m,年平均降雨量1140mm,年平均气温18.3℃,工程周边主要为旱地、灌木地,林地及其他地形。
- $gaikuang = arr2str($gaikuangArr, ',') . '。';
- $template->setValue('gongchenggaikuang', $gaikuang);
- //分飞监测
- $fenfei = '';
- $fenfei_baiyijianche = '';
- if ($model->is_fenfei) {
- $fday = Carbon::parse($model->fenfei_start_day)->format("Y年m月d日");
- $fenfei = "本工程实施了白蚁分飞监测,{$fday}监测到{$model->fenfei_nums}次分飞,监测到{$model->fenfei_body}种蚁种。";
- $fenfei_baiyijianche = "经对监测结果分析{$model->project_name}有白蚁危害。";
- } else {
- $fenfei = '本工程未进行白蚁危害监测。';
- $fenfei_baiyijianche = "未实施白蚁监测。";
- }
- $template->setValue('fenfei', $fenfei);
- //未实施白蚁监测(如有就填写“经对监测结果分析xx水库有白蚁危害”)。
- $template->setValue('fenfei_baiyijianche', $fenfei_baiyijianche);
- $baiyifenxiArr = [];
- $baiyifenxizongjie = '';
- if (!$model->is_ant_danger && !$model->is_ant_area) {
- $baiyifenxizongjie = "经对{$model->project_name}检查未发现白蚁外露特征及活动痕迹,未发现其他害堤动物活动痕迹。";
- } elseif ($model->is_ant_danger && !$model->is_ant_area) {
- $wltz = [];
- if (is_array($model->danger_feature_extend)) {
- foreach ($model->danger_feature_extend as $item) {
- $wltz[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $wltz[] = "分飞孔{$model->danger_hole}个";
- $wltzs = arr2str($wltz, '、');
- $wltzs = "({$wltzs}。)";
- $baiyifenxiArr[] = "经对{$model->project_name}检查,蚁患区共发现有{$model->danger_feature}处外露特征{$wltzs}。";
- } elseif (!$model->is_ant_danger && $model->is_ant_area) {
- $wltz = [];
- if (is_array($model->area_feature_extend)) {
- foreach ($model->area_feature_extend as $item) {
- $wltz[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $wltz[] = "分飞孔{$model->area_hole}个";
- $wltzs = arr2str($wltz, '、');
- $wltzs = "({$wltzs}。)";
- $baiyifenxiArr[] = "经对{$model->project_name}检查,蚁源区共发现有{$model->area_feature}处外露特征{$wltzs}。";
- } else {
- $wltz = [];
- if (is_array($model->danger_feature_extend)) {
- foreach ($model->danger_feature_extend as $item) {
- $wltz[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $wltz[] = "分飞孔{$model->danger_hole}个";
- $wltzs = arr2str($wltz, '、');
- $wltzs = "({$wltzs}。)";
- $awltz = [];
- if (is_array($model->area_feature_extend)) {
- foreach ($model->area_feature_extend as $item) {
- $awltz[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $awltz[] = "分飞孔{$model->area_hole}个";
- $awltz = arr2str($awltz, '、');
- $awltz = "({$awltz}。)";
- $baiyifenxiArr[] = "经对{$model->project_name}蚁患区{$model->danger_area}m²、蚁源区{$model->area_area}m²进行检查,蚁患区共有{$model->danger_feature}处外露特征{$wltzs}。蚁源区共发现有{$model->area_feature}处外露特征{$wltzs}。";
- }
- // $wltz = [];
- // if (is_array($model->danger_feature_extend)) {
- // foreach ($model->danger_feature_extend as $item) {
- // $wltz[] = "{$item['name']}{$item['nums']}处";
- // }
- // }
- // $wltz[] = "分飞孔{$model->danger_hole}个";
- // $wltzs = arr2str($wltz, '、');
- // $wltzs = "({$wltzs}。)";
- // $baiyifenxiArr[] = "经对{$model->project_name}蚁患区{$model->danger_area}m²、蚁源区{$model->area_area}m²进行检查,蚁患区共有{$model->danger_feature}处外露特征{$wltzs}。";
- if ($model->pd_sanjin || $model->pd_shipo || $model->pd_loudong || $model->pd_diewo || $model->pd_tuopo) {
- $byzc = "非白蚁造成危害";
- if ($model->is_ant_cause_danger) {
- $byzc = "为白蚁造成危害";
- }
- $baiyifenxiArr[] = "散浸{$model->pd_sanjin}处、湿坡{$model->shipo}处、漏洞{$model->loudong}处、跌窝{$model->pd_diewo}处、脱坡{$model->tuopo}处,{$byzc}";
- } else {
- $baiyifenxiArr[] = "无散浸、湿坡、漏洞、跌窝、脱坡等现象。";
- }
- $danger_types = $model->danger_types;
- $dangerArr = [];
- if (is_array($danger_types) && array_key_exists('select', $danger_types)) {
- foreach ($danger_types['select'] as $item) {
- if ($item['checked']) {
- $dangerArr[] = "{$item['name']}";
- }
- }
- if ($danger_types['others']) $dangerArr[] = $danger_types['others'];
- }
- $p3 = '';
- $isDanger = false;
- //检查到蚁种为黑翅土白蚁,检查未发现其他害堤动物(检查发现其他害堤动物外露特征 处,(獾 处、鼠 处、狐 处、其他动物 处))
- if (count($dangerArr)) {
- $isDanger = true;
- $p3 = "检查到蚁种为" . arr2str($dangerArr, '、');
- } else {
- $p3 = "检查未发现蚁种";
- }
- $dangerAnimalArr = [];
- if ($model->danger_animal) {
- $danger_animals = $model->danger_animal_extend;
- foreach ($danger_animals as $item) {
- $dangerAnimalArr[] = "{$item['name']}{$item['nums']}处";
- }
- }
- $p4 = '';
- $isDangerAnimal = false;
- //检查到蚁种为黑翅土白蚁,检查未发现其他害堤动物(检查发现其他害堤动物外露特征 处,(獾 处、鼠 处、狐 处、其他动物 处))
- if (count($dangerAnimalArr)) {
- $dws = arr2str($dangerAnimalArr, '、');
- $isDangerAnimal = true;
- $p4 = "检查发现其他害堤动物外露特征{$model->danger_animal}处({$dws})。";
- } else {
- $p4 = "检查未发现其他害堤动物。";
- }
- $baiyifenxiArr[] = "{$p3},{$p4}";
- $baiyifenxi = arr2str($baiyifenxiArr, '');
- //经对青杠溪水库蚁患区 m²、蚁源区 m²进行检查,蚁患区共有11处外露特征(泥被、泥线11处、真菌指示物0处、白蚁活动痕迹0处、蚁道0处、其他外露特征0处、分飞孔0处。)。蚁源区共有1处外露特征(泥被、泥线1处、真菌指示物0处、白蚁活动痕迹0处、蚁道0处、其他外露特征0处、分飞孔0处。)。无散浸、湿坡、漏洞、跌窝、脱坡等现象,(散浸 处、湿坡 处、漏洞 处、跌窝 处、脱坡 处,为白蚁造成危害{非白蚁造成危害})。检查到蚁种为黑翅土白蚁,检查未发现其他害堤动物(检查发现其他害堤动物外露特征 处,(獾 处、鼠 处、狐 处、其他动物 处))(括号为“如有的情况下”段落为固定格式)。
- $template->setValue('baiyifenxi', $baiyifenxi);
- if ($isDanger == false && $isDangerAnimal == false) {
- $baiyifenxizongjie = "根据检查结果分析,{$model->project_name}没有白蚁危害。";
- } else {
- $baiyifenxizongjieArr[] = '根据检查结果分析';
- if ($isDanger) {
- $my = arr2str($dangerArr, '、');
- $baiyifenxizongjieArr[] = "{$model->project_name}有{$my}危害";
- if ($isDangerAnimal) {
- $baiyifenxizongjieArr[] = "及其他害堤动物危害";
- }
- } else {
- if ($isDangerAnimal) {
- $baiyifenxizongjieArr[] = "{$model->project_name}有其他害堤动物危害";
- }
- }
- $baiyifenxizongjie = arr2str($baiyifenxizongjieArr, ',') . '。';
- }
- $template->setValue('baiyifenxizongjie', $baiyifenxizongjie);
- $template->setValue('danger_level', $model->danger_level . '。');
- $danger_jianyi = '';
- switch ($model->danger_level) {
- case '无危害':
- $danger_jianyi = "";
- break;
- case '一级危害':
- $danger_jianyi = "建议对危害物种定期进行监测,掌握危害发展趋势,适时开展白蚁等害堤动物危害综合治理。";
- break;
- case '二级危害':
- $danger_jianyi = "建议对危害物种进行适时监测,尽早开展白蚁等害堤动物危害综合治理。";
- break;
- case '三级危害':
- $danger_jianyi = "建议对危害物种进行密切监测,即时开展白蚁等害堤动物危害综合治理。";
- break;
- }
- $template->setValue('danger_jianyi', $danger_jianyi);
- $filename = "1.水利工程白蚁危害评定报告.docx";
- File::isDirectory($directory) or File::makeDirectory($directory, 0777, true, true);
- $file_path = "{$directory}/{$filename}";
- $template->saveAs($file_path);
- $base_directory = "jlb/{$model->id}/{$time}";
- //拷贝图片
- if ($model->danger_feature && is_array($model->danger_animal_extend)) {
- $directory = "{$base_directory}/5.白蚁危害评定检查现场及相关影像/蚁患/外露特征";
- foreach ($model->danger_feature_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- //分飞孔
- if ($model->danger_hole && is_array($model->danger_hole_paths)) {
- $directory = "{$base_directory}/5.白蚁危害评定检查现场及相关影像/蚁患/外露特征";
- foreach ($model->danger_hole_paths as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/分飞孔/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- if ($model->danger_animal && is_array($model->danger_animal_extend)) {
- $directory = "{$base_directory}/5.白蚁危害评定检查现场及相关影像/蚁患/其他害堤动物外露特征";
- foreach ($model->danger_animal_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- //蚁源区
- if ($model->area_feature && is_array($model->area_feature_extend)) {
- $directory = "{$base_directory}/5.白蚁危害评定检查现场及相关影像/蚁源区/外露特征";
- foreach ($model->area_feature_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- //分飞孔
- if ($model->area_hole && is_array($model->area_hole_paths)) {
- $directory = "{$base_directory}/5.白蚁危害评定检查现场及相关影像/蚁源区/外露特征";
- foreach ($model->area_hole_paths as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/分飞孔/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- } catch (\Exception $exception) {
- log_record('报告生产出错', $exception);
- abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '文件生成失败');
- }
- }
- /**
- * 生成图片
- * @param $model
- * @return bool
- */
- public static function makeImgWord($model)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $directory = Storage::disk('public')->path("jlb/{$model->id}/{$time}");
- $template_type = 4;
- $path = base_path("public/template/ant/template_{$template_type}.docx");
- $is = file_exists($path);
- if (!$is) {
- abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '模板文件找不到');
- return false;
- }
- try {
- $template = new TemplateProcessor($path);
- $table = new Table(['borderSize' => 0, 'borderColor' => 'ffffff', 'alignMent' => JcTable::CENTER, 'cellSpacing' => 50]);
- $table_imgs = [];
- $i = 1;
- if ($model->danger_feature && is_array($model->danger_animal_extend)) {
- foreach ($model->danger_feature_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- $table->addRow();
- $table->addCell(5000, ['gridSpan' => 2])->addText('蚁患-' . $item['name']);
- foreach ($item['img_paths'] as $k => $img) {
- $filename = $img['url'];
- if ($k % 2 == 0) $table->addRow();
- $key = 'img_' . $i;
- $table->addCell(5000)->addText('${img_' . $i . '}');
- $i++;
- $table_imgs[] = ['key' => $key, 'url' => $filename];
- }
- }
- }
- //分飞孔
- if ($model->danger_hole && is_array($model->danger_hole_paths)) {
- $table->addRow();
- $table->addCell(5000, ['gridSpan' => 2])->addText('蚁患-分飞孔');
- foreach ($model->danger_hole_paths as $k => $img) {
- $filename = $img['url'];
- if ($k % 2 == 0) $table->addRow();
- $key = 'img_' . $i;
- $table->addCell(5000)->addText('${img_' . $i . '}');
- $i++;
- $table_imgs[] = ['key' => $key, 'url' => $filename];
- }
- }
- if ($model->danger_animal && is_array($model->danger_animal_extend)) {
- $table->addRow();
- $table->addCell(5000, ['gridSpan' => 2])->addText('蚁患-其他害堤动物外露特征');
- foreach ($model->danger_animal_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $filename = $img['url'];
- if ($k % 2 == 0) $table->addRow();
- $key = 'img_' . $i;
- $table->addCell(5000)->addText('${img_' . $i . '}');
- $i++;
- $table_imgs[] = ['key' => $key, 'url' => $filename];
- }
- }
- }
- //蚁源区
- if ($model->area_feature && is_array($model->area_feature_extend)) {
- $table->addRow();
- $table->addCell(5000, ['gridSpan' => 2])->addText('蚁源区-外露特征');
- foreach ($model->area_feature_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $filename = $img['url'];
- if ($k % 2 == 0) $table->addRow();
- $key = 'img_' . $i;
- $table->addCell(5000)->addText('${img_' . $i . '}');
- $i++;
- $table_imgs[] = ['key' => $key, 'url' => $filename];
- }
- }
- }
- //分飞孔
- if ($model->area_hole && is_array($model->area_hole_paths)) {
- $table->addRow();
- $table->addCell(5000, ['gridSpan' => 2])->addText('蚁源区-分飞孔');
- foreach ($model->area_hole_paths as $k => $img) {
- $filename = $img['url'];
- if ($k % 2 == 0) $table->addRow();
- $key = 'img_' . $i;
- $table->addCell(5000)->addText('${img_' . $i . '}');
- $i++;
- $table_imgs[] = ['key' => $key, 'url' => $filename];
- }
- }
- $template->setComplexBlock('block', $table);
- foreach ($table_imgs as $img) {
- $template->setImageValue($img['key'], ['path' => $img['url'], 'width' => 1000, 'height' => 200]);
- }
- $filename = "6.白蚁危害评定检查现场及相关影像.docx";
- File::isDirectory($directory) or File::makeDirectory($directory, 0777, true, true);
- $file_path = "{$directory}/{$filename}";
- $template->saveAs($file_path);
- } catch (\Exception $exception) {
- log_record('报告图片出错', $exception);
- abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '文件生成失败');
- }
- return true;
- }
- public static function packImgs($model, $type)
- {
- $time = Carbon::parse($model->updated_at)->timestamp;
- $base_directory = "packImgs/{$model->id}/{$time}";
- $filename = '';
- switch ($type) {
- case 1:
- $directory = "{$base_directory}/周围环境";
- //周围环境
- if (!self::isZipExists($directory)) {
- if (is_array($model->environment)) {
- foreach ($model->environment as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- $filename = "{$model->project_name}_周围环境.zip";
- }
- break;
- case 2:
- //蚁患
- $directory = "{$base_directory}/蚁患/外露特征";
- if (!self::isZipExists($directory)) {
- if (is_array($model->danger_feature_extend)) {
- foreach ($model->danger_feature_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- if ($model->danger_hole && is_array($model->danger_hole_paths)) {
- foreach ($model->danger_hole_paths as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/分飞孔/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- $directory = "{$base_directory}/蚁患/其他害堤动物外露特征";
- if ($model->danger_animal && is_array($model->danger_animal_extend)) {
- foreach ($model->danger_animal_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- }
- $directory = "{$base_directory}/蚁患";
- $filename = "{$model->project_name}_蚁患.zip";
- break;
- case 3:
- //蚁源区
- $directory = "{$base_directory}/蚁源区/外露特征";
- if (!self::isZipExists($directory)) {
- if ($model->area_feature && is_array($model->area_feature_extend)) {
- $directory = "{$base_directory}/蚁源区/外露特征";
- foreach ($model->area_feature_extend as $item) {
- if (!isset($item['img_paths']) || !is_array($item['img_paths'])) continue;
- foreach ($item['img_paths'] as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/{$item['name']}/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- //分飞孔
- if ($model->area_hole && is_array($model->area_hole_paths)) {
- $directory = "{$base_directory}/蚁源区/外露特征";
- foreach ($model->area_hole_paths as $k => $img) {
- $index = $k + 1;
- $exception = File::extension($img['url']);
- $filename = $directory . "/分飞孔/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($img['url']));
- }
- }
- }
- $directory = "{$base_directory}/蚁源区";
- $filename = "{$model->project_name}_蚁源区.zip";
- break;
- case 4:
- //工程影响
- $directory = "{$base_directory}/工程影响";
- if (!self::isZipExists($directory)) {
- if ($model->pd_sanjin && is_array($model->pd_sanjin_paths)) {
- foreach ($model->pd_sanjin_paths as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/散浸/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- if ($model->pd_shipo && is_array($model->pd_shipo_paths)) {
- foreach ($model->pd_shipo_paths as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/湿坡/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- if ($model->pd_loudong && is_array($model->pd_loudong_paths)) {
- foreach ($model->pd_loudong_paths as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/漏洞/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- if ($model->pd_diewo && is_array($model->pd_diewo_paths)) {
- foreach ($model->pd_diewo_paths as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/跌窝/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- if ($model->pd_tuopo && is_array($model->pd_tuopo_paths)) {
- foreach ($model->pd_tuopo_paths as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/脱坡/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- }
- $directory = "{$base_directory}/工程影响";
- $filename = "{$model->project_name}_工程影响.zip";
- break;
- case 5:
- //示意图
- $directory = "{$base_directory}/示意图";
- if (!self::isZipExists($directory)) {
- $shiyitu = $model->shiyitu;
- if (is_array($shiyitu)) {
- foreach ($shiyitu as $k => $item) {
- $index = $k + 1;
- $exception = File::extension($item['url']);
- $filename = $directory . "/{$index}.{$exception}";
- Storage::disk('public')->put($filename, file_get_contents($item['url']));
- }
- }
- }
- $directory = "{$base_directory}/示意图";
- $filename = "{$model->project_name}_示意图.zip";
- break;
- }
- self::packDownZip($filename, $directory);
- }
- }
|