This commit is contained in:
Your Name
2026-11-26 15:46:20 +08:00
parent db6d327e91
commit be79e09c83
170 changed files with 21159 additions and 13217 deletions
@@ -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);