Files
zyt/server/app/api/controller/ChatController.php
T
2026-05-11 17:49:38 +08:00

76 lines
2.8 KiB
PHP
Executable File

<?php
namespace app\api\controller;
use app\api\logic\ChatNotifyLogic;
use think\facade\Db;
/**
* 聊天相关接口(C端-患者)
*/
class ChatController extends BaseApiController
{
public array $notNeedLogin = ['notifyOpen', 'notifyClose', 'logAvPermission'];
/**
* 上报音视频权限拒绝日志
* 患者小程序请求摄像头/麦克风权限被拒绝,且用户点击「取消」未前往设置页时调用
*/
public function logAvPermission()
{
$patientId = trim((string) ($this->request->post('patient_id', '')));
$doctorId = trim((string) ($this->request->post('doctor_id', '')));
$deniedScope = trim((string) ($this->request->post('denied_scope', '')));
$scene = trim((string) ($this->request->post('scene', '')));
$action = trim((string) ($this->request->post('action', 'cancel')));
$wxVersion = trim((string) ($this->request->post('wx_version', '')));
Db::name('av_permission_log')->insert([
'patient_id' => $patientId,
'doctor_id' => $doctorId,
'denied_scope' => $deniedScope ?: 'unknown',
'scene' => $scene ?: 'unknown',
'action' => in_array($action, ['cancel', 'open_setting']) ? $action : 'cancel',
'wx_version' => $wxVersion,
'create_time' => time(),
]);
return $this->success('已记录');
}
/**
* 患者打开会话时通知医生
* 无需登录,通过参数传递
*/
public function notifyOpen()
{
$doctorId = (int) ($this->request->post('doctor_id') ?: $this->request->post('doctorId'));
$patientId = trim((string) ($this->request->post('patient_id') ?: $this->request->post('patientId') ?: ''));
$patientName = trim((string) ($this->request->post('patient_name') ?: $this->request->post('patientName') ?: '患者'));
if ($doctorId <= 0) {
return $this->fail('医生ID无效');
}
ChatNotifyLogic::addNotify($doctorId, $patientId ?: '0', $patientName);
return $this->success('已通知');
}
/**
* 患者离开会话页时通知医生(管理后台轮询 + 可与 IM 信令配合)
*/
public function notifyClose()
{
$doctorId = (int) ($this->request->post('doctor_id') ?: $this->request->post('doctorId'));
$patientId = trim((string) ($this->request->post('patient_id') ?: $this->request->post('patientId') ?: ''));
$patientName = trim((string) ($this->request->post('patient_name') ?: $this->request->post('patientName') ?: '患者'));
if ($doctorId <= 0) {
return $this->fail('医生ID无效');
}
ChatNotifyLogic::addPatientLeftNotify($doctorId, $patientId ?: '0', $patientName);
return $this->success('已通知');
}
}