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.
117 lines
3.9 KiB
PHP
117 lines
3.9 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'],
|
|
"id_card_num"=>$CheckupInfo['id_card_num'],
|
|
"type"=>$CheckupInfo['type'],
|
|
"institution_id"=>$org_id[0]->id,
|
|
"tijian_time"=>$CheckupInfo['tijian_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("未找到记录");
|
|
}
|
|
|
|
|
|
}
|
|
}
|