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.

149 lines
5.4 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\Services\mH5;
use DateTime;
use Illuminate\Support\Facades\DB;
class PersonService
{
//检测是否注册过
public function checkRegister($arr){
$openid=$arr['openid'];
$c=DB::table('persons')->where(['openid'=>$openid])->get();
if(count($c)){
return true;
}else{
return false;
}
}
//注册
public function Register($arr){
$result=array();
$c= $this->checkRegister(['openid'=>$arr['openid']]);
if($c){
$result['status']=false;
$result['msg']='已注册过,无需进行此操作';
}else{
//HSM加密
$HSM_sfz =\App\Lib\HSM::HsmEncrypt($arr['info']['sfz']);
if($HSM_sfz['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$arr['info']['sfz']=$HSM_sfz['data'];
if(isset($arr['info']['tel'])){
$HSM_tel =\App\Lib\HSM::HsmEncrypt($arr['info']['tel']);
if($HSM_tel['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$arr['info']['tel']=$HSM_tel['data'];
}
$i=DB::table('persons')->insert([
'name' => $arr['info']['name'],
'sex' => $arr['info']['sex'],
'id_card_num' => $arr['info']['sfz'],
'tel' => $arr['info']['tel'],
'openid' => $arr['openid'],
'status'=>1
]);
if($i){
$result['status']=true;
$result['msg']='创建成功';
}else{
$result['status']=false;
$result['msg']='操作失败';
}
}
return $result;
}
//检测是否进行过免费体检
public function GetPersonRecode($arr,$type=1){
$result=array();
$id_num='';
if(isset($arr['group']) and $arr['group']=='mH5user'){ //如果是本地项目请求(非对外接口)
$openid=$arr['openid'];
$c=DB::table('persons')->select(['id_card_num'])->where(['openid'=>$openid,'status'=>1])->get();
if(count($c)>0){
$id_num=$c[0]->id_card_num;
}else{
$result['status']=false;
$result['msg']='未找到有效用户';
return $result;
}
}else{ //对外接口直接获取证件IdNum
$id_num=$arr['id_num'];
}
if(strlen($id_num)>0){
date_default_timezone_set('PRC');
$currentYear = date('Y');
$firstDay = date('Y-01-01', strtotime($currentYear));
$lastDay = date('Y-12-31', strtotime($currentYear));
//查询体检预约记录
//查询体检记录表 免费体检记录
$c=DB::table('examination_records as a') ->join('medical_institution as b', 'a.institution_id', '=', 'b.id')
->select(['a.id','a.institution_id','a.id_card_num','a.tijian_num','a.tijian_time','a.created_at as insertime','b.org_name'])->where([['a.id_card_num','=',$id_num],['a.created_at','>=',$firstDay],['a.created_at','<=',$lastDay]])->get();
if(count($c)>0){
$result['status']=false;
$result['msg']='已体检过';
$result['info']=$c;
}else{
$result['status']=true;
$result['msg']='可以继续,本年度无免费体检记录';
$result['info']=$c;
}
}else{
$result['status']=false;
$result['msg']='用户证件号未传';
}
return $result;
}
//获取个人预约记录详情
public function GetAppointmentRecord($arr){
//HSM加密
$HSM_sfz =\App\Lib\HSM::HsmEncrypt($arr['id_num']);
if($HSM_sfz['status']!=true){
return \Yz::echoError1('调用HSM加密失败');
}
$arr['id_num']=$HSM_sfz['data'];
$cha = DB::select("SELECT a.*,b.sex,b.tel,b.status,c.org_name from appointment_record as a INNER JOIN
persons as b on a.person_id=b.id INNER JOIN medical_institution as c on a.org_id=c.id where a.id_card_num=?
and a.status=1",[$arr['id_num']]);
if(count($cha)>0){
$cha[0]->bind_check_type=null;
$cha[0]->bind_unit_id=null;
$cha[0]->bind_group_id=null;
$cha[0]->bind_batch_id=null;
$cha[0]->start_time=substr($cha[0]->time, 0,5);
$cha[0]->end_time=substr($cha[0]->time,-5);
$org_seting=DB::table('institution_seting')->where(['institution_id'=>$cha[0]->org_id,'small_check_type'=>$cha[0]->doc_type_name])->first();
if(!!$org_seting){
$cha[0]->bind_check_type=$org_seting->bind_check_type;
$cha[0]->bind_unit_id=$org_seting->bind_unit_id;
$cha[0]->bind_group_id=$org_seting->bind_group_id;
$cha[0]->bind_batch_id=$org_seting->bind_batch_id;
}
$cha_img =DB::table('appointment_img')->where('appointment_record_id',$cha[0]->id)->get();
//env('APP_URL')
foreach ($cha_img as $key=>$item){
$cha_img[$key]->imgurl=env('APP_URL').$item->imgurl;
}
$cha[0]->imgs=$cha_img;
}
if(!count($cha)>0) return \Yz::echoError1("未找到预约记录");
return \Yz::Return(true,'',$cha);
}
}