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.
151 lines
5.4 KiB
PHP
151 lines
5.4 KiB
PHP
<?php
|
|
namespace App\Services\Admin\YeWu;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Services\mH5\PersonService;
|
|
|
|
class HealthCheckupService
|
|
{
|
|
//创建体检记录
|
|
public function CreateRecord($CheckupInfo){
|
|
date_default_timezone_set('PRC');
|
|
$currentYear = date('Y');
|
|
$firstDay = date('Y-01-01', strtotime($currentYear));
|
|
$lastDay = date('Y-12-31', strtotime($currentYear));
|
|
|
|
|
|
//如果此次报告内容是免费类型,则检查今年是否进行过免费体检
|
|
// if($CheckupInfo['fee_type']==0){
|
|
// $s=app()->make(PersonService::class);
|
|
// $check=$s->GetPersonRecode(['id_num'=>$CheckupInfo['id_card_num']]);
|
|
//
|
|
// if(!$check['status']) return $check;
|
|
// }
|
|
|
|
$org_id=DB::select("select id from medical_institution where sn=?",[$CheckupInfo['institution_sn']]);
|
|
if(count($org_id)!=1) return \Yz::echoError1('机构码不存在');
|
|
$status=false;
|
|
|
|
DB::beginTransaction(); // 开始事务
|
|
try {
|
|
// 执行数据库操作
|
|
if($CheckupInfo['type']==1){
|
|
//如果体检类型为健康证 更新预约记录表
|
|
$u= DB::table('appointment_record')
|
|
->where([
|
|
'id_card_num'=>$CheckupInfo['id_card_num'],
|
|
'org_id'=>$org_id[0]->id,
|
|
'status'=>1
|
|
])->whereBetween('created_at',[$firstDay,$lastDay])->update(['status'=>2]);
|
|
|
|
|
|
}
|
|
|
|
//检查体检流水号是否存在,存在禁止再次插入。
|
|
$check_cunzai=DB::table('examination_records')->where('tijian_num',$CheckupInfo['tijian_num'])->get();
|
|
if(count($check_cunzai)>0) return \Yz::echoError1('此体检号已经存在,禁止创建');
|
|
|
|
$u2=DB::table('examination_records')->insert([
|
|
"name"=>$CheckupInfo['name'],
|
|
"sex"=>$CheckupInfo['sex'],
|
|
"tel"=>$CheckupInfo['tel'],
|
|
"id_card_num"=>$CheckupInfo['id_card_num'],
|
|
"type"=>$CheckupInfo['type'],
|
|
"industry_type"=>$CheckupInfo['industry_type'],
|
|
"institution_id"=>$org_id[0]->id,
|
|
"tijian_time"=>$CheckupInfo['tijian_time'],
|
|
"register_time"=>$CheckupInfo['register_time'],//登记时间
|
|
"tijian_num"=>$CheckupInfo['tijian_num'],
|
|
"report_content"=>json_encode($CheckupInfo['report_content']),
|
|
"fee_type"=>$CheckupInfo['fee_type']
|
|
]);
|
|
if($CheckupInfo['type']==1){
|
|
|
|
if($u==1 and $u2==true){
|
|
|
|
DB::commit(); // 提交事务
|
|
$status=true;
|
|
}else{
|
|
|
|
DB::rollBack(); // 回滚事务
|
|
}
|
|
}else{
|
|
if($u2){
|
|
|
|
DB::commit(); // 提交事务
|
|
$status=true;
|
|
}else{
|
|
DB::rollBack(); // 回滚事务
|
|
|
|
}
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
DB::rollBack(); // 回滚事务
|
|
dd($e);
|
|
|
|
}
|
|
|
|
if($status){
|
|
return \Yz::Return(true,'记录完成',["num"=>$CheckupInfo['tijian_num']]);
|
|
}else{
|
|
return \Yz::echoError1("操作失败");
|
|
}
|
|
|
|
}
|
|
|
|
//保存文件返回存储路径
|
|
public function SaveFile($arr){
|
|
|
|
$date = date("Ymd");
|
|
$path = $arr['file']->store('public/'.$date);
|
|
return \Yz::Return(true,'',$path);
|
|
}
|
|
//查询个人查询体检记录列表
|
|
public function GetPersonCheckUpList($arr){
|
|
$list = DB::table("examination_records")->where(['id_card_num'=>$arr['id_card_num']])->get();
|
|
return \Yz::Return(true,'查询成功',['list'=>$list,'count'=>count($list)]);
|
|
}
|
|
//根据体检号查询体检详情
|
|
public function GetPersonCheckUpDetail($arr){
|
|
|
|
$detail=DB::table('examination_records')->where(['tijian_num'=>$arr['tijian_num']])->first();
|
|
if(!empty($detail)){
|
|
return \Yz::Return(true,'查询成功',$detail);
|
|
}else{
|
|
return \Yz::echoError1("未找到记录");
|
|
}
|
|
|
|
|
|
}
|
|
//获取体检记录列表
|
|
public function GetCheckUpList($arr){
|
|
$sql=' where 1=1';
|
|
$canshu=array();
|
|
|
|
if($arr['searchInfo']['dateRange']){
|
|
|
|
$sql=$sql . ' and a.tijian_time>=? and a.tijian_time<=? ';
|
|
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.institution_id=?';
|
|
array_push($canshu, $cha[0]->id);
|
|
}else{
|
|
if($arr['searchInfo']['orgId']){
|
|
|
|
$sql=$sql .' and a.institution_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 examination_records as a LEFT JOIN medical_institution as b on a.institution_id=b.id ".$sql." order by a.id desc limit ?,?",$canshu);
|
|
$count=DB::select("select count(*) as c from examination_records as a ".$sql,$canshu);
|
|
return \Yz::Return(true,'',['list'=>$query,'count'=>$count[0]->c]);
|
|
|
|
}
|
|
}
|