更新
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\doctor\Roster;
|
||||
|
||||
/**
|
||||
* 医生逻辑层
|
||||
* Class DoctorLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class DoctorLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 获取医生列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public static function getDoctorList($params = [])
|
||||
{
|
||||
$page_no = $params['page_no'] ?? 1;
|
||||
$page_size = $params['page_size'] ?? 10;
|
||||
$keyword = $params['keyword'] ?? '';
|
||||
|
||||
$offset = ($page_no - 1) * $page_size;
|
||||
|
||||
// 通过中间表 zyt_admin_role 查询 role_id = 1 的医生
|
||||
$adminIds = AdminRole::where('role_id', 1)->column('admin_id');
|
||||
|
||||
if (empty($adminIds)) {
|
||||
return [
|
||||
'lists' => [],
|
||||
'count' => 0,
|
||||
'page_no' => $page_no,
|
||||
'page_size' => $page_size
|
||||
];
|
||||
}
|
||||
|
||||
$query = Admin::whereIn('id', $adminIds)
|
||||
->where('disable', 0);
|
||||
|
||||
// 搜索关键词
|
||||
if (!empty($keyword)) {
|
||||
$query->where('name|account', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
|
||||
$lists = $query->field(['id', 'name', 'account', 'avatar'])
|
||||
->limit($offset, $page_size)
|
||||
->order('id asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 处理医生数据
|
||||
$doctors = [];
|
||||
foreach ($lists as $doctor) {
|
||||
$doctors[] = [
|
||||
'id' => $doctor['id'],
|
||||
'name' => $doctor['name'],
|
||||
'account' => $doctor['account'],
|
||||
'avatar' => $doctor['avatar'] ?? '',
|
||||
'specialty' => '医生', // 可根据需要扩展
|
||||
'title' => '医生', // 可根据需要扩展
|
||||
'rating' => '9.8', // 可根据需要从其他表获取
|
||||
];
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
$countQuery = Admin::whereIn('id', $adminIds)
|
||||
->where('disable', 0);
|
||||
|
||||
if (!empty($keyword)) {
|
||||
$countQuery->where('name|account', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
|
||||
$count = $countQuery->count();
|
||||
|
||||
return [
|
||||
'lists' => $doctors,
|
||||
'count' => $count,
|
||||
'page_no' => $page_no,
|
||||
'page_size' => $page_size
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取医生详情
|
||||
* @param int $doctorId
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getDoctorDetail($doctorId)
|
||||
{
|
||||
// 检查该医生是否有医生角色(role_id = 1)
|
||||
$hasRole = AdminRole::where('admin_id', $doctorId)
|
||||
->where('role_id', 1)
|
||||
->exists();
|
||||
|
||||
if (!$hasRole) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$doctor = Admin::where('id', $doctorId)
|
||||
->where('disable', 0)
|
||||
->field(['id', 'name', 'account', 'avatar', 'mobile', 'email'])
|
||||
->find();
|
||||
|
||||
if (!$doctor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$doctorData = $doctor->toArray();
|
||||
|
||||
return [
|
||||
'id' => $doctorData['id'],
|
||||
'name' => $doctorData['name'],
|
||||
'account' => $doctorData['account'],
|
||||
'avatar' => $doctorData['avatar'] ?? '',
|
||||
'mobile' => $doctorData['mobile'] ?? '',
|
||||
'email' => $doctorData['email'] ?? '',
|
||||
'specialty' => '医生',
|
||||
'title' => '医生',
|
||||
'rating' => '4.8',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取医生排班
|
||||
* @param int $doctorId
|
||||
* @param string $date
|
||||
* @return array
|
||||
*/
|
||||
public static function getDoctorRoster($doctorId, $date)
|
||||
{
|
||||
// 检查该医生是否有医生角色
|
||||
$hasRole = AdminRole::where('admin_id', $doctorId)
|
||||
->where('role_id', 1)
|
||||
->exists();
|
||||
|
||||
if (!$hasRole) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rosters = Roster::where('doctor_id', $doctorId)
|
||||
->where('date', $date)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $rosters;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user