|
|
<?php
|
|
|
namespace App\Services\Admin\YeWu;
|
|
|
use DateTime;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
class AppointmentService
|
|
|
{
|
|
|
//获取体检记录列表
|
|
|
public function GetAppointmentList($arr){
|
|
|
$sql=' where 1=1';
|
|
|
$canshu=array();
|
|
|
if($arr['searchInfo']['status']){
|
|
|
$sql=$sql .' and a.status = ? ';
|
|
|
array_push($canshu, $arr['searchInfo']['status']);
|
|
|
}
|
|
|
if($arr['searchInfo']['calendarId']){
|
|
|
$sql=$sql .' and a.calendar_id = ? ';
|
|
|
array_push($canshu, $arr['searchInfo']['calendarId']);
|
|
|
}
|
|
|
|
|
|
|
|
|
if($arr['searchInfo']['dateRange']){
|
|
|
|
|
|
$sql=$sql . ' and a.date>=? and a.date<=? ';
|
|
|
array_push($canshu,$arr['searchInfo']['dateRange'][0],$arr['searchInfo']['dateRange'][1]);
|
|
|
}
|
|
|
|
|
|
|
|
|
if($arr['group']==7){
|
|
|
$cha=DB::table('medical_institution')->where(['link_user_id'=>$arr['userid']])->get();
|
|
|
$sql=$sql .' and a.org_id=?';
|
|
|
array_push($canshu, $cha[0]->id);
|
|
|
}else{
|
|
|
if($arr['searchInfo']['orgId']){
|
|
|
|
|
|
$sql=$sql .' and a.org_id=?';
|
|
|
array_push($canshu, $arr['searchInfo']['orgId']);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
array_push($canshu,($arr['page']-1)*$arr['pageSize'],$arr['pageSize']);
|
|
|
|
|
|
$query=DB::select("select a.*,b.org_name from appointment_record as a LEFT JOIN
|
|
|
medical_institution as b on a.org_id=b.id ".$sql." order by a.id desc limit ?,?",$canshu);
|
|
|
|
|
|
$count=DB::select("select count(*) as c from appointment_record as a ".$sql,$canshu);
|
|
|
return \Yz::Return(true,'',['list'=>$query,'count'=>$count[0]->c]);
|
|
|
|
|
|
}
|
|
|
//检测是否有登记预约记录
|
|
|
public function CheckAppointment($name,$id_card_num,$type){
|
|
|
if(strlen($id_card_num)>0){
|
|
|
date_default_timezone_set('PRC');
|
|
|
$currentYear = date('Y');
|
|
|
$firstDay = date('Y-01-01', strtotime($currentYear));
|
|
|
$lastDay = date('Y-12-31', strtotime($currentYear));
|
|
|
|
|
|
|
|
|
//查询预约登记表
|
|
|
if($type==2 and $this->isOver65($id_card_num)===false){
|
|
|
return \Yz::echoError1("年龄不满足条件");
|
|
|
}
|
|
|
$c=DB::table('appointment_record as a')
|
|
|
->leftJoin('medical_institution as b', 'a.org_id', '=', 'b.id')
|
|
|
->select(['a.id','a.org_id','a.id_card_num','a.created_at as insertime','b.org_name'])
|
|
|
->where(['a.id_card_num'=>$id_card_num,'a.type'=>$type,['a.created_at','>=',$firstDay],['a.created_at','<=',$lastDay]])->whereIn('a.status',[1,2])->get();
|
|
|
if(count($c)){
|
|
|
$result['status']=false;
|
|
|
$result['msg']='已体检过';
|
|
|
$result['info']=$c;
|
|
|
}else{
|
|
|
|
|
|
$gongwei= self::CheckGongWei($name,$id_card_num);
|
|
|
if( $gongwei['status']===false) {
|
|
|
$result['status'] = false;
|
|
|
$result['msg'] = $gongwei['msg'];
|
|
|
$result['GongWeiinfo'] = $gongwei['GongWeiinfo'];
|
|
|
return $result;
|
|
|
}
|
|
|
$result['status']=true;
|
|
|
$result['msg']='可以继续,本年度无免费体检记录';
|
|
|
$result['info']=$c;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}else{
|
|
|
$result['status']=false;
|
|
|
$result['msg']='用户证件号未传';
|
|
|
}
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
public function CheckGongWei($name,$id_card_num){
|
|
|
date_default_timezone_set('PRC');
|
|
|
$currentYear = date('Y');
|
|
|
$firstDay = date('Y-01-01', strtotime($currentYear));
|
|
|
$lastDay = date('Y-12-31', strtotime($currentYear));
|
|
|
$SendData='<com:queryCheckUp>
|
|
|
<!--Optional:-->
|
|
|
<xm>'.$name.'</xm>
|
|
|
<!--Optional:-->
|
|
|
<sfz>'.$id_card_num.'</sfz>
|
|
|
</com:queryCheckUp>';
|
|
|
|
|
|
$url = config('app.globals.GongWeiBaseUrl').'/jkdacp/webservice/DPService?wsdl';
|
|
|
$res=\Yz::XmlHttp($SendData,$url);
|
|
|
//如果没有返回queryCheckUp节点,返回异常
|
|
|
if(!isset($res['queryCheckUp'])) {
|
|
|
$result['status']=false;
|
|
|
$result['msg']='公卫接口异常';
|
|
|
$result['GongWeiinfo']=$res;
|
|
|
return $result;
|
|
|
}
|
|
|
$result=[];
|
|
|
if(isset($res['queryCheckUp']['tjrq']) and ($res['queryCheckUp']['tjrq']>=$firstDay and $res['queryCheckUp']['tjrq']<=$lastDay)){
|
|
|
$result['status']=false;
|
|
|
$result['msg']='公卫有记录';
|
|
|
$result['GongWeiinfo']=$res['queryCheckUp'];
|
|
|
}else{
|
|
|
$result['status']=true;
|
|
|
$result['msg']='公卫有无记录';
|
|
|
$result['GongWeiinfo']=$res['queryCheckUp'];
|
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
function isOver65($idCard) {
|
|
|
// 从身份证号中提取出生日期
|
|
|
$birthYear = substr($idCard, 6, 4);
|
|
|
$birthMonth = substr($idCard, 10, 2);
|
|
|
$birthDay = substr($idCard, 12, 2);
|
|
|
|
|
|
// 将出生日期转换为日期对象
|
|
|
$birthdate = new DateTime($birthYear . '-' . $birthMonth . '-' . $birthDay);
|
|
|
|
|
|
// 获取当前日期
|
|
|
$currentDate = new DateTime();
|
|
|
|
|
|
// 计算年龄差
|
|
|
$ageDiff = $birthdate->diff($currentDate)->y;
|
|
|
|
|
|
// 判断年龄是否大于65岁
|
|
|
if ($ageDiff > 65) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|