igengx
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user