103 lines
3.1 KiB
PHP
103 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\lists\doctor;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\common\model\doctor\Appointment;
|
|
use app\common\lists\ListsSearchInterface;
|
|
|
|
/**
|
|
* 医生预约列表
|
|
* Class AppointmentLists
|
|
* @package app\adminapi\lists\doctor
|
|
*/
|
|
class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterface
|
|
{
|
|
/**
|
|
* @notes 设置搜索条件
|
|
* @return array
|
|
*/
|
|
public function setSearch(): array
|
|
{
|
|
$allowSearch = [
|
|
'=' => ['a.patient_id', 'a.doctor_id', 'a.status', 'a.appointment_date'],
|
|
];
|
|
|
|
// 处理日期范围搜索
|
|
if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) {
|
|
$this->searchWhere[] = ['a.appointment_date', 'between', [$this->params['start_date'], $this->params['end_date']]];
|
|
}
|
|
|
|
// 处理患者姓名搜索
|
|
if (!empty($this->params['patient_name'])) {
|
|
$this->searchWhere[] = ['u.patient_name', 'like', '%' . $this->params['patient_name'] . '%'];
|
|
}
|
|
|
|
// 处理医生姓名搜索
|
|
if (!empty($this->params['doctor_name'])) {
|
|
$this->searchWhere[] = ['ad.name', 'like', '%' . $this->params['doctor_name'] . '%'];
|
|
}
|
|
|
|
return $allowSearch;
|
|
}
|
|
|
|
/**
|
|
* @notes 获取列表
|
|
* @return array
|
|
*/
|
|
public function lists(): array
|
|
{
|
|
|
|
$lists = Appointment::alias('a')
|
|
->leftJoin('tcm_diagnosis u', 'a.patient_id = u.id')
|
|
->leftJoin('admin ad', 'a.doctor_id = ad.id')
|
|
->field('a.*, u.patient_name as patient_name, u.phone as patient_phone, ad.name as doctor_name')
|
|
->where($this->searchWhere)
|
|
->order('a.id', 'desc')
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()
|
|
->toArray();
|
|
|
|
// 添加状态和类型描述
|
|
foreach ($lists as &$item) {
|
|
$statusMap = [
|
|
1 => '已预约',
|
|
2 => '已取消',
|
|
3 => '已完成',
|
|
];
|
|
$item['status_desc'] = $statusMap[$item['status']] ?? '未知';
|
|
|
|
$typeMap = [
|
|
'video' => '视频问诊',
|
|
'text' => '图文问诊',
|
|
'phone' => '电话问诊',
|
|
];
|
|
$item['appointment_type_desc'] = $typeMap[$item['appointment_type']] ?? '未知';
|
|
|
|
// 格式化时间戳为日期时间
|
|
if (isset($item['create_time']) && is_numeric($item['create_time'])) {
|
|
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
|
}
|
|
if (isset($item['update_time']) && is_numeric($item['update_time'])) {
|
|
$item['update_time'] = date('Y-m-d H:i:s', $item['update_time']);
|
|
}
|
|
}
|
|
|
|
return $lists;
|
|
}
|
|
|
|
/**
|
|
* @notes 获取数量
|
|
* @return int
|
|
*/
|
|
public function count(): int
|
|
{
|
|
$query = Appointment::alias('a')
|
|
->leftJoin('tcm_diagnosis u', 'a.patient_id = u.id')
|
|
->leftJoin('admin ad', 'a.doctor_id = ad.id')
|
|
->where($this->searchWhere);
|
|
|
|
return $query->count();
|
|
}
|
|
}
|