init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user