You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.9 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Controllers\API\mH5;
use App\Http\Controllers\Controller;
use App\Services\mH5\PersonService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Storage;
class PersonController extends Controller
{
//注册
public function Register(Request $request){
$openid = $request->get('userid');//中间件产生的参数
$info =request('info');
$s=app()->make(PersonService::class);
return $s->Register(['openid'=>$openid,'info'=>$info]);
}
public function GetPersonRecode(Request $request){
$openid = $request->get('userid');//中间件产生的参数
$group = $request->get('role');//中间件产生的参数
$s=app()->make(PersonService::class);
return $s->GetPersonRecode(['openid'=>$openid,'group'=>$group]);
}
//获取用户体检详情和pdf
public function GetPersonReportDetail(){
$sfz =request('sfz');
//HSM加密
$HSM_sfz =\App\Lib\HSM::HsmEncrypt($sfz);
if($HSM_sfz['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$sfz=$HSM_sfz['data'];
$info=DB::table('examination_records')->where(['id_card_num'=>$sfz]) ->orderBy('id', 'desc')->first();
if($info){
$info->pdfs=count(json_decode($info->pdfs, true));
$item=DB::table('report_result_item')
->where(['examination_id'=>$info->id])
->select(['item_name','item_result','flag'])->get();
$info->items=$item;
if(strlen($info->id_card_num)>30){
//HSM解密
$HSM_sfz =\App\Lib\HSM::HsmDecrypt($info->id_card_num);
if($HSM_sfz['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$info->id_card_num=$HSM_sfz['data'];
}
return \Yz::Return(true,'',['info'=>$info]);
}else{
return \Yz::echoError1('未找到相关体检信息');
}
}
//修改H5获取用户pdf方式改为根据体检提供的pdf链接地址获取pdf
public function GetPersonPdfDetailByLink()
{
$recordid =request('recordid');
$pdf_num =request('pdf_num');
$query=DB::table('examination_records')->where(['id'=>$recordid])->first();
if(!$query) return \Yz::echoError1('未找到对应体检记录');
$pdfs=json_decode($query->pdfs, true);
$pdfurl=$pdfs[$pdf_num];
// 使用 GuzzleHttp 获取第三方 PDF 地址的内容
$client = new Client();
$response = $client->get($pdfurl);
return response($response->getBody());
// return response($response->getBody()->getContents(), 200)
// ->header('Content-Type', 'application/pdf')
// ->header('Content-Disposition', 'inline; filename="sample.pdf"');
// $date = date("Ymd");
// $filename = 'pdf_' . time() . '.pdf';
// Storage::disk('public')->put('/pdf/'.$date.'/'."a.pdf", $response->getBody());
//
// return \Yz::Return(true,'获取成功',['fileurl' =>'/storage/pdf/'.$date.'/'.$filename]);
}
//用户扫码跳转输入身份证和电话 查询用户体检详情和pdf
public function H5GetPersonReportDetail(){
$get_info =request('info');
if(!isset($get_info['sfz'])) return \Yz::echoError1('身份证不能为空');
if(!isset($get_info['tel'])) return \Yz::echoError1('电话不能为空');
//HSM加密
$HSM_sfz =\App\Lib\HSM::HsmEncrypt($get_info['sfz']);
if($HSM_sfz['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$get_info['sfz']=$HSM_sfz['data'];
if(isset($get_info['tel'])){
$HSM_tel =\App\Lib\HSM::HsmEncrypt($get_info['tel']);
if($HSM_tel['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$get_info['tel']=$HSM_tel['data'];
}
$info=DB::table('examination_records')->where(['id_card_num'=>$get_info['sfz'],'tel'=>$get_info['tel']]) ->orderBy('id', 'desc')->first();
if($info){
$item=DB::table('report_result_item')
->where(['examination_id'=>$info->id])
->select(['item_name','item_result','flag'])->get();
$info->items=$item;
$accessTimeout = \JWT::GetGetSecretTimeOut();
$refreshTimeout = \JWT::GetRefreshTokenTimeOut();
$access_token = \JWT::BuildJWT('yz','access',$get_info['sfz'],'mH5user',$accessTimeout);
$refresh_token = \JWT::BuildJWT('yz','refresh',$get_info['sfz'],'',$refreshTimeout);
return \Yz::Return(true,'',['info'=>$info,'token'=>$access_token,'refresh_token'=>$refresh_token]);
}else{
return \Yz::echoError1('未找到相关体检信息');
}
}
}