51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace plugin\admin\app\repository;
|
|
|
|
use plugin\admin\app\model\OpmMwHospital;
|
|
use plugin\admin\app\repository\exception\EntityNotFoundException;
|
|
|
|
class HospitalRepository extends BaseRepository
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->model = new OpmMwHospital;
|
|
}
|
|
|
|
public static function new(): HospitalRepository
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
/**
|
|
* 只查询消毒灭菌医院 (ds_region_id != 0)
|
|
*/
|
|
public function scopedQuery()
|
|
{
|
|
return parent::scopedQuery()->where('ds_region_id', '!=', 0);
|
|
}
|
|
|
|
/**
|
|
* 获取医院列表(带数据权限)
|
|
*/
|
|
public function getListWithPermission(): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
return $this->scopedQuery()
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 根据ID查找医院
|
|
* @throws EntityNotFoundException
|
|
*/
|
|
public function findOrFail(int $id): OpmMwHospital
|
|
{
|
|
$hospital = $this->scopedQuery()->find($id);
|
|
if (!$hospital) {
|
|
throw new EntityNotFoundException('医院不存在');
|
|
}
|
|
return $hospital;
|
|
}
|
|
}
|