parent
92955a80b1
commit
a2198832b3
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\Admin\YeWu;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Admin\YeWu\HealthCheckupService;
|
||||
|
||||
class HealthCheckupController extends Controller
|
||||
{
|
||||
//创建体检记录
|
||||
public function CreateRecord(){
|
||||
$CheckupInfo=request('CheckupInfo');
|
||||
if(!$CheckupInfo) return \Yz::echoError1('检查信息为空');
|
||||
if(!$CheckupInfo['name']) return \Yz::echoError1('姓名不能为空');
|
||||
if(!isset($CheckupInfo['id_card_num'])) return \Yz::echoError1('id_card_num不能为空');
|
||||
if(!isset($CheckupInfo['type'])) return \Yz::echoError1('type不能为空');
|
||||
if(!isset($CheckupInfo['institution_id'])) return \Yz::echoError1('institution_id不能为空');
|
||||
$s=app()->make(HealthCheckupService::class);
|
||||
return $s->CreateRecord($CheckupInfo);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
<?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));
|
||||
|
||||
//检查今年是否体检过
|
||||
$s=app()->make(PersonService::class);
|
||||
$check=$s->GetPersonRecode(['id_num'=>$CheckupInfo['id_card_num']]);
|
||||
|
||||
if(!$check['status']) return $check;
|
||||
|
||||
$status=false;
|
||||
DB::beginTransaction(); // 开始事务
|
||||
try {
|
||||
// 执行数据库操作
|
||||
if($CheckupInfo['type']==1){
|
||||
//如果体检类型为健康证 更新预约记录表
|
||||
$u= DB::table('appointment_record')
|
||||
->where([
|
||||
'id_card_num'=>$CheckupInfo['id_card_num'],
|
||||
'org_id'=>$CheckupInfo['institution_id'],
|
||||
'status'=>1
|
||||
])->whereBetween('created_at',[$firstDay,$lastDay])->update(['status'=>2]);
|
||||
|
||||
|
||||
}
|
||||
$u2=DB::table('examination_records')->insert([
|
||||
"id_card_num"=>$CheckupInfo['id_card_num'],
|
||||
"type"=>$CheckupInfo['type'],
|
||||
"institution_id"=>$CheckupInfo['institution_id']
|
||||
]);
|
||||
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(); // 回滚事务
|
||||
|
||||
|
||||
}
|
||||
|
||||
if($status){
|
||||
return \Yz::Return(true,'ok',[]);
|
||||
}else{
|
||||
return \Yz::echoError1("操作失败");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
Loading…
Reference in New Issue