This commit is contained in:
Your Name
2026-03-16 15:08:28 +08:00
parent 294fee4d88
commit cda63b5ae2
26 changed files with 1695 additions and 492 deletions
@@ -70,6 +70,10 @@ class AdminLogic extends BaseLogic
'education' => $params['education'] ?? null,
'experience' => $params['experience'] ?? null,
'honors' => $params['honors'] ?? null,
'license_no' => $params['license_no'] ?? '',
'enable_image_consult' => $params['enable_image_consult'] ?? 1,
'enable_video_consult' => $params['enable_video_consult'] ?? 1,
'enable_charge' => $params['enable_charge'] ?? 0,
]);
// 角色
@@ -120,6 +124,10 @@ class AdminLogic extends BaseLogic
'education' => $params['education'] ?? null,
'experience' => $params['experience'] ?? null,
'honors' => $params['honors'] ?? null,
'license_no' => $params['license_no'] ?? '',
'enable_image_consult' => $params['enable_image_consult'] ?? 1,
'enable_video_consult' => $params['enable_video_consult'] ?? 1,
'enable_charge' => $params['enable_charge'] ?? 0,
];
// 头像
@@ -254,6 +262,7 @@ class AdminLogic extends BaseLogic
'multipoint_login', 'avatar',
'gender', 'age', 'phone', 'title', 'department',
'specialty', 'education', 'experience', 'honors',
'license_no', 'enable_image_consult', 'enable_video_consult', 'enable_charge',
'work_wechat_userid'
])->findOrEmpty($params['id'])->toArray();
@@ -1437,6 +1437,75 @@ class DiagnosisLogic extends BaseLogic
}
}
/**
* @notes 新建就诊卡(供小程序调用)
* patient_id 可选:有则复用(同患者多张卡),无则自动生成(新患者首张卡)
* @param array $params
* @return array|bool 成功返回 ['id'=>诊单ID, 'patient_id'=>患者ID],失败返回false
*/
public static function addCard(array $params)
{
try {
$userId = $params['user_id'] ?? 0;
unset($params['user_id']); // 诊单表无此字段,仅用于创建 view_record
$patientId = $params['patient_id'] ?? 0;
if (!$patientId) {
$params['patient_id'] = self::generatePatientId();
}
$params['status'] = 1;
// 处理既往史数组
if (isset($params['past_history']) && is_array($params['past_history'])) {
$params['past_history'] = implode(',', $params['past_history']);
}
$multiSelectFields = [
'diet_condition', 'body_feeling', 'sleep_condition', 'eye_condition',
'head_feeling', 'sweat_condition', 'skin_condition', 'urine_condition',
'stool_condition', 'kidney_condition', 'local_hospital_diagnosis'
];
foreach ($multiSelectFields as $field) {
if (isset($params[$field]) && is_array($params[$field])) {
$params[$field] = implode(',', $params[$field]);
}
}
if (isset($params['tongue_images']) && is_array($params['tongue_images'])) {
$params['tongue_images'] = json_encode($params['tongue_images'], JSON_UNESCAPED_UNICODE);
}
if (isset($params['report_files']) && is_array($params['report_files'])) {
$params['report_files'] = json_encode($params['report_files'], JSON_UNESCAPED_UNICODE);
}
if (isset($params['diagnosis_date'])) {
$params['diagnosis_date'] = is_numeric($params['diagnosis_date']) ? $params['diagnosis_date'] : strtotime($params['diagnosis_date']);
}
$model = Diagnosis::create($params);
self::createPatientTrtcAccount($model->patient_id);
// 关联 diagnosis_view_records,便于用户通过 User::with('diagnosis') 获取就诊卡
if ($userId) {
$now = time();
\app\common\model\DiagnosisViewRecord::create([
'user_id' => $userId,
'diagnosis_id' => $model->id,
'patient_id' => $model->patient_id,
'share_user_id' => 0,
'view_count' => 1,
'first_view_time' => $now,
'last_view_time' => $now,
'is_confirmed' => 0,
'create_time' => $now,
'update_time' => $now
]);
}
return ['id' => $model->id, 'patient_id' => $model->patient_id];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 更新就诊卡(供小程序调用)
* @param array $params
+19 -1
View File
@@ -11,7 +11,7 @@ use app\api\logic\DoctorLogic;
*/
class DoctorController extends BaseApiController
{
public array $notNeedLogin = ['lists', 'detail'];
public array $notNeedLogin = ['lists', 'detail', 'reviews'];
/**
* @notes 获取医生列表
@@ -70,4 +70,22 @@ class DoctorController extends BaseApiController
$result = DoctorLogic::getDoctorRoster($doctorId, $date);
return $this->success('', $result);
}
/**
* @notes 获取医生评价列表
* @return \think\response\Json
*/
public function reviews()
{
$doctorId = $this->request->get('doctor_id', 0);
$pageNo = $this->request->get('page_no', 1);
$pageSize = $this->request->get('page_size', 10);
if (!$doctorId) {
return $this->fail('医生ID不能为空');
}
$result = DoctorLogic::getDoctorReviews($doctorId, $pageNo, $pageSize);
return $this->success('', $result);
}
}
@@ -155,6 +155,74 @@ class TcmController extends BaseApiController
}
}
/**
* @notes 新建就诊卡(供小程序调用)
* @return \think\response\Json
*/
public function addCard()
{
$params = [
'user_id' => $this->userId,
'patient_id' => $this->request->post('patient_id'),
'patient_name' => $this->request->post('patient_name'),
'gender' => $this->request->post('gender'),
'age' => $this->request->post('age'),
'id_card' => $this->request->post('id_card'),
'height' => $this->request->post('height'),
'weight' => $this->request->post('weight'),
'systolic_pressure' => $this->request->post('systolic_pressure'),
'diastolic_pressure' => $this->request->post('diastolic_pressure'),
'fasting_blood_sugar' => $this->request->post('fasting_blood_sugar'),
'diabetes_discovery_year' => $this->request->post('diabetes_discovery_year'),
'local_hospital_diagnosis' => $this->request->post('local_hospital_diagnosis'),
'local_hospital_name' => $this->request->post('local_hospital_name'),
'local_hospital_visit_date' => $this->request->post('local_hospital_visit_date'),
'diagnosis_date' => $this->request->post('diagnosis_date'),
'diagnosis_type' => $this->request->post('diagnosis_type'),
'syndrome_type' => $this->request->post('syndrome_type'),
'diabetes_type' => $this->request->post('diabetes_type'),
'appetite' => $this->request->post('appetite'),
'water_intake' => $this->request->post('water_intake'),
'diet_condition' => $this->request->post('diet_condition'),
'weight_change' => $this->request->post('weight_change'),
'body_feeling' => $this->request->post('body_feeling'),
'sleep_condition' => $this->request->post('sleep_condition'),
'eye_condition' => $this->request->post('eye_condition'),
'head_feeling' => $this->request->post('head_feeling'),
'sweat_condition' => $this->request->post('sweat_condition'),
'skin_condition' => $this->request->post('skin_condition'),
'urine_condition' => $this->request->post('urine_condition'),
'stool_condition' => $this->request->post('stool_condition'),
'kidney_condition' => $this->request->post('kidney_condition'),
'fatty_liver_degree' => $this->request->post('fatty_liver_degree'),
'past_history' => $this->request->post('past_history'),
'trauma_history' => $this->request->post('trauma_history'),
'surgery_history' => $this->request->post('surgery_history'),
'allergy_history' => $this->request->post('allergy_history'),
'family_history' => $this->request->post('family_history'),
'pregnancy_history' => $this->request->post('pregnancy_history'),
'symptoms' => $this->request->post('symptoms'),
'tongue_coating' => $this->request->post('tongue_coating'),
'tongue_images' => $this->request->post('tongue_images'),
'report_files' => $this->request->post('report_files'),
'pulse' => $this->request->post('pulse'),
'treatment_principle' => $this->request->post('treatment_principle'),
'prescription' => $this->request->post('prescription'),
'doctor_advice' => $this->request->post('doctor_advice'),
'remark' => $this->request->post('remark')
];
// patient_id 可选:不传则创建时自动生成(新患者首张就诊卡)
try {
$result = DiagnosisLogic::addCard($params);
if ($result === false) {
return $this->fail(DiagnosisLogic::getError());
}
return $this->success('创建成功', $result);
} catch (\Exception $e) {
return $this->fail($e->getMessage());
}
}
/**
* @notes 更新就诊卡(供小程序调用)
* @return \think\response\Json
+76 -7
View File
@@ -6,6 +6,7 @@ use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminRole;
use app\common\model\doctor\Roster;
use app\common\model\doctor\Appointment;
/**
* 医生逻辑层
@@ -86,7 +87,7 @@ class DoctorLogic extends BaseLogic
}
/**
* @notes 获取医生详情
* @notes 获取医生详情(含完整档案信息)
* @param int $doctorId
* @return array|null
*/
@@ -95,7 +96,7 @@ class DoctorLogic extends BaseLogic
// 检查该医生是否有医生角色(role_id = 1)
$hasRole = AdminRole::where('admin_id', $doctorId)
->where('role_id', 1)
->exists();
->count() > 0;
if (!$hasRole) {
return null;
@@ -103,7 +104,7 @@ class DoctorLogic extends BaseLogic
$doctor = Admin::where('id', $doctorId)
->where('disable', 0)
->field(['id', 'name', 'account', 'avatar', 'mobile', 'email'])
->field(['id', 'name', 'account', 'avatar','specialty','license_no','enable_image_consult','enable_video_consult','enable_charge'])
->find();
if (!$doctor) {
@@ -112,6 +113,12 @@ class DoctorLogic extends BaseLogic
$doctorData = $doctor->toArray();
// 统计患者数(已完成预约,去重)
$patientIds = Appointment::where('doctor_id', $doctorId)
->where('status', 3)
->column('patient_id');
$patientCount = count(array_unique(array_filter($patientIds)));
return [
'id' => $doctorData['id'],
'name' => $doctorData['name'],
@@ -119,9 +126,71 @@ class DoctorLogic extends BaseLogic
'avatar' => $doctorData['avatar'] ?? '',
'mobile' => $doctorData['mobile'] ?? '',
'email' => $doctorData['email'] ?? '',
'specialty' => '医生',
'title' => '医生',
'rating' => '4.8',
'license_no' => $doctorData['license_no'] ?? '',
'enable_image_consult' => $doctorData['enable_image_consult'] ?? 1,
'enable_video_consult' => $doctorData['enable_video_consult'] ?? 1,
'enable_charge' => $doctorData['enable_charge'] ?? 0,
'specialty' => '中医',
'title' => '主任医师',
'hospital' => '甄养堂互联网医院',
'experience' => '24年临床经验',
'rating' => '4.9',
'patient_count' => $patientCount,
'papers' => 15,
'about' => $doctorData['specialty'] ?? '擅长运用传统中医理论与现代诊断相结合,专注于慢性炎症及呼吸系统健康的调理。精通草本方剂,致力于为患者提供个性化的整体康复方案。',
'expertise' => [
['icon' => 'psychiatry', 'title' => '草本药方', 'desc' => '为整体康复提供量身定制的草本处方。'],
['icon' => 'eco', 'title' => '草本药方', 'desc' => '为整体康复提供量身定制的草本处方。'],
['icon' => 'vital_signs', 'title' => '切脉诊断', 'desc' => '运用传统方法对全身平衡和器官健康进行深度触诊评估。', 'wide' => true],
],
];
}
/**
* @notes 获取医生评价列表
* @param int $doctorId
* @param int $pageNo
* @param int $pageSize
* @return array
*/
public static function getDoctorReviews($doctorId, $pageNo = 1, $pageSize = 10)
{
$hasRole = AdminRole::where('admin_id', $doctorId)
->where('role_id', 1)
->count() > 0;
if (!$hasRole) {
return ['lists' => [], 'count' => 0];
}
// 默认评价数据(后续可扩展为独立评价表)
$defaultReviews = [
[
'id' => 1,
'patient_initials' => 'JS',
'patient_name' => 'James S.',
'rating' => 5,
'content' => '李医生对我慢性疲劳的治疗改变了我的生活。他在建议方剂之前足足听我倾诉了45分钟。真是一位大师级的人物。',
'create_time' => '2天前',
],
[
'id' => 2,
'patient_initials' => 'ML',
'patient_name' => 'Mei Ling',
'rating' => 5,
'content' => '非常专业,知识渊博。针灸疗程显著缓解了我的偏头痛。非常推荐这家医院。',
'create_time' => '1周前',
],
];
$offset = ($pageNo - 1) * $pageSize;
$lists = array_slice($defaultReviews, $offset, $pageSize);
return [
'lists' => $lists,
'count' => count($defaultReviews),
'page_no' => $pageNo,
'page_size' => $pageSize,
];
}
@@ -136,7 +205,7 @@ class DoctorLogic extends BaseLogic
// 检查该医生是否有医生角色
$hasRole = AdminRole::where('admin_id', $doctorId)
->where('role_id', 1)
->exists();
->count() > 0;
if (!$hasRole) {
return [];
+1
View File
@@ -70,6 +70,7 @@ class UserLogic extends BaseLogic
*/
public static function info(int $userId)
{
$user = User::where(['id' => $userId])
->with('diagnosis')
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,age,create_time,user_money')
+7
View File
@@ -0,0 +1,7 @@
-- 医生表(la_admin)新增字段:执业证书编号、图文问诊、视频问诊、收费开关
-- 若项目使用 zyt_ 前缀,请将 la_admin 替换为 zyt_admin 后执行
ALTER TABLE `la_admin` ADD COLUMN `license_no` varchar(100) NULL DEFAULT '' COMMENT '执业证书编号';
ALTER TABLE `la_admin` ADD COLUMN `enable_image_consult` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否开启图文问诊:0-关闭 1-开启';
ALTER TABLE `la_admin` ADD COLUMN `enable_video_consult` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否开启视频问诊:0-关闭 1-开启';
ALTER TABLE `la_admin` ADD COLUMN `enable_charge` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否开启收费:0-关闭 1-开启';