igengx
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
namespace app\adminapi\controller;
|
||||
|
||||
use app\adminapi\logic\LoginLogic;
|
||||
use app\adminapi\service\DesktopSessionService;
|
||||
use app\adminapi\validate\LoginValidate;
|
||||
use app\common\enum\AdminTerminalEnum;
|
||||
|
||||
/**
|
||||
* 管理员登录控制器
|
||||
@@ -41,6 +43,20 @@ class LoginController extends BaseAdminController
|
||||
return $this->data((new LoginLogic())->login($params));
|
||||
}
|
||||
|
||||
/** 工作站在线心跳 */
|
||||
public function desktopHeartbeat()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->fail('请使用 POST 请求');
|
||||
}
|
||||
if ((int) ($this->adminInfo['terminal'] ?? 0) !== AdminTerminalEnum::WORKSTATION) {
|
||||
return $this->fail('请重新登录桌面工作站', [], -1);
|
||||
}
|
||||
$expiresAt = DesktopSessionService::update((string) $this->adminInfo['token'], 'heartbeat');
|
||||
return $expiresAt ? $this->data(['desktop_expires_at' => $expiresAt])
|
||||
: $this->fail('登录已过期,请重新登录', [], -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取企业微信登录配置(前端构造OAuth URL/扫码用)
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,11 @@ namespace app\adminapi\controller\setting\system;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\setting\system\DesktopSessionLists;
|
||||
use app\adminapi\lists\setting\system\LogLists;
|
||||
use app\adminapi\logic\auth\AuthLogic;
|
||||
use app\adminapi\service\DesktopSessionService;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
@@ -35,4 +39,17 @@ class LogController extends BaseAdminController
|
||||
{
|
||||
return $this->dataLists(new LogLists());
|
||||
}
|
||||
}
|
||||
|
||||
public function desktopSessions()
|
||||
{
|
||||
// 未配置菜单时,通用中间件会放过未登记的接口。
|
||||
if ((int) ($this->adminInfo['root'] ?? 0) !== 1
|
||||
&& !in_array('setting.system.log/desktopSessions', AuthLogic::getAuthByAdminId($this->adminId), true)) {
|
||||
return $this->fail('权限不足,无法查看桌面登录记录');
|
||||
}
|
||||
|
||||
$lists = new DesktopSessionLists();
|
||||
DesktopSessionService::settleDue();
|
||||
return Db::transaction(fn () => $this->dataLists($lists));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,7 @@ use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\logic\tcm\PrescriptionLogic;
|
||||
use app\adminapi\validate\tcm\PrescriptionValidate;
|
||||
use app\common\service\esign\DoctorEsignIdentityService;
|
||||
use app\common\service\esign\PrescriptionCaSigningSettings;
|
||||
use app\common\service\esign\PrescriptionEsignService;
|
||||
use app\common\service\esign\PrescriptionReviewEsignService;
|
||||
|
||||
@@ -102,6 +103,27 @@ class PrescriptionController extends BaseAdminController
|
||||
return $this->data($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 上传处方送审
|
||||
*/
|
||||
public function submitForReview()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->fail('请使用 POST 上传处方');
|
||||
}
|
||||
$rawId = $this->request->post('id');
|
||||
$id = (is_int($rawId) || is_string($rawId))
|
||||
? filter_var($rawId, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]) : false;
|
||||
if ($id === false) {
|
||||
return $this->fail('处方ID无效');
|
||||
}
|
||||
try {
|
||||
return $this->data(PrescriptionLogic::submitForReview($id, (int) $this->adminId, $this->adminInfo));
|
||||
} catch (\Throwable $error) {
|
||||
return $this->fail($error instanceof \DomainException ? $error->getMessage() : '处方上传失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 审核处方(通过 / 驳回,驳回即作废)
|
||||
*/
|
||||
@@ -121,13 +143,8 @@ class PrescriptionController extends BaseAdminController
|
||||
|
||||
$msg = $params['action'] === 'reject' ? '已驳回并作废处方' : '审核通过';
|
||||
$wecom = PrescriptionLogic::consumeLastAuditWecomNotify();
|
||||
$data = [];
|
||||
if (is_array($wecom)) {
|
||||
$data['wecom_notify_ok'] = !empty($wecom['ok']);
|
||||
if (empty($wecom['ok']) && !empty($wecom['message'])) {
|
||||
$data['wecom_notify_hint'] = (string) $wecom['message'];
|
||||
}
|
||||
}
|
||||
// The audit is already committed. The notification diagnostic belongs in server logs.
|
||||
$data = $wecom === null ? [] : ['wecom_notify_ok' => !empty($wecom['ok'])];
|
||||
|
||||
return $this->success($msg, $data);
|
||||
}
|
||||
@@ -180,7 +197,11 @@ class PrescriptionController extends BaseAdminController
|
||||
if ($id <= 0) {
|
||||
return $this->fail('处方ID不能为空');
|
||||
}
|
||||
$ok = PrescriptionLogic::void($id, $this->adminId, $this->adminInfo);
|
||||
$pendingOnly = $this->request->post('pending_only', false, null);
|
||||
if (!is_bool($pendingOnly)) {
|
||||
return $this->fail('作废参数无效');
|
||||
}
|
||||
$ok = PrescriptionLogic::void($id, $this->adminId, $this->adminInfo, $pendingOnly);
|
||||
if (!$ok) {
|
||||
return $this->fail(PrescriptionLogic::getError());
|
||||
}
|
||||
@@ -191,6 +212,29 @@ class PrescriptionController extends BaseAdminController
|
||||
{
|
||||
return $this->data(PrescriptionEsignService::capability());
|
||||
}
|
||||
|
||||
/** @notes 修改处方 CA 签名设置 */
|
||||
public function esignSetConfig()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return $this->fail('请使用 POST 修改 CA 签名设置');
|
||||
}
|
||||
if ((int) ($this->adminInfo['root'] ?? 0) !== 1) {
|
||||
return $this->fail('仅超级管理员可以修改 CA 签名设置');
|
||||
}
|
||||
$enabled = $this->request->post('enabled', null, null);
|
||||
if (!is_bool($enabled)) {
|
||||
return $this->fail('CA 签名开关必须为布尔值');
|
||||
}
|
||||
try {
|
||||
PrescriptionCaSigningSettings::setEnabled($enabled, $this->adminId);
|
||||
return $this->data(PrescriptionEsignService::capability());
|
||||
} catch (\DomainException $error) {
|
||||
return $this->fail($error->getMessage());
|
||||
} catch (\Throwable) {
|
||||
return $this->fail('CA 签名设置暂时无法保存,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
public function esignStatus()
|
||||
{
|
||||
@@ -238,11 +282,11 @@ class PrescriptionController extends BaseAdminController
|
||||
if ($confirm ? !$this->request->isPost() : !$this->request->isGet()) {
|
||||
return $this->fail($confirm ? '请使用 POST 请求' : '请使用 GET 请求');
|
||||
}
|
||||
$params = $confirm ? $this->request->post() : $this->request->get();
|
||||
$params = $confirm ? $this->request->post(false) : $this->request->get();
|
||||
$id = (int) ($params['id'] ?? 0);
|
||||
$orderId = (int) ($params['order_id'] ?? 0);
|
||||
$actor = (int) $this->adminId;
|
||||
$verifyOnly = $params['verify_only'] ?? false;
|
||||
$verifyOnly = array_key_exists('verify_only', $params) ? $params['verify_only'] : false;
|
||||
if ($id <= 0 || $orderId < 0 || !is_bool($verifyOnly)) {
|
||||
return $this->fail('审核签署参数无效');
|
||||
}
|
||||
@@ -300,9 +344,16 @@ class PrescriptionController extends BaseAdminController
|
||||
}
|
||||
if ($operation === 'complete') {
|
||||
ignore_user_abort(true);
|
||||
$data = DoctorEsignIdentityService::complete((int) $this->adminId, $input);
|
||||
} else {
|
||||
$body = $this->request->post(false);
|
||||
$signerName = $body['signer_name'] ?? null;
|
||||
if (array_key_exists('signer_name', $body) && (!is_string($signerName) || strlen($signerName) > 200)) {
|
||||
return $this->fail('证件姓名格式无效');
|
||||
}
|
||||
$data = DoctorEsignIdentityService::start((int) $this->adminId, $input, $signerName);
|
||||
}
|
||||
return $this->data(DoctorEsignIdentityService::{$operation}((int) $this->adminId, $input))
|
||||
->header(['Cache-Control' => 'private, no-store']);
|
||||
return $this->data($data)->header(['Cache-Control' => 'private, no-store']);
|
||||
} catch (\Throwable $error) {
|
||||
return $this->fail($error instanceof \DomainException ? $error->getMessage() : '医师认证暂不可用,请稍后重试');
|
||||
}
|
||||
|
||||
@@ -78,20 +78,22 @@ class AuthMiddleware
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$adminAuthCache = new AdminAuthCache($request->adminInfo['admin_id']);
|
||||
|
||||
// 当前访问路径
|
||||
$accessUri = strtolower($request->controller() . '/' . $request->action());
|
||||
if ($accessUri === 'tcm.prescription/esignconfig') {
|
||||
return $next($request); // Logged-in clients only receive signing capability flags.
|
||||
}
|
||||
if ($accessUri === 'tcm.prescription/esignsetconfig') {
|
||||
return JsonService::fail('仅超级管理员可以修改 CA 签名设置');
|
||||
}
|
||||
|
||||
$adminAuthCache = new AdminAuthCache($request->adminInfo['admin_id']);
|
||||
|
||||
// Explicit gate: these new endpoints must not use unregistered-route bypass.
|
||||
if (str_starts_with($accessUri, 'tcm.prescription/esign')) {
|
||||
$action = substr($accessUri, strlen('tcm.prescription/'));
|
||||
if ($action === 'esignconfig') {
|
||||
return $next($request); // Only exposes enabled + environment, to logged-in users.
|
||||
}
|
||||
$uris = $this->formatUrl($adminAuthCache->getAdminUri() ?? []);
|
||||
$writes = ['tcm.prescription/add', 'tcm.prescription/edit', 'cf.prescription/add', 'cf.prescription/edit',
|
||||
'tcm.diagnosis/chufang', 'tcm.diagnosis/kaifang'];
|
||||
$writes = PrescriptionLogic::REVIEW_SUBMIT_PERMISSIONS;
|
||||
$reads = array_merge($writes, ['tcm.prescription/detail', 'tcm.prescription/lists', 'cf.prescription/lists',
|
||||
'cf.prescription/detail', 'cf.prescription/audit', 'tcm.prescription/audit',
|
||||
'tcm.prescriptionorder/lists', 'tcm.prescriptionorder/detail', 'tcm.prescriptionorder/auditprescription']);
|
||||
@@ -275,6 +277,7 @@ class AuthMiddleware
|
||||
|
||||
$prescriptionWriteAliases = [
|
||||
'tcm.prescription/add' => PrescriptionLogic::PRESCRIBE_PERMISSIONS,
|
||||
'tcm.prescription/submitforreview' => PrescriptionLogic::REVIEW_SUBMIT_PERMISSIONS,
|
||||
'tcm.prescription/edit' => [
|
||||
'tcm.prescription/edit', 'cf.prescription/edit',
|
||||
'tcm.diagnosis/chufang', 'tcm.diagnosis/kaifang',
|
||||
@@ -351,6 +354,7 @@ class AuthMiddleware
|
||||
'tcm.prescription/delete',
|
||||
'tcm.prescription/void',
|
||||
'tcm.prescription/audit',
|
||||
'tcm.prescription/submitforreview',
|
||||
], true);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class LoginMiddleware
|
||||
}
|
||||
|
||||
//token临近过期,自动续期
|
||||
if ($adminInfo) {
|
||||
if ($adminInfo && (int) ($adminInfo['terminal'] ?? 0) !== AdminTerminalEnum::WORKSTATION) {
|
||||
//获取临近过期自动续期时长
|
||||
$beExpireDuration = AdminTokenService::renewalWindow($adminInfo['terminal'] ?? 0);
|
||||
//token续期
|
||||
@@ -93,6 +93,9 @@ class LoginMiddleware
|
||||
|
||||
private static function isWorkWechatBindExemptAction($request): bool
|
||||
{
|
||||
if (strtolower($request->controller() . '/' . $request->action()) === 'login/desktopheartbeat') {
|
||||
return true;
|
||||
}
|
||||
if (LoginLogic::isWorkWechatBindExemptActionName((string) $request->action())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ class OperationLog
|
||||
{
|
||||
$request = request();
|
||||
$accessUri = strtolower($request->controller() . '/' . $request->action());
|
||||
// 在线时间已在会话表内记录,定时心跳不产生操作日志。
|
||||
if ($accessUri === 'login/desktopheartbeat') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Temporary visual observations and rejected upload parameters must never
|
||||
// enter the generic request/response audit log if this listener is enabled.
|
||||
@@ -126,7 +130,7 @@ class OperationLog
|
||||
private function stripLargeLogFields(array &$data): void
|
||||
{
|
||||
foreach ($data as $key => &$value) {
|
||||
if ($key === 'auth_url') {
|
||||
if (in_array($key, ['auth_url', 'review_signature', 'signing_log'], true)) {
|
||||
unset($data[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,6 @@ class MyPatientOrderLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
if ($prescriptionIds !== []) {
|
||||
$prescriptions = Prescription::whereIn('id', $prescriptionIds)
|
||||
->whereNull('delete_time')
|
||||
->field(['id', 'creator_id', 'doctor_name'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($prescriptions as $prescription) {
|
||||
@@ -285,6 +284,7 @@ class MyPatientOrderLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
|
||||
foreach ($rows as &$row) {
|
||||
$prescription = $prescriptionMap[(int) ($row['prescription_id'] ?? 0)] ?? [];
|
||||
$row = PrescriptionOrderLogic::withReviewAvailability($row, $prescription);
|
||||
$doctorId = (int) ($prescription['creator_id'] ?? 0);
|
||||
$doctorName = trim((string) ($prescription['doctor_name'] ?? ''));
|
||||
$creatorId = (int) ($row['creator_id'] ?? 0);
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\lists\setting\system;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
use app\common\service\DataScope\DataScopeService;
|
||||
use app\common\service\JsonService;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use think\db\Query;
|
||||
use think\facade\Db;
|
||||
|
||||
class DesktopSessionLists extends BaseAdminDataLists implements ListsExtendInterface
|
||||
{
|
||||
use HasDataScopeFilter;
|
||||
|
||||
private Query $sessions;
|
||||
private DateTimeImmutable $now;
|
||||
private string $daySecondsSql;
|
||||
private ?array $summary = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->now = new DateTimeImmutable('now', new DateTimeZone('Asia/Shanghai'));
|
||||
$date = $this->request->get('date', $this->now->format('Y-m-d'));
|
||||
$day = is_string($date) && preg_match('/^\d{4}-\d{2}-\d{2}$/D', $date)
|
||||
? DateTimeImmutable::createFromFormat('!Y-m-d', $date, $this->now->getTimezone())
|
||||
: false;
|
||||
if (!$day || $day->format('Y-m-d') !== $date) {
|
||||
JsonService::throw('请选择有效的查询日期');
|
||||
}
|
||||
$keyword = $this->request->get('keyword', '');
|
||||
if (!is_string($keyword)) {
|
||||
JsonService::throw('请填写账号或姓名');
|
||||
}
|
||||
|
||||
$start = $day->getTimestamp();
|
||||
$end = $day->modify('+1 day')->getTimestamp();
|
||||
$now = $this->now->getTimestamp();
|
||||
// 所有会话最迟到下一次 05:00。用前一日下界限制登录时间索引的扫描范围。
|
||||
$this->sessions = Db::name('desktop_login_session')
|
||||
->where('login_time', '>=', $day->modify('-1 day')->getTimestamp())
|
||||
->where('login_time', '<', $end)
|
||||
->where('login_time', '<=', $now)
|
||||
// 同秒登录退出也应保留在登录当日,午夜退出归入前一天。
|
||||
->whereRaw("(login_time >= {$start} OR COALESCE(logout_time, {$now}) > {$start})");
|
||||
$this->daySecondsSql = "LEAST(COALESCE(logout_time, {$now}), {$end}) - GREATEST(login_time, {$start})";
|
||||
|
||||
if (trim($keyword) !== '') {
|
||||
$pattern = '%' . strtr(trim($keyword), ['!' => '!!', '%' => '!%', '_' => '!_']) . '%';
|
||||
$this->sessions->whereRaw("(account LIKE ? ESCAPE '!' OR name LIKE ? ESCAPE '!')", [$pattern, $pattern]);
|
||||
}
|
||||
if ((int) ($this->adminInfo['root'] ?? 0) !== 1) {
|
||||
$this->adminInfo['role_id'] = DataScopeService::roleIdsOf($this->adminId);
|
||||
}
|
||||
$this->applyDataScopeByOwner($this->sessions, 'admin_id');
|
||||
}
|
||||
|
||||
public function lists(): array
|
||||
{
|
||||
$rows = (clone $this->sessions)
|
||||
->field('id,admin_id,account,name,login_time,logout_time,end_reason,duration_seconds')
|
||||
->fieldRaw("({$this->daySecondsSql}) AS day_seconds")
|
||||
->order(['login_time' => 'desc', 'id' => 'desc'])
|
||||
->limit($this->limitOffset, $this->limitLength)->select()->toArray();
|
||||
foreach ($rows as &$row) {
|
||||
$login = (int) $row['login_time'];
|
||||
$logout = $row['logout_time'];
|
||||
$row['status'] = $logout === null ? 'online' : $row['end_reason'];
|
||||
$row['status_label'] = match ($row['status']) {
|
||||
'online' => '在线',
|
||||
'logout' => '已退出',
|
||||
'replaced' => '重新登录',
|
||||
'timeout' => '连接超时',
|
||||
'daily_cutoff' => '每日下线',
|
||||
'revoked' => '登录已撤销',
|
||||
default => '已结束',
|
||||
};
|
||||
$row['duration_seconds'] = $logout === null
|
||||
? $this->now->getTimestamp() - $login : (int) $row['duration_seconds'];
|
||||
$row['day_seconds'] = (int) $row['day_seconds'];
|
||||
$row['login_time'] = $this->now->setTimestamp($login)->format('Y-m-d H:i:s');
|
||||
$row['logout_time'] = $logout === null
|
||||
? null : $this->now->setTimestamp((int) $logout)->format('Y-m-d H:i:s');
|
||||
unset($row['end_reason']);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function summary(): array
|
||||
{
|
||||
return $this->summary ??= (clone $this->sessions)
|
||||
->fieldRaw("COUNT(*) AS session_count, COALESCE(SUM({$this->daySecondsSql}), 0) AS day_seconds")
|
||||
->find();
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return (int) $this->summary()['session_count'];
|
||||
}
|
||||
|
||||
public function extend(): array
|
||||
{
|
||||
return ['total_day_seconds' => (int) $this->summary()['day_seconds']];
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ use app\adminapi\logic\tcm\PrescriptionLogic;
|
||||
use app\adminapi\logic\tcm\PrescriptionOrderLogic;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\service\esign\PrescriptionEsignService;
|
||||
use think\db\Query;
|
||||
|
||||
/**
|
||||
* 处方列表
|
||||
@@ -157,7 +159,16 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$query->whereIn('audit_status', [0, 2]);
|
||||
break;
|
||||
case 'pending':
|
||||
$query->where('audit_status', '=', 0);
|
||||
$esignEnabled = PrescriptionEsignService::enabled();
|
||||
$query->where('audit_status', '=', 0)->where('review_submitted_at', '>', 0)->where('void_status', '=', 0)
|
||||
->where(static function (Query $q) use ($esignEnabled): void {
|
||||
$q->where('esign_status', 'signed')->whereOr(static function (Query $legacy) use ($esignEnabled): void {
|
||||
$legacy->where('esign_required', 0);
|
||||
if ($esignEnabled) {
|
||||
$legacy->where('esign_status', '<>', 'legacy');
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 'rejected':
|
||||
$query->where('audit_status', '=', 2);
|
||||
@@ -167,6 +178,18 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
}
|
||||
}
|
||||
|
||||
private function buildFilteredQuery(): Query
|
||||
{
|
||||
$query = Prescription::where($this->searchWhere)->whereNull('delete_time');
|
||||
$this->applyAuditFilter($query);
|
||||
$this->applySourceFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
$this->applyDataScopeByOwnerColumns($query, ['creator_id', 'assistant_id']);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 来源:system=系统代开(is_system_auto=1),manual=手工(0 或空)
|
||||
*/
|
||||
@@ -230,18 +253,13 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = Prescription::where($this->searchWhere);
|
||||
$this->applyAuditFilter($query);
|
||||
$this->applySourceFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
$this->applyDataScopeByOwnerColumns($query, ['creator_id', 'assistant_id']);
|
||||
$query = $this->buildFilteredQuery();
|
||||
|
||||
// 全局置顶:有业务订单且处方药材为空白/重复
|
||||
$candidateIds = (clone $query)->whereNull('delete_time')->column('id');
|
||||
$candidateIds = (clone $query)->column('id');
|
||||
$riskIds = $this->collectRiskPrescriptionIds(is_array($candidateIds) ? $candidateIds : []);
|
||||
|
||||
$listQuery = $query->whereNull('delete_time');
|
||||
$listQuery = $query;
|
||||
if ($riskIds !== []) {
|
||||
$riskIdStr = implode(',', array_map('intval', $riskIds));
|
||||
$listQuery->orderRaw("CASE WHEN id IN ({$riskIdStr}) THEN 0 ELSE 1 END ASC");
|
||||
@@ -257,7 +275,7 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$rejectedRx = [];
|
||||
$bizRejectRemark = [];
|
||||
$hasBizOrderRx = [];
|
||||
$hasReleasedOrderRx = [];
|
||||
$ordersByPrescription = [];
|
||||
if ($rxIds !== []) {
|
||||
$bizRejectRows = PrescriptionOrder::whereIn('prescription_id', $rxIds)
|
||||
->where('prescription_audit_status', 2)
|
||||
@@ -280,13 +298,12 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
|
||||
$orders = PrescriptionOrder::whereIn('prescription_id', $rxIds)
|
||||
->whereNull('delete_time')
|
||||
->field(['prescription_id', 'fulfillment_status'])
|
||||
->select();
|
||||
->field(['prescription_id', 'fulfillment_status', 'prescription_audit_status', 'payment_slip_audit_status'])
|
||||
->select()->toArray();
|
||||
foreach ($orders as $order) {
|
||||
$prescriptionId = (int) $order->prescription_id;
|
||||
if (in_array((int) $order->fulfillment_status, PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES, true)) {
|
||||
$hasReleasedOrderRx[$prescriptionId] = true;
|
||||
} else {
|
||||
$prescriptionId = (int) $order['prescription_id'];
|
||||
$ordersByPrescription[$prescriptionId][] = $order;
|
||||
if (!in_array((int) $order['fulfillment_status'], PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES, true)) {
|
||||
$hasBizOrderRx[$prescriptionId] = true;
|
||||
}
|
||||
}
|
||||
@@ -302,13 +319,16 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
|
||||
// 处理字段格式
|
||||
$voidAccess = $lists === [] ? [] : PrescriptionLogic::getVoidAccess($this->adminId, $this->adminInfo);
|
||||
$maySubmit = in_array($this->adminId, array_map('intval', array_column($lists, 'creator_id')), true)
|
||||
&& PrescriptionLogic::canSubmitForReview($this->adminId, $this->adminInfo);
|
||||
foreach ($lists as &$item) {
|
||||
$rid = (int) $item['id'];
|
||||
$item['can_void'] = empty($item['void_status']) && empty($hasBizOrderRx[$rid])
|
||||
$item['can_void'] = empty($item['void_status'])
|
||||
&& PrescriptionLogic::hasVoidAccess($item, $this->adminId, $this->adminInfo, $voidAccess)
|
||||
&& (empty($hasReleasedOrderRx[$rid]) || PrescriptionOrderLogic::remoteSnapshotLockErrorForPrescription($rid) === null);
|
||||
&& !PrescriptionLogic::hasBlockingVoidOrder($item, $ordersByPrescription[$rid] ?? [])
|
||||
&& (empty($ordersByPrescription[$rid]) || PrescriptionOrderLogic::remoteSnapshotLockErrorForPrescription($rid) === null);
|
||||
$item['can_restore_rejected'] = PrescriptionLogic::canRestoreRejected($item);
|
||||
$item['esign'] = \app\common\service\esign\PrescriptionEsignService::describe($item, (int) $this->adminId);
|
||||
$item = PrescriptionLogic::withSigningStatus($item, $this->adminId, $maySubmit);
|
||||
// 设置默认值
|
||||
$item['usage_time'] = $item['usage_time'] ?? '饭前';
|
||||
$item['usage_way'] = $item['usage_way'] ?? '温水送服';
|
||||
@@ -343,13 +363,6 @@ class PrescriptionLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$query = Prescription::where($this->searchWhere);
|
||||
$this->applyAuditFilter($query);
|
||||
$this->applySourceFilter($query);
|
||||
$this->applyVisibilityScope($query);
|
||||
$this->applyCreatorIdsFilter($query);
|
||||
$this->applyDataScopeByOwnerColumns($query, ['creator_id', 'assistant_id']);
|
||||
|
||||
return $query->whereNull('delete_time')->count();
|
||||
return $this->buildFilteredQuery()->count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,7 +667,6 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
if ($prescriptionIds !== []) {
|
||||
$prescriptions = \app\common\model\tcm\Prescription::whereIn('id', $prescriptionIds)
|
||||
->whereNull('delete_time')
|
||||
->field(['id', 'creator_id', 'doctor_name', 'phone', 'assistant_id'])
|
||||
->select()
|
||||
->toArray();
|
||||
$doctorIds = [];
|
||||
@@ -681,7 +680,7 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
'doctor_name' => $doctorName,
|
||||
'phone' => (string) ($rx['phone'] ?? ''),
|
||||
'assistant_id' => (int) ($rx['assistant_id'] ?? 0),
|
||||
];
|
||||
] + $rx;
|
||||
if ($doctorId > 0) {
|
||||
$doctorIds[] = $doctorId;
|
||||
}
|
||||
@@ -781,6 +780,7 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
// 添加开方人姓名、处方登记手机(与业务订单收货手机比对用)
|
||||
$item['doctor_name'] = $rxId > 0 ? ($prescriptionCreators[$rxId]['doctor_name'] ?? '') : '';
|
||||
$item['prescription_phone'] = $rxId > 0 ? ($prescriptionCreators[$rxId]['phone'] ?? '') : '';
|
||||
$item = PrescriptionOrderLogic::withReviewAvailability($item, $prescriptionCreators[$rxId] ?? []);
|
||||
}
|
||||
unset($item);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace app\adminapi\logic;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\adminapi\service\AdminTokenService;
|
||||
use app\common\enum\AdminTerminalEnum;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Config;
|
||||
use think\facade\Cache;
|
||||
@@ -144,6 +145,9 @@ class LoginLogic extends BaseLogic
|
||||
'root' => (int) ($admin->root ?? 0),
|
||||
'work_wechat_userid' => (string) ($admin->work_wechat_userid ?? ''),
|
||||
]);
|
||||
if ((int) $params['terminal'] === AdminTerminalEnum::WORKSTATION) {
|
||||
$row['desktop_expires_at'] = $adminInfo['desktop_expires_at'];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
@@ -226,7 +230,7 @@ class LoginLogic extends BaseLogic
|
||||
$avatar = $admin->avatar ?: Config::get('project.default_image.admin_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
|
||||
return [
|
||||
$row = [
|
||||
'name' => $adminInfo['name'],
|
||||
'avatar' => $avatar,
|
||||
'role_name' => $adminInfo['role_name'],
|
||||
@@ -235,6 +239,10 @@ class LoginLogic extends BaseLogic
|
||||
// 企微扫码登录即已绑定 userid
|
||||
'need_bind_work_wechat' => false,
|
||||
];
|
||||
if ((int) $terminal === AdminTerminalEnum::WORKSTATION) {
|
||||
$row['desktop_expires_at'] = $adminInfo['desktop_expires_at'];
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +355,7 @@ class LoginLogic extends BaseLogic
|
||||
$admin->is_paw = 1;
|
||||
Db::transaction(static function () use ($admin) {
|
||||
$admin->save();
|
||||
AdminTokenService::revokeBcrSessions((int) $admin->id);
|
||||
AdminTokenService::revokeNativeSessions((int) $admin->id);
|
||||
});
|
||||
|
||||
// 使当前 token 过期,要求重新登录
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace app\adminapi\logic\auth;
|
||||
use app\adminapi\logic\LoginLogic;
|
||||
use app\adminapi\service\DoctorWebConsultationPolicy;
|
||||
use app\adminapi\service\AdminTokenService;
|
||||
use app\adminapi\service\DesktopSessionService;
|
||||
use app\common\enum\AdminTerminalEnum;
|
||||
use app\common\cache\AdminAuthCache;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
@@ -121,6 +123,8 @@ class AdminLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 与工作站签发共用账号锁,停用或更换角色时能看到此前签发的全部终端。
|
||||
Admin::where('id', $params['id'])->field('id')->lock(true)->find();
|
||||
// 处理资质图片:如果是数组则转为JSON字符串
|
||||
$qualificationImages = '';
|
||||
if (isset($params['qualification_images'])) {
|
||||
@@ -178,7 +182,7 @@ class AdminLogic extends BaseLogic
|
||||
|
||||
Admin::update($data);
|
||||
if (isset($data['password'])) {
|
||||
AdminTokenService::revokeBcrSessions((int) $params['id']);
|
||||
AdminTokenService::revokeNativeSessions((int) $params['id']);
|
||||
}
|
||||
|
||||
// 删除旧的关联信息
|
||||
@@ -223,7 +227,7 @@ class AdminLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$admin = Admin::findOrEmpty($params['id']);
|
||||
$admin = Admin::where('id', $params['id'])->lock(true)->findOrEmpty();
|
||||
if ($admin->root == YesNoEnum::YES) {
|
||||
throw new \Exception("超级管理员不允许被删除");
|
||||
}
|
||||
@@ -270,6 +274,9 @@ class AdminLogic extends BaseLogic
|
||||
if (empty($adminSession)) {
|
||||
return false;
|
||||
}
|
||||
if ((int) $adminSession->terminal === AdminTerminalEnum::WORKSTATION) {
|
||||
return (bool) DesktopSessionService::update((string) $token, 'revoked');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$adminSession->expire_time = $time;
|
||||
@@ -362,7 +369,7 @@ class AdminLogic extends BaseLogic
|
||||
return Db::transaction(static function () use ($data) {
|
||||
$admin = Admin::update($data);
|
||||
if (isset($data['password'])) {
|
||||
AdminTokenService::revokeBcrSessions((int) $data['id']);
|
||||
AdminTokenService::revokeNativeSessions((int) $data['id']);
|
||||
}
|
||||
return $admin;
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -51,7 +51,7 @@ class PatientAiReportLogic extends BaseLogic
|
||||
private const PROMPT_VERSION = 'patient-longitudinal-report-tcm-four-diagnoses-v7';
|
||||
|
||||
/** @var array<int,string> */
|
||||
private const MODEL_KEYS = ['qwen', 'openai'];
|
||||
private const MODEL_KEYS = ['qwen', 'openai', 'doubao'];
|
||||
|
||||
private const MAX_RESPONSE_BYTES = 65536;
|
||||
|
||||
@@ -174,7 +174,7 @@ class PatientAiReportLogic extends BaseLogic
|
||||
array $adminInfo
|
||||
): ?array {
|
||||
if (!in_array($modelKey, self::MODEL_KEYS, true)) {
|
||||
self::setError('AI模型仅支持qwen或openai');
|
||||
self::setError('AI模型仅支持qwen、openai或doubao');
|
||||
return null;
|
||||
}
|
||||
if (!self::hasPermission($adminId, $adminInfo, self::PERMISSION_READ)) {
|
||||
@@ -1664,7 +1664,7 @@ class PatientAiReportLogic extends BaseLogic
|
||||
|
||||
$authorized = array_fill_keys(array_map('intval', $diagnosisIds), true);
|
||||
$versionById = [];
|
||||
$modelVersions = ['qwen' => 0, 'openai' => 0];
|
||||
$modelVersions = array_fill_keys(self::MODEL_KEYS, 0);
|
||||
foreach (array_reverse($rows) as $row) {
|
||||
$model = strtolower(trim((string) ($row['model_key'] ?? '')));
|
||||
if (!array_key_exists($model, $modelVersions)) {
|
||||
@@ -1675,7 +1675,7 @@ class PatientAiReportLogic extends BaseLogic
|
||||
}
|
||||
|
||||
$reports = [];
|
||||
$latestByModel = ['qwen' => null, 'openai' => null];
|
||||
$latestByModel = array_fill_keys(self::MODEL_KEYS, null);
|
||||
$generatedReport = null;
|
||||
foreach ($rows as $row) {
|
||||
$sourceDiagnosisIds = array_values(array_filter(array_map(
|
||||
|
||||
@@ -29,7 +29,7 @@ class PrescriptionLibraryAiLogic extends BaseLogic
|
||||
private const PERMISSION_EDIT = 'tcm.prescriptionlibrary/editaireport';
|
||||
|
||||
/** @var array<int,string> */
|
||||
private const MODEL_KEYS = ['qwen', 'openai'];
|
||||
private const MODEL_KEYS = ['qwen', 'openai', 'doubao'];
|
||||
|
||||
/** @var array<string,string> */
|
||||
private const TEXT_REPORT_SECTIONS = [
|
||||
|
||||
@@ -28,6 +28,7 @@ class PrescriptionLogic
|
||||
public const PRESCRIBE_PERMISSIONS = [
|
||||
'tcm.prescription/add', 'cf.prescription/add', 'tcm.diagnosis/chufang', 'tcm.diagnosis/kaifang',
|
||||
];
|
||||
public const REVIEW_SUBMIT_PERMISSIONS = [...self::PRESCRIBE_PERMISSIONS, 'tcm.prescription/edit', 'cf.prescription/edit'];
|
||||
public const VOID_MANAGE_PERMISSIONS = ['tcm.prescription/void', 'cf.prescription/del'];
|
||||
public const AUDIT_PERMISSIONS = ['tcm.prescription/audit', 'cf.prescription/audit'];
|
||||
|
||||
@@ -188,18 +189,67 @@ class PrescriptionLogic
|
||||
&& (int) ($row['audit_by'] ?? 0) > 0 && (int) $row['audit_by'] === (int) ($row['void_by'] ?? 0)
|
||||
&& (empty($row['esign_required']) || ($row['esign_status'] ?? 'pending') === 'pending');
|
||||
}
|
||||
|
||||
public static function canSubmitForReview(int $adminId, array $adminInfo): bool
|
||||
{
|
||||
return $adminId > 0 && ((int) ($adminInfo['root'] ?? 0) === 1
|
||||
|| array_intersect(self::REVIEW_SUBMIT_PERMISSIONS, array_map('strtolower', AuthLogic::getAuthByAdminId($adminId))) !== []);
|
||||
}
|
||||
|
||||
public static function withSigningStatus(array $row, int $adminId, bool $maySubmit, bool $details = false): array
|
||||
{
|
||||
$row['esign'] = PrescriptionEsignService::describe($row, $adminId, $details, $maySubmit);
|
||||
$row['review_submitted_at'] = $row['esign']['review_submitted_at'];
|
||||
$row['can_submit_for_review'] = $row['esign']['can_submit_for_review'];
|
||||
$row['can_review_prescription'] = $row['esign']['can_review_prescription'];
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function submitForReview(int $id, int $adminId, array $adminInfo): array
|
||||
{
|
||||
if (!self::canSubmitForReview($adminId, $adminInfo)) {
|
||||
throw new \DomainException('无权限上传处方');
|
||||
}
|
||||
|
||||
return Db::transaction(static function () use ($id, $adminId): array {
|
||||
$prescription = Prescription::where('id', $id)->whereNull('delete_time')->lock(true)->find();
|
||||
if (!$prescription || (int) $prescription->creator_id !== $adminId) {
|
||||
throw new \DomainException('处方不存在或非本人开具');
|
||||
}
|
||||
|
||||
$row = $prescription->toArray();
|
||||
$required = PrescriptionEsignService::requiresSignature($row, PrescriptionEsignService::enabled());
|
||||
if (!empty($row['void_status']) || !PrescriptionEsignService::hasUploadContent($row, $required)) {
|
||||
throw new \DomainException('请确认处方未作废并已补全内容');
|
||||
}
|
||||
$submittedAt = (int) ($row['review_submitted_at'] ?? 0);
|
||||
if ($submittedAt <= 0) {
|
||||
if (!PrescriptionEsignPolicy::isPendingReview($row)) {
|
||||
throw new \DomainException('当前处方状态不可上传');
|
||||
}
|
||||
$submittedAt = time();
|
||||
if (!$prescription->save(['review_submitted_at' => $submittedAt])) {
|
||||
throw new \DomainException('处方上传未完成,请重试');
|
||||
}
|
||||
}
|
||||
|
||||
return ['review_submitted_at' => $submittedAt, 'can_submit_for_review' => false];
|
||||
});
|
||||
}
|
||||
|
||||
private static function withActionAvailability(array $row, int $viewerAdminId, array $viewerAdminInfo): array
|
||||
{
|
||||
$id = (int) $row['id'];
|
||||
// 与列表和创建校验一致:已取消 / 已退款的订单保留历史关联,但不再占用处方。
|
||||
$hasBizOrder = PrescriptionOrder::where('prescription_id', $id)
|
||||
$orders = PrescriptionOrder::where('prescription_id', $id)
|
||||
->whereNull('delete_time')
|
||||
->whereNotIn('fulfillment_status', PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES)
|
||||
->count() > 0;
|
||||
->field(['fulfillment_status', 'prescription_audit_status', 'payment_slip_audit_status'])
|
||||
->select()->toArray();
|
||||
$hasBizOrder = array_filter($orders, static fn (array $order): bool =>
|
||||
!in_array((int) $order['fulfillment_status'], PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES, true)) !== [];
|
||||
$row['has_prescription_order'] = $hasBizOrder ? 1 : 0;
|
||||
$row['can_restore_rejected'] = self::canRestoreRejected($row);
|
||||
$row['can_void'] = !$hasBizOrder && empty($row['void_status'])
|
||||
$row['can_void'] = empty($row['void_status']) && !self::hasBlockingVoidOrder($row, $orders)
|
||||
&& self::hasVoidAccess(
|
||||
$row,
|
||||
$viewerAdminId,
|
||||
@@ -211,6 +261,24 @@ class PrescriptionLogic
|
||||
return $row;
|
||||
}
|
||||
|
||||
/** Pending prescriptions can be voided while any active order is still waiting for both reviews. */
|
||||
public static function hasBlockingVoidOrder(array $prescription, array $orders): bool
|
||||
{
|
||||
foreach ($orders as $order) {
|
||||
$fulfillmentStatus = (int) ($order['fulfillment_status'] ?? -1);
|
||||
if (in_array($fulfillmentStatus, PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($fulfillmentStatus !== 1
|
||||
|| !in_array($order['prescription_audit_status'] ?? null, [0, '0'], true)
|
||||
|| !in_array($order['payment_slip_audit_status'] ?? null, [0, '0'], true)
|
||||
|| !PrescriptionEsignPolicy::isPendingReview($prescription)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function generateSn(): string
|
||||
{
|
||||
return 'RX' . date('Ymd') . str_pad((string)mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);
|
||||
@@ -648,6 +716,7 @@ class PrescriptionLogic
|
||||
'is_system_auto' => 0,
|
||||
// 开方医生修改后重新进入待审核
|
||||
'audit_status' => 0,
|
||||
'review_submitted_at' => 0,
|
||||
'audit_time' => null,
|
||||
'audit_by' => null,
|
||||
'audit_by_name' => '',
|
||||
@@ -790,7 +859,7 @@ class PrescriptionLogic
|
||||
'patient_name' => $patientName,
|
||||
'phone' => $phone,
|
||||
'gender' => $gender,
|
||||
]);
|
||||
] + (PrescriptionEsignPolicy::isPendingReview($prescription->toArray()) ? ['review_submitted_at' => 0] : []));
|
||||
|
||||
$latestPo = PrescriptionOrder::where('prescription_id', $rxId)
|
||||
->whereNull('delete_time')
|
||||
@@ -881,7 +950,8 @@ class PrescriptionLogic
|
||||
return null;
|
||||
}
|
||||
$arr = $row->toArray();
|
||||
$arr['esign'] = PrescriptionEsignService::describe($arr, $viewerAdminId);
|
||||
$arr = self::withSigningStatus($arr, $viewerAdminId,
|
||||
(int) $row->creator_id === $viewerAdminId && self::canSubmitForReview($viewerAdminId, $viewerAdminInfo), true);
|
||||
$arr['gender_desc'] = $arr['gender'] == 1 ? '男' : '女';
|
||||
|
||||
$bizPo = PrescriptionOrder::where('prescription_id', $id)
|
||||
@@ -942,7 +1012,7 @@ class PrescriptionLogic
|
||||
if (!$row || (int) ($row->void_status ?? 0) === 1 || (int) ($row->audit_status ?? 1) !== 0) {
|
||||
return null;
|
||||
}
|
||||
PrescriptionEsignService::assertSignedById($prescriptionId, false, $adminId);
|
||||
PrescriptionEsignService::assertSignedById($prescriptionId, false, $adminId, orderApproval: true);
|
||||
$row->audit_status = 1;
|
||||
$row->audit_time = time();
|
||||
$row->audit_by = $adminId;
|
||||
@@ -1046,6 +1116,7 @@ class PrescriptionLogic
|
||||
}
|
||||
|
||||
if ($action === 'reject') {
|
||||
PrescriptionEsignService::assertReviewReady($row->toArray());
|
||||
if (trim($remark) === '') {
|
||||
self::setError('驳回时请填写审核意见');
|
||||
|
||||
@@ -1166,10 +1237,9 @@ class PrescriptionLogic
|
||||
$rows,
|
||||
static fn (array $row): bool => self::canViewPrescription($row, $viewerAdminId, $viewerAdminInfo)
|
||||
));
|
||||
return array_map(static function (array $row) use ($viewerAdminId): array {
|
||||
$row['esign'] = PrescriptionEsignService::describe($row, $viewerAdminId);
|
||||
return $row;
|
||||
}, $visible);
|
||||
$maySubmit = in_array($viewerAdminId, array_map('intval', array_column($visible, 'creator_id')), true)
|
||||
&& self::canSubmitForReview($viewerAdminId, $viewerAdminInfo);
|
||||
return array_map(static fn (array $row): array => self::withSigningStatus($row, $viewerAdminId, $maySubmit), $visible);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1206,8 +1276,8 @@ class PrescriptionLogic
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $row->toArray();
|
||||
$result['esign'] = PrescriptionEsignService::describe($result, $viewerAdminId);
|
||||
$result = self::withSigningStatus($row->toArray(), $viewerAdminId,
|
||||
(int) $row->creator_id === $viewerAdminId && self::canSubmitForReview($viewerAdminId, $viewerAdminInfo));
|
||||
return self::withActionAvailability($result, $viewerAdminId, $viewerAdminInfo);
|
||||
}
|
||||
|
||||
@@ -1348,7 +1418,7 @@ class PrescriptionLogic
|
||||
/**
|
||||
* 作废处方
|
||||
*/
|
||||
public static function void(int $id, int $adminId, array $adminInfo): bool
|
||||
public static function void(int $id, int $adminId, array $adminInfo, bool $pendingOnly = false): bool
|
||||
{
|
||||
self::setError('');
|
||||
try {
|
||||
@@ -1362,7 +1432,7 @@ class PrescriptionLogic
|
||||
|
||||
return (bool) LockedPharmacySnapshotMutation::executeForPrescription(
|
||||
$id,
|
||||
static fn (): bool => self::voidLocked($id, $adminId, $adminInfo, $access)
|
||||
static fn (array $orders): bool => self::voidLocked($id, $adminId, $adminInfo, $access, $pendingOnly, $orders)
|
||||
);
|
||||
} catch (\Throwable $exception) {
|
||||
if (self::getError() === '') {
|
||||
@@ -1372,7 +1442,7 @@ class PrescriptionLogic
|
||||
}
|
||||
}
|
||||
|
||||
private static function voidLocked(int $id, int $adminId, array $adminInfo, array $access): bool
|
||||
private static function voidLocked(int $id, int $adminId, array $adminInfo, array $access, bool $pendingOnly, array $orders): bool
|
||||
{
|
||||
$row = Prescription::where('id', $id)->whereNull('delete_time')->lock(true)->find();
|
||||
if (!$row || !self::hasVoidAccess($row->toArray(), $adminId, $adminInfo, $access)) {
|
||||
@@ -1383,13 +1453,12 @@ class PrescriptionLogic
|
||||
self::setError('该处方已作废');
|
||||
return false;
|
||||
}
|
||||
$rxId = (int) ($row->id ?? 0);
|
||||
$bizCount = (int) PrescriptionOrder::where('prescription_id', $rxId)
|
||||
->whereNull('delete_time')
|
||||
->whereNotIn('fulfillment_status', PrescriptionOrder::RELEASED_PRESCRIPTION_STATUSES)
|
||||
->count();
|
||||
if ($bizCount > 0) {
|
||||
self::setError('该处方已存在业务订单,无法作废');
|
||||
if ($pendingOnly && !PrescriptionEsignPolicy::isPendingReview($row->toArray())) {
|
||||
self::setError('处方审核状态已变化,请刷新列表后查看');
|
||||
return false;
|
||||
}
|
||||
if (self::hasBlockingVoidOrder($row->toArray(), $orders)) {
|
||||
self::setError('关联业务订单的审核或履约状态不允许作废此处方');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -60,16 +60,33 @@ class PrescriptionOrderLogic
|
||||
return self::$error;
|
||||
}
|
||||
|
||||
private static function assertEsignApproved(PrescriptionOrder $order, bool $forDispensing = false, ?int $reviewer = null): bool
|
||||
private static function assertEsignApproved(PrescriptionOrder $order, bool $forDispensing = false, ?int $orderAuditor = null): bool
|
||||
{
|
||||
try {
|
||||
PrescriptionEsignService::assertSignedById((int) $order->prescription_id, $forDispensing, $reviewer);
|
||||
PrescriptionEsignService::assertSignedById(
|
||||
(int) $order->prescription_id, $forDispensing, $orderAuditor, orderApproval: $orderAuditor !== null
|
||||
);
|
||||
return true;
|
||||
} catch (\DomainException $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function assertPrescriptionReviewReady(PrescriptionOrder $order): void
|
||||
{
|
||||
$rx = Db::name('tcm_prescription')->where('id', (int) $order->prescription_id)->lock(true)->find();
|
||||
PrescriptionEsignService::assertReviewReady($rx ?: []);
|
||||
}
|
||||
|
||||
public static function withReviewAvailability(array $order, array $rx): array
|
||||
{
|
||||
$order['review_submitted_at'] = (int) ($rx['review_submitted_at'] ?? 0);
|
||||
$order['can_review_prescription'] = (int) ($order['prescription_audit_status'] ?? -1) === 0
|
||||
&& !in_array((int) ($order['fulfillment_status'] ?? 0), [3, 4], true)
|
||||
&& PrescriptionEsignService::canReview($rx);
|
||||
return $order;
|
||||
}
|
||||
|
||||
private static function assertTrackingAuditApproved(PrescriptionOrder $order): bool
|
||||
{
|
||||
@@ -1284,6 +1301,8 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
}
|
||||
|
||||
$arr = self::withReviewAvailability($arr, $arr['prescription'] ?? []);
|
||||
|
||||
$canHerbs = self::canViewPrescriptionHerbsInOrderDetail($adminInfo);
|
||||
$arr['prescription_detail_herbs_visible'] = $canHerbs;
|
||||
if (! $canHerbs && isset($arr['prescription']) && is_array($arr['prescription'])) {
|
||||
@@ -2329,21 +2348,7 @@ class PrescriptionOrderLogic
|
||||
|
||||
try {
|
||||
$order->save();
|
||||
|
||||
// 撤回订单后,将关联的处方审核状态改回"待审核"
|
||||
$prescriptionId = (int) $order->prescription_id;
|
||||
if ($prescriptionId > 0) {
|
||||
Prescription::where('id', $prescriptionId)
|
||||
->whereNull('delete_time')
|
||||
->update([
|
||||
'audit_status' => 0, // 0=待审核
|
||||
'audit_time' => null,
|
||||
'audit_by' => null,
|
||||
'audit_by_name' => '',
|
||||
'audit_remark' => '',
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
self::resetPrescriptionReview((int) $order->prescription_id);
|
||||
} catch (\Throwable $e) {
|
||||
self::$error = $e->getMessage();
|
||||
|
||||
@@ -2427,6 +2432,9 @@ class PrescriptionOrderLogic
|
||||
if ($action === 'approve' && !self::assertEsignApproved($order, false, $adminId)) {
|
||||
return false;
|
||||
}
|
||||
if ($action === 'reject') {
|
||||
self::assertPrescriptionReviewReady($order);
|
||||
}
|
||||
|
||||
if ($action === 'approve') {
|
||||
$order->prescription_audit_status = 1;
|
||||
@@ -2673,26 +2681,7 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
|
||||
// 同步撤回处方表的审核状态
|
||||
$prescriptionId = (int) $order->prescription_id;
|
||||
if ($prescriptionId > 0) {
|
||||
try {
|
||||
$prescription = Prescription::where('id', $prescriptionId)->whereNull('delete_time')->find();
|
||||
if ($prescription) {
|
||||
$prescription->audit_status = 0;
|
||||
$prescription->audit_remark = '';
|
||||
$prescription->audit_time = null;
|
||||
$prescription->audit_by = null;
|
||||
$prescription->audit_by_name = '';
|
||||
$prescription->save();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 记录日志但不影响主流程
|
||||
Log::error('撤回处方审核时同步处方表失败: ' . $e->getMessage(), [
|
||||
'prescription_id' => $prescriptionId,
|
||||
'order_id' => $id
|
||||
]);
|
||||
}
|
||||
}
|
||||
self::resetPrescriptionReview((int) $order->prescription_id);
|
||||
|
||||
self::writeLog((int) $order->id, $adminId, $adminInfo, 'revoke_rx_audit', '撤回处方审核,状态重置为待审核');
|
||||
|
||||
@@ -2704,6 +2693,21 @@ class PrescriptionOrderLogic
|
||||
return $out;
|
||||
}
|
||||
|
||||
private static function resetPrescriptionReview(int $prescriptionId): void
|
||||
{
|
||||
if ($prescriptionId > 0) {
|
||||
Prescription::where('id', $prescriptionId)->whereNull('delete_time')->update([
|
||||
'audit_status' => 0,
|
||||
'review_submitted_at' => 0,
|
||||
'audit_time' => null,
|
||||
'audit_by' => null,
|
||||
'audit_by_name' => '',
|
||||
'audit_remark' => '',
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回支付单审核:将已通过/已驳回的支付单审核重置为待审核
|
||||
*
|
||||
@@ -2871,10 +2875,16 @@ class PrescriptionOrderLogic
|
||||
return false;
|
||||
}
|
||||
$oldRx = (int) $order->prescription_audit_status;
|
||||
if ($newRx === 1 && $newRx !== $oldRx && !self::assertEsignApproved($order, false, $adminId)) {
|
||||
return false;
|
||||
}
|
||||
if ($newRx !== $oldRx) {
|
||||
if ($newRx === 1 && !self::assertEsignApproved($order, false, $adminId)) {
|
||||
return false;
|
||||
}
|
||||
if ($newRx === 2) {
|
||||
self::assertPrescriptionReviewReady($order);
|
||||
}
|
||||
if ($newRx === 0) {
|
||||
self::resetPrescriptionReview((int) $order->prescription_id);
|
||||
}
|
||||
$order->prescription_audit_status = $newRx;
|
||||
$changeParts[] = '处方审核:' . self::auditStatusLabelForLog($oldRx)
|
||||
. ' → ' . self::auditStatusLabelForLog($newRx);
|
||||
@@ -5982,13 +5992,16 @@ class PrescriptionOrderLogic
|
||||
$changes['辅方袋数'] = [$oldAuxDosageBagCount, $auxDosageBagCount, '袋'];
|
||||
}
|
||||
}
|
||||
$changes['订单服用天数'] = [$oldMedDays, $medDays, '天'];
|
||||
$parts = [];
|
||||
foreach ($changes as $label => [$oldValue, $newValue, $unit]) {
|
||||
if ($oldValue !== $newValue) {
|
||||
$parts[] = sprintf('%s %d%s → %d%s', $label, $oldValue, $unit, $newValue, $unit);
|
||||
}
|
||||
}
|
||||
$prescriptionChanged = $parts !== [];
|
||||
if ($oldMedDays !== $medDays) {
|
||||
$parts[] = sprintf('订单服用天数:%d → %d', $oldMedDays, $medDays);
|
||||
}
|
||||
if ($parts === []) {
|
||||
return true;
|
||||
}
|
||||
@@ -6010,6 +6023,9 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
$rxUpdates['aux_usage'] = $auxUsage;
|
||||
}
|
||||
if ($prescriptionChanged && PrescriptionEsignPolicy::isPendingReview($rx->toArray())) {
|
||||
$rxUpdates['review_submitted_at'] = 0;
|
||||
}
|
||||
$rx->save($rxUpdates);
|
||||
|
||||
$order->medication_days = $medDays;
|
||||
|
||||
@@ -21,7 +21,7 @@ final class TongueScreenshotLogic extends BaseLogic
|
||||
throw new \DomainException('截图分析请求包含不支持的字段');
|
||||
}
|
||||
$model = array_key_exists('model', $params) ? $params['model'] : 'qwen';
|
||||
if (!is_string($model) || !in_array($model, ['qwen', 'openai'], true)) {
|
||||
if (!is_string($model) || !in_array($model, ['qwen', 'openai', 'doubao'], true)) {
|
||||
throw new \DomainException('截图分析模型无效');
|
||||
}
|
||||
$rawId = $params['id'] ?? null;
|
||||
|
||||
@@ -42,7 +42,13 @@ class AdminTokenService
|
||||
(int) $terminal === AdminTerminalEnum::BCR ? 86400 * 150 : 3600);
|
||||
}
|
||||
|
||||
/** 与改密同一事务调用;只撤销 BCR,会话有效性由 DB 决定,旧缓存不能续活。 */
|
||||
/** 改密撤销原生终端的独立凭据。 */
|
||||
public static function revokeNativeSessions(int $adminId): void
|
||||
{
|
||||
self::revokeBcrSessions($adminId);
|
||||
DesktopSessionService::closeForAdmin($adminId, 'revoked');
|
||||
}
|
||||
|
||||
public static function revokeBcrSessions(int $adminId): void
|
||||
{
|
||||
AdminSession::where('admin_id', $adminId)->where('terminal', AdminTerminalEnum::BCR)
|
||||
@@ -63,6 +69,9 @@ class AdminTokenService
|
||||
*/
|
||||
public static function setToken($adminId, $terminal, $multipointLogin = 1)
|
||||
{
|
||||
if ((int) $terminal === AdminTerminalEnum::WORKSTATION) {
|
||||
return DesktopSessionService::open((int) $adminId);
|
||||
}
|
||||
$time = time();
|
||||
$adminSession = AdminSession::where([['admin_id', '=', $adminId], ['terminal', '=', $terminal]])->find();
|
||||
|
||||
@@ -113,6 +122,9 @@ class AdminTokenService
|
||||
if ($adminSession->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if ((int) $adminSession->terminal === AdminTerminalEnum::WORKSTATION) {
|
||||
return false; // 只有桌面心跳可以续租,不能跨过每天 05:00。
|
||||
}
|
||||
if ((int) $adminSession->terminal === AdminTerminalEnum::BCR) {
|
||||
$previousExpiry = (int) $adminSession->expire_time;
|
||||
if ($previousExpiry <= $time || !Admin::where('id', $adminSession->admin_id)
|
||||
@@ -153,6 +165,9 @@ class AdminTokenService
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((int) $adminSession->terminal === AdminTerminalEnum::WORKSTATION) {
|
||||
return (bool) DesktopSessionService::update((string) $token, 'logout');
|
||||
}
|
||||
// 其他终端保留多处登录的原有退出语义。
|
||||
// BCR 必须注销;同账号多台 BCR 复用一个 token 时,这些设备会一起失效。
|
||||
if ((int) $adminSession->terminal !== AdminTerminalEnum::BCR
|
||||
|
||||
@@ -88,7 +88,7 @@ final class AssistantRequestControl
|
||||
/** Atomic ownership record immediately before this generation's first POST execution. */
|
||||
public function beginSubmission(string $profile, string $user): string
|
||||
{
|
||||
if (!in_array($profile, ['qwen', 'openai'], true) || strlen($user) > 128) throw new \RuntimeException('Invalid submission scope');
|
||||
if (!in_array($profile, ['qwen', 'openai', 'doubao'], true) || strlen($user) > 128) throw new \RuntimeException('Invalid submission scope');
|
||||
$token = bin2hex(random_bytes(12));
|
||||
return $this->update(static function (array &$state) use ($profile, $user, $token): string {
|
||||
if (!self::canStartState($state)) throw new \RuntimeException('UPSTREAM_CLEANUP_PENDING');
|
||||
@@ -198,7 +198,7 @@ final class AssistantRequestControl
|
||||
|
||||
public function bindTask(string $profile, string $user, string $taskId, string $workflowRunId = '', string $submissionId = ''): void
|
||||
{
|
||||
if (!in_array($profile, ['qwen', 'openai'], true)
|
||||
if (!in_array($profile, ['qwen', 'openai', 'doubao'], true)
|
||||
|| !self::validUpstreamId($taskId) || strlen($user) > 128
|
||||
|| ($workflowRunId !== '' && !self::validUpstreamId($workflowRunId))) {
|
||||
throw new \RuntimeException('Invalid upstream task identity');
|
||||
@@ -573,7 +573,7 @@ final class AssistantRequestControl
|
||||
$task = $target['upstream'] ?? [];
|
||||
if (!is_array($task) || !is_string($task['task_id'] ?? null) || !self::validUpstreamId($task['task_id'])
|
||||
|| !is_string($task['workflow_run_id'] ?? null) || !self::validUpstreamId($task['workflow_run_id'])
|
||||
|| !in_array($task['profile'] ?? '', ['qwen', 'openai'], true)
|
||||
|| !in_array($task['profile'] ?? '', ['qwen', 'openai', 'doubao'], true)
|
||||
|| !is_string($task['user'] ?? null) || strlen($task['user']) > 128
|
||||
|| !is_int($task['generation'] ?? null) || $task['generation'] <= 0) return null;
|
||||
return ['profile' => $task['profile'], 'user' => $task['user'], 'task_id' => $task['task_id'],
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\service;
|
||||
|
||||
use app\common\cache\AdminTokenCache;
|
||||
use app\common\enum\AdminTerminalEnum;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\service\JsonService;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use think\facade\Db;
|
||||
|
||||
/** 医生工作站每次登录单独计时,认证记录与历史记录在同一事务内更新。 */
|
||||
final class DesktopSessionService
|
||||
{
|
||||
public const HEARTBEAT_GRACE = 180;
|
||||
|
||||
public static function nextCutoff(int $time): int
|
||||
{
|
||||
$local = (new DateTimeImmutable('@' . $time))->setTimezone(new DateTimeZone('Asia/Shanghai'));
|
||||
$cutoff = $local->setTime(5, 0);
|
||||
return ($cutoff <= $local ? $cutoff->modify('+1 day') : $cutoff)->getTimestamp();
|
||||
}
|
||||
|
||||
public static function open(int $adminId): array
|
||||
{
|
||||
return Db::transaction(static function () use ($adminId): array {
|
||||
// 即使还没有任何会话行,账号锁也能串行化单点登录的首次并发签发。
|
||||
$admin = Admin::where('id', $adminId)->lock(true)->find();
|
||||
if (!$admin || (int) $admin['disable'] !== 0) {
|
||||
JsonService::throw('账号不存在或已禁用');
|
||||
}
|
||||
if (!(int) $admin['multipoint_login']) {
|
||||
self::closeForAdmin($adminId, 'replaced');
|
||||
}
|
||||
$now = time();
|
||||
$cutoff = self::nextCutoff($now);
|
||||
$due = min($cutoff, $now + self::HEARTBEAT_GRACE);
|
||||
$slot = Db::name('desktop_login_session')->insertGetId([
|
||||
'admin_id' => $adminId, 'account' => $admin['account'], 'name' => $admin['name'],
|
||||
'login_time' => $now, 'last_seen_time' => $now, 'expires_at' => $cutoff,
|
||||
'due_time' => $due, 'login_ip' => request()->ip(),
|
||||
]);
|
||||
$token = bin2hex(random_bytes(16));
|
||||
Db::name('admin_session')->insert([
|
||||
'admin_id' => $adminId, 'terminal' => AdminTerminalEnum::WORKSTATION,
|
||||
'workstation_slot' => $slot, 'token' => $token, 'expire_time' => $due, 'update_time' => $now,
|
||||
]);
|
||||
$info = (new AdminTokenCache())->setAdminInfo($token);
|
||||
if (!$info) {
|
||||
// 签发若恰好跨过 05:00,与认证行一起回滚。
|
||||
JsonService::throw('登录已到期,请重新登录', [], -1);
|
||||
}
|
||||
return $info;
|
||||
});
|
||||
}
|
||||
|
||||
/** 在改密、停用及单点重登事务内调用。其他终端不访问工作站历史表。 */
|
||||
public static function closeForAdmin(int $adminId, string $reason): void
|
||||
{
|
||||
$tokens = Db::name('admin_session')->where('admin_id', $adminId)
|
||||
->where('terminal', AdminTerminalEnum::WORKSTATION)->order('id')->column('token');
|
||||
foreach ($tokens as $token) {
|
||||
self::update((string) $token, $reason);
|
||||
}
|
||||
}
|
||||
|
||||
/** 心跳返回固定的 05:00 截止时间;手工退出或撤销返回结束时间。过期凭据不能续活。 */
|
||||
public static function update(string $token, string $action): int
|
||||
{
|
||||
return Db::transaction(static function () use ($token, $action): int {
|
||||
$auth = Db::name('admin_session')->where('token', $token)
|
||||
->where('terminal', AdminTerminalEnum::WORKSTATION)->lock(true)->find();
|
||||
if (!$auth) {
|
||||
return 0;
|
||||
}
|
||||
$row = Db::name('desktop_login_session')->where('id', $auth['workstation_slot'])
|
||||
->whereNull('logout_time')->lock(true)->find();
|
||||
if (!$row) {
|
||||
return 0;
|
||||
}
|
||||
$now = time();
|
||||
$reason = $action;
|
||||
$end = $now;
|
||||
if ((int) $auth['expire_time'] < (int) $row['due_time'] && (int) $auth['expire_time'] <= $now) {
|
||||
// 兼容通过通用账号管理入口撤销凭据的情形。
|
||||
$reason = 'revoked';
|
||||
$end = min($now, (int) $auth['update_time']);
|
||||
} elseif ((int) $row['due_time'] <= $now) {
|
||||
$cutoffReached = (int) $row['due_time'] === (int) $row['expires_at'];
|
||||
$reason = $cutoffReached ? 'daily_cutoff' : 'timeout';
|
||||
$end = $cutoffReached ? (int) $row['expires_at'] : (int) $row['last_seen_time'];
|
||||
} elseif ($action === 'heartbeat') {
|
||||
$due = min((int) $row['expires_at'], $now + self::HEARTBEAT_GRACE);
|
||||
Db::name('desktop_login_session')->where('id', $row['id'])->update([
|
||||
'last_seen_time' => $now, 'due_time' => $due, 'duration_seconds' => $now - (int) $row['login_time'],
|
||||
]);
|
||||
Db::name('admin_session')->where('id', $auth['id'])->update(['expire_time' => $due, 'update_time' => $now]);
|
||||
return (int) $row['expires_at'];
|
||||
} elseif ($action === 'settle') {
|
||||
// 扫描与锁行之间可能已收到心跳。
|
||||
return 0;
|
||||
}
|
||||
$end = max((int) $row['login_time'], $end);
|
||||
Db::name('desktop_login_session')->where('id', $row['id'])->update([
|
||||
'logout_time' => $end, 'duration_seconds' => $end - (int) $row['login_time'], 'end_reason' => $reason,
|
||||
]);
|
||||
Db::name('admin_session')->where('id', $auth['id'])->delete();
|
||||
return $action === 'heartbeat' ? 0 : $end;
|
||||
});
|
||||
}
|
||||
|
||||
/** 定时任务及报表入口共用;到期时间取已落库的界线,不受任务迟到的影响。 */
|
||||
public static function settleDue(): int
|
||||
{
|
||||
$settled = 0;
|
||||
$now = time();
|
||||
Db::name('admin_session')->where('terminal', AdminTerminalEnum::WORKSTATION)
|
||||
->where('workstation_slot', '>', 0)->where('expire_time', '<=', $now)->field('id,token')
|
||||
->chunk(200, static function ($rows) use (&$settled) {
|
||||
foreach ($rows as $row) {
|
||||
if (self::update((string) $row['token'], 'settle')) {
|
||||
$settled++;
|
||||
}
|
||||
}
|
||||
}, 'id');
|
||||
return $settled;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class LoginValidate extends BaseValidate
|
||||
protected $rule = [
|
||||
'terminal' => 'require|in:' . AdminTerminalEnum::PC . ',' . AdminTerminalEnum::MOBILE
|
||||
. ',' . AdminTerminalEnum::WECOM_RPA . ',' . AdminTerminalEnum::WECOM_RPA_MOBILE
|
||||
. ',' . AdminTerminalEnum::BCR,
|
||||
. ',' . AdminTerminalEnum::BCR . ',' . AdminTerminalEnum::WORKSTATION,
|
||||
'account' => 'require',
|
||||
'password' => 'require|password',
|
||||
];
|
||||
|
||||
@@ -1,113 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\tcm;
|
||||
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 中医辨房病因诊单验证
|
||||
* Class DiagnosisValidate
|
||||
* @package app\adminapi\validate\tcm
|
||||
*/
|
||||
class DiagnosisValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkDiagnosis',
|
||||
'patient_name' => 'require|length:1,50',
|
||||
'id_card' => 'length:15,18',
|
||||
'phone' => 'require|mobile',
|
||||
'gender' => 'require|in:0,1',
|
||||
'age' => 'require|number|between:0,150',
|
||||
'diagnosis_type' => 'require',
|
||||
'local_hospital_name' => 'require|max:255',
|
||||
'status' => 'in:0,1',
|
||||
'show_card' => 'in:0,1',
|
||||
'create_source' => 'max:32',
|
||||
'current_medications' => 'max:2000',
|
||||
'tongue_images' => 'array',
|
||||
'report_files' => 'array',
|
||||
'diabetes_discovery_year' => 'max:50',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date|checkDateRange',
|
||||
'diagnosis_id' => 'require|integer|checkDiagnosisId',
|
||||
'tracking_content' => 'require|length:1,1000',
|
||||
'revisit_slot_start_offset' => 'integer|between:0,20',
|
||||
'report_id' => 'number|gt:0',
|
||||
'content' => 'max:12000',
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\tcm;
|
||||
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 中医辨房病因诊单验证
|
||||
* Class DiagnosisValidate
|
||||
* @package app\adminapi\validate\tcm
|
||||
*/
|
||||
class DiagnosisValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkDiagnosis',
|
||||
'patient_name' => 'require|length:1,50',
|
||||
'id_card' => 'length:15,18',
|
||||
'phone' => 'require|mobile',
|
||||
'gender' => 'require|in:0,1',
|
||||
'age' => 'require|number|between:0,150',
|
||||
'diagnosis_type' => 'require',
|
||||
'local_hospital_name' => 'require|max:255',
|
||||
'status' => 'in:0,1',
|
||||
'show_card' => 'in:0,1',
|
||||
'create_source' => 'max:32',
|
||||
'current_medications' => 'max:2000',
|
||||
'tongue_images' => 'array',
|
||||
'report_files' => 'array',
|
||||
'diabetes_discovery_year' => 'max:50',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date|checkDateRange',
|
||||
'diagnosis_id' => 'require|integer|checkDiagnosisId',
|
||||
'tracking_content' => 'require|length:1,1000',
|
||||
'revisit_slot_start_offset' => 'integer|between:0,20',
|
||||
'report_id' => 'number|gt:0',
|
||||
'content' => 'max:12000',
|
||||
'task' => 'require|in:summary,case_analysis,glucose_trend,lifestyle_advice,tcm_pattern,prescription_review,prescription_generate,medication_review,exam_review,complication_risk,guideline_review,custom,live_consultation,live_review',
|
||||
'prompt' => 'max:500',
|
||||
'model' => 'in:qwen,openai',
|
||||
'patient_id' => 'integer|gt:0',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'patient_name.require' => '请输入患者姓名',
|
||||
'patient_name.length' => '患者姓名长度须在1-50位字符',
|
||||
'id_card.length' => '身份证号长度不正确',
|
||||
'id_card.require' => '请输入身份证号',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone.mobile' => '手机号格式不正确',
|
||||
'gender.require' => '请选择性别',
|
||||
'gender.in' => '性别参数错误',
|
||||
'age.require' => '请输入年龄',
|
||||
'age.number' => '年龄必须为数字',
|
||||
'age.between' => '年龄范围0-150',
|
||||
'diagnosis_type.require' => '请选择诊断类型',
|
||||
'local_hospital_name.require' => '请输入当地就诊医院名称',
|
||||
'local_hospital_name.max' => '当地就诊医院名称最多255个字符',
|
||||
'status.in' => '状态参数错误',
|
||||
'create_source.max' => '渠道来源长度不能超过32个字符',
|
||||
'current_medications.max' => '在用药物最多2000个字符',
|
||||
'diabetes_discovery_year.max' => '发现糖尿病患病史最多50个字符',
|
||||
'start_date.date' => '开始日期格式不正确',
|
||||
'end_date.date' => '结束日期格式不正确',
|
||||
'diagnosis_id.require' => '诊单ID不能为空',
|
||||
'tracking_content.require' => '跟踪备注内容不能为空',
|
||||
'tracking_content.length' => '跟踪备注最多1000个字符',
|
||||
'report_id.require' => '报告ID不能为空',
|
||||
'report_id.number' => '报告ID必须为数字',
|
||||
'report_id.gt' => '报告ID必须大于0',
|
||||
'content.require' => '报告内容不能为空',
|
||||
'content.max' => '报告内容最多12000个字符',
|
||||
'task.require' => '请选择 AI 助手任务',
|
||||
'task.in' => 'AI 助手任务不受支持',
|
||||
'prompt.max' => '问题最多500个字符',
|
||||
'model.in' => 'AI模型仅支持qwen或openai',
|
||||
'patient_id.require' => '患者ID不能为空',
|
||||
'patient_id.integer' => '患者ID必须为整数',
|
||||
'patient_id.gt' => '患者ID必须大于0',
|
||||
];
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
// 全局规则里混有跟踪备注、AI 助手字段;新增诊单只去掉这些无关校验。
|
||||
// 不要改成 only([...]):add 还会写入现病史等多选字段,only 会把它们从请求里丢掉。
|
||||
return $this->remove('id', true)
|
||||
->remove('diagnosis_id', true)
|
||||
->remove('tracking_content', true)
|
||||
->remove('task', true)
|
||||
->remove('prompt', true)
|
||||
->remove('model', true)
|
||||
->remove('report_id', true)
|
||||
->remove('content', true);
|
||||
}
|
||||
|
||||
public function sceneEdit()
|
||||
{
|
||||
'prompt' => 'max:500',
|
||||
'model' => 'in:qwen,openai,doubao',
|
||||
'patient_id' => 'integer|gt:0',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'patient_name.require' => '请输入患者姓名',
|
||||
'patient_name.length' => '患者姓名长度须在1-50位字符',
|
||||
'id_card.length' => '身份证号长度不正确',
|
||||
'id_card.require' => '请输入身份证号',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone.mobile' => '手机号格式不正确',
|
||||
'gender.require' => '请选择性别',
|
||||
'gender.in' => '性别参数错误',
|
||||
'age.require' => '请输入年龄',
|
||||
'age.number' => '年龄必须为数字',
|
||||
'age.between' => '年龄范围0-150',
|
||||
'diagnosis_type.require' => '请选择诊断类型',
|
||||
'local_hospital_name.require' => '请输入当地就诊医院名称',
|
||||
'local_hospital_name.max' => '当地就诊医院名称最多255个字符',
|
||||
'status.in' => '状态参数错误',
|
||||
'create_source.max' => '渠道来源长度不能超过32个字符',
|
||||
'current_medications.max' => '在用药物最多2000个字符',
|
||||
'diabetes_discovery_year.max' => '发现糖尿病患病史最多50个字符',
|
||||
'start_date.date' => '开始日期格式不正确',
|
||||
'end_date.date' => '结束日期格式不正确',
|
||||
'diagnosis_id.require' => '诊单ID不能为空',
|
||||
'tracking_content.require' => '跟踪备注内容不能为空',
|
||||
'tracking_content.length' => '跟踪备注最多1000个字符',
|
||||
'report_id.require' => '报告ID不能为空',
|
||||
'report_id.number' => '报告ID必须为数字',
|
||||
'report_id.gt' => '报告ID必须大于0',
|
||||
'content.require' => '报告内容不能为空',
|
||||
'content.max' => '报告内容最多12000个字符',
|
||||
'task.require' => '请选择 AI 助手任务',
|
||||
'task.in' => 'AI 助手任务不受支持',
|
||||
'prompt.max' => '问题最多500个字符',
|
||||
'model.in' => 'AI模型仅支持qwen、openai或doubao',
|
||||
'patient_id.require' => '患者ID不能为空',
|
||||
'patient_id.integer' => '患者ID必须为整数',
|
||||
'patient_id.gt' => '患者ID必须大于0',
|
||||
];
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
// 全局规则里混有跟踪备注、AI 助手字段;新增诊单只去掉这些无关校验。
|
||||
// 不要改成 only([...]):add 还会写入现病史等多选字段,only 会把它们从请求里丢掉。
|
||||
return $this->remove('id', true)
|
||||
->remove('diagnosis_id', true)
|
||||
->remove('tracking_content', true)
|
||||
->remove('task', true)
|
||||
->remove('prompt', true)
|
||||
->remove('model', true)
|
||||
->remove('report_id', true)
|
||||
->remove('content', true);
|
||||
}
|
||||
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'patient_name', 'id_card', 'phone', 'gender', 'age', 'diagnosis_date', 'diagnosis_type', 'syndrome_type', 'marital_status', 'height', 'weight', 'region', 'systolic_pressure', 'diastolic_pressure', 'fasting_blood_sugar', 'diabetes_discovery_year', 'local_hospital_diagnosis', 'local_hospital_name', 'past_history', 'symptoms', 'tongue_coating', 'pulse', 'treatment_principle', 'prescription', 'doctor_advice', 'remark', 'current_medications', 'status', 'show_card', 'create_source'])
|
||||
// 脱敏或被业务锁定的基本信息可省略,省略表示保留原值;显式提交仍需非空且格式有效。
|
||||
->remove(['patient_name' => 'require', 'phone' => 'require', 'gender' => 'require', 'age' => 'require'])
|
||||
@@ -123,28 +123,28 @@ class DiagnosisValidate extends BaseValidate
|
||||
return $this->message[$field . '.require'];
|
||||
}
|
||||
|
||||
public function sceneId()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneReadonlyDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneTrackingWindow()
|
||||
{
|
||||
return $this->only(['id', 'start_date', 'end_date']);
|
||||
}
|
||||
|
||||
/** 新增跟踪备注:诊单ID + 备注内容 */
|
||||
public function sceneAddTrackingNote()
|
||||
{
|
||||
return $this->only(['diagnosis_id', 'tracking_content']);
|
||||
}
|
||||
|
||||
/** 拉取跟踪备注列表:诊单ID */
|
||||
public function sceneId()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneReadonlyDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneTrackingWindow()
|
||||
{
|
||||
return $this->only(['id', 'start_date', 'end_date']);
|
||||
}
|
||||
|
||||
/** 新增跟踪备注:诊单ID + 备注内容 */
|
||||
public function sceneAddTrackingNote()
|
||||
{
|
||||
return $this->only(['diagnosis_id', 'tracking_content']);
|
||||
}
|
||||
|
||||
/** 拉取跟踪备注列表:诊单ID */
|
||||
public function sceneTrackingNotes()
|
||||
{
|
||||
return $this->only(['diagnosis_id']);
|
||||
@@ -161,54 +161,54 @@ class DiagnosisValidate extends BaseValidate
|
||||
}
|
||||
|
||||
public function sceneGenerateQrcode()
|
||||
{
|
||||
return $this->only(['diagnosis_id', 'doctor_id', 'patient_id', 'share_user_id', 'mini_program_path'])
|
||||
// The global diagnosis_id rule is required for diagnosis APIs, but
|
||||
// video QR codes identify the doctor instead. Keep diagnosis_id
|
||||
// optional here while still validating it when it is supplied.
|
||||
->remove('diagnosis_id', 'require')
|
||||
->append('patient_id', 'require|integer|checkQrcodeIds')
|
||||
->append('share_user_id', 'require|integer')
|
||||
->append('doctor_id', 'integer');
|
||||
}
|
||||
|
||||
public function sceneGenerateOrderQrcode()
|
||||
{
|
||||
return $this->only([]);
|
||||
}
|
||||
|
||||
public function sceneFillIdCard()
|
||||
{
|
||||
return $this->only(['id', 'id_card'])
|
||||
->append('id', 'require')
|
||||
->append('id_card', 'require|length:15,18');
|
||||
}
|
||||
|
||||
public function sceneGuahaoLogList()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/** 业务订单 tab:设置复诊接诊率统计起始偏移 */
|
||||
public function sceneSetRevisitSlotStartOffset()
|
||||
{
|
||||
return $this->only(['id', 'revisit_slot_start_offset'])
|
||||
->append('revisit_slot_start_offset', 'require|integer|between:0,20');
|
||||
}
|
||||
|
||||
public function sceneAiReports()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneAiAssistant()
|
||||
{
|
||||
return $this->only(['id', 'task', 'prompt']);
|
||||
}
|
||||
|
||||
{
|
||||
return $this->only(['diagnosis_id', 'doctor_id', 'patient_id', 'share_user_id', 'mini_program_path'])
|
||||
// The global diagnosis_id rule is required for diagnosis APIs, but
|
||||
// video QR codes identify the doctor instead. Keep diagnosis_id
|
||||
// optional here while still validating it when it is supplied.
|
||||
->remove('diagnosis_id', 'require')
|
||||
->append('patient_id', 'require|integer|checkQrcodeIds')
|
||||
->append('share_user_id', 'require|integer')
|
||||
->append('doctor_id', 'integer');
|
||||
}
|
||||
|
||||
public function sceneGenerateOrderQrcode()
|
||||
{
|
||||
return $this->only([]);
|
||||
}
|
||||
|
||||
public function sceneFillIdCard()
|
||||
{
|
||||
return $this->only(['id', 'id_card'])
|
||||
->append('id', 'require')
|
||||
->append('id_card', 'require|length:15,18');
|
||||
}
|
||||
|
||||
public function sceneGuahaoLogList()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/** 业务订单 tab:设置复诊接诊率统计起始偏移 */
|
||||
public function sceneSetRevisitSlotStartOffset()
|
||||
{
|
||||
return $this->only(['id', 'revisit_slot_start_offset'])
|
||||
->append('revisit_slot_start_offset', 'require|integer|between:0,20');
|
||||
}
|
||||
|
||||
public function sceneAiReports()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneAiAssistant()
|
||||
{
|
||||
return $this->only(['id', 'task', 'prompt', 'model']);
|
||||
}
|
||||
|
||||
public function sceneAiAssistantStream()
|
||||
{
|
||||
return $this->only(['id', 'task', 'prompt', 'request_id', 'call_record_id', 'transcription_session_id'])
|
||||
return $this->only(['id', 'task', 'prompt', 'model', 'request_id', 'call_record_id', 'transcription_session_id'])
|
||||
->append('task', 'checkLiveAssistantIdentity')
|
||||
->append('request_id', 'checkAssistantRequestId');
|
||||
}
|
||||
@@ -233,136 +233,136 @@ class DiagnosisValidate extends BaseValidate
|
||||
? true : 'AI请求标识无效';
|
||||
}
|
||||
|
||||
public function sceneAiAnalysis()
|
||||
{
|
||||
return $this->only(['id', 'model'])
|
||||
->remove('id', 'checkDiagnosis')
|
||||
->append('id', 'integer|gt:0|checkAiAnalysisPayload');
|
||||
}
|
||||
|
||||
public function scenePatientAiReports()
|
||||
{
|
||||
return $this->only(['patient_id'])
|
||||
->append('patient_id', 'require|integer|gt:0|checkPatientAiReportsPayload');
|
||||
}
|
||||
|
||||
public function sceneGeneratePatientAiReport()
|
||||
{
|
||||
return $this->only(['patient_id', 'model'])
|
||||
->append('patient_id', 'require|integer|gt:0|checkGeneratePatientAiReportPayload')
|
||||
->append('model', 'require|in:qwen,openai');
|
||||
}
|
||||
|
||||
public function sceneGenerateAiReports()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneEditAiReport()
|
||||
{
|
||||
return $this->only(['id', 'report_id', 'content'])
|
||||
->append('report_id', 'require|number|gt:0')
|
||||
->append('content', 'require|max:12000');
|
||||
}
|
||||
|
||||
protected function checkDiagnosis($value)
|
||||
{
|
||||
$diagnosis = Diagnosis::findOrEmpty($value);
|
||||
if ($diagnosis->isEmpty()) {
|
||||
return '诊单不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 校验 diagnosis_id 字段(addTrackingNote 等场景使用,避开 id 字段) */
|
||||
protected function checkDiagnosisId($value)
|
||||
{
|
||||
$diagnosis = Diagnosis::findOrEmpty($value);
|
||||
if ($diagnosis->isEmpty()) {
|
||||
return '诊单不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** end_date 不能早于 start_date */
|
||||
protected function checkDateRange($value, $rule, $data = [])
|
||||
{
|
||||
$start = $data['start_date'] ?? '';
|
||||
if ($start && $value && strtotime($value) < strtotime($start)) {
|
||||
return '结束日期不能早于开始日期';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 视频场景需 doctor_id,确认诊单需 diagnosis_id */
|
||||
protected function checkQrcodeIds($value, $rule, $data = [])
|
||||
{
|
||||
$page = $data['mini_program_path'] ?? '';
|
||||
$hasDoctor = !empty($data['doctor_id']);
|
||||
$hasDiagnosis = !empty($data['diagnosis_id']);
|
||||
if ($page === 'pages/login/login') {
|
||||
return $hasDoctor ? true : '视频二维码需传挂号医生ID';
|
||||
}
|
||||
return $hasDiagnosis ? true : '诊单ID不能为空';
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 智能分析仅接受诊单 ID 和可选的固定模型键。客户端不得提供
|
||||
* provider、凭据、上游地址、提示词等服务端配置或控制字段。
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $rule
|
||||
* @param array<string,mixed> $data
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function checkAiAnalysisPayload($value, $rule, array $data = [])
|
||||
{
|
||||
if (!array_key_exists('id', $data)) {
|
||||
return 'AI智能分析请求缺少id参数';
|
||||
}
|
||||
|
||||
$extraFields = array_diff(array_keys($data), ['id', 'model']);
|
||||
if ($extraFields !== []) {
|
||||
return 'AI智能分析请求仅允许id及可选model参数';
|
||||
}
|
||||
|
||||
if (array_key_exists('model', $data)) {
|
||||
$model = $data['model'];
|
||||
if (!is_string($model) || !in_array($model, ['qwen', 'openai'], true)) {
|
||||
return 'AI模型仅支持qwen或openai';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $data */
|
||||
protected function checkPatientAiReportsPayload($value, $rule, array $data = [])
|
||||
{
|
||||
if (!array_key_exists('patient_id', $data)) {
|
||||
return '请求缺少patient_id参数';
|
||||
}
|
||||
$extraFields = array_diff(array_keys($data), ['patient_id']);
|
||||
return $extraFields === [] ? true : '请求仅允许patient_id参数';
|
||||
}
|
||||
|
||||
/**
|
||||
* 患者报告生成端点只接受稳定患者ID与服务端模型白名单键。
|
||||
* provider、凭据、BASE_URL、提示词和任意来源正文均不得由客户端注入。
|
||||
*
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
protected function checkGeneratePatientAiReportPayload($value, $rule, array $data = [])
|
||||
{
|
||||
if (!array_key_exists('patient_id', $data) || !array_key_exists('model', $data)) {
|
||||
return '请求缺少patient_id或model参数';
|
||||
}
|
||||
$extraFields = array_diff(array_keys($data), ['patient_id', 'model']);
|
||||
if ($extraFields !== []) {
|
||||
return '请求仅允许patient_id和model参数';
|
||||
}
|
||||
if (!is_string($data['model']) || !in_array($data['model'], ['qwen', 'openai'], true)) {
|
||||
return 'AI模型仅支持qwen或openai';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public function sceneAiAnalysis()
|
||||
{
|
||||
return $this->only(['id', 'model'])
|
||||
->remove('id', 'checkDiagnosis')
|
||||
->append('id', 'integer|gt:0|checkAiAnalysisPayload');
|
||||
}
|
||||
|
||||
public function scenePatientAiReports()
|
||||
{
|
||||
return $this->only(['patient_id'])
|
||||
->append('patient_id', 'require|integer|gt:0|checkPatientAiReportsPayload');
|
||||
}
|
||||
|
||||
public function sceneGeneratePatientAiReport()
|
||||
{
|
||||
return $this->only(['patient_id', 'model'])
|
||||
->append('patient_id', 'require|integer|gt:0|checkGeneratePatientAiReportPayload')
|
||||
->append('model', 'require|in:qwen,openai,doubao');
|
||||
}
|
||||
|
||||
public function sceneGenerateAiReports()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function sceneEditAiReport()
|
||||
{
|
||||
return $this->only(['id', 'report_id', 'content'])
|
||||
->append('report_id', 'require|number|gt:0')
|
||||
->append('content', 'require|max:12000');
|
||||
}
|
||||
|
||||
protected function checkDiagnosis($value)
|
||||
{
|
||||
$diagnosis = Diagnosis::findOrEmpty($value);
|
||||
if ($diagnosis->isEmpty()) {
|
||||
return '诊单不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 校验 diagnosis_id 字段(addTrackingNote 等场景使用,避开 id 字段) */
|
||||
protected function checkDiagnosisId($value)
|
||||
{
|
||||
$diagnosis = Diagnosis::findOrEmpty($value);
|
||||
if ($diagnosis->isEmpty()) {
|
||||
return '诊单不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** end_date 不能早于 start_date */
|
||||
protected function checkDateRange($value, $rule, $data = [])
|
||||
{
|
||||
$start = $data['start_date'] ?? '';
|
||||
if ($start && $value && strtotime($value) < strtotime($start)) {
|
||||
return '结束日期不能早于开始日期';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 视频场景需 doctor_id,确认诊单需 diagnosis_id */
|
||||
protected function checkQrcodeIds($value, $rule, $data = [])
|
||||
{
|
||||
$page = $data['mini_program_path'] ?? '';
|
||||
$hasDoctor = !empty($data['doctor_id']);
|
||||
$hasDiagnosis = !empty($data['diagnosis_id']);
|
||||
if ($page === 'pages/login/login') {
|
||||
return $hasDoctor ? true : '视频二维码需传挂号医生ID';
|
||||
}
|
||||
return $hasDiagnosis ? true : '诊单ID不能为空';
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 智能分析仅接受诊单 ID 和可选的固定模型键。客户端不得提供
|
||||
* provider、凭据、上游地址、提示词等服务端配置或控制字段。
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $rule
|
||||
* @param array<string,mixed> $data
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function checkAiAnalysisPayload($value, $rule, array $data = [])
|
||||
{
|
||||
if (!array_key_exists('id', $data)) {
|
||||
return 'AI智能分析请求缺少id参数';
|
||||
}
|
||||
|
||||
$extraFields = array_diff(array_keys($data), ['id', 'model']);
|
||||
if ($extraFields !== []) {
|
||||
return 'AI智能分析请求仅允许id及可选model参数';
|
||||
}
|
||||
|
||||
if (array_key_exists('model', $data)) {
|
||||
$model = $data['model'];
|
||||
if (!is_string($model) || !in_array($model, ['qwen', 'openai', 'doubao'], true)) {
|
||||
return 'AI模型仅支持qwen、openai或doubao';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $data */
|
||||
protected function checkPatientAiReportsPayload($value, $rule, array $data = [])
|
||||
{
|
||||
if (!array_key_exists('patient_id', $data)) {
|
||||
return '请求缺少patient_id参数';
|
||||
}
|
||||
$extraFields = array_diff(array_keys($data), ['patient_id']);
|
||||
return $extraFields === [] ? true : '请求仅允许patient_id参数';
|
||||
}
|
||||
|
||||
/**
|
||||
* 患者报告生成端点只接受稳定患者ID与服务端模型白名单键。
|
||||
* provider、凭据、BASE_URL、提示词和任意来源正文均不得由客户端注入。
|
||||
*
|
||||
* @param array<string,mixed> $data
|
||||
*/
|
||||
protected function checkGeneratePatientAiReportPayload($value, $rule, array $data = [])
|
||||
{
|
||||
if (!array_key_exists('patient_id', $data) || !array_key_exists('model', $data)) {
|
||||
return '请求缺少patient_id或model参数';
|
||||
}
|
||||
$extraFields = array_diff(array_keys($data), ['patient_id', 'model']);
|
||||
if ($extraFields !== []) {
|
||||
return '请求仅允许patient_id和model参数';
|
||||
}
|
||||
if (!is_string($data['model']) || !in_array($data['model'], ['qwen', 'openai', 'doubao'], true)) {
|
||||
return 'AI模型仅支持qwen、openai或doubao';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user