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