- 洛阳药房:作废时先调用 POST /api/openapi/v1/prescription-orders/{订单号}/cancel 撤单,确认 CANCELLED 后再作废并挂起订单;
远端拒绝(已发货/已扣库存,409)或未确认时不作废并提示原因;撤单写订单日志。撤单后的订单重新审核通过后以新版本提交药房
- 甘草:暂无撤单接口,须先在甘草撤单;甘草回传撤单/驳回(91/92)后可作废
- 远端已确认取消且无在途新版本提交时,订单不再被药房快照锁定
- 列表与详情的 can_void 按「能否自动撤单」判断
- 重新构建管理后台
Co-Authored-By: Claude Opus 5 <[EMAIL]>
66 lines
2.2 KiB
PHP
Executable File
66 lines
2.2 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\common\service\pharmacy;
|
|
|
|
use DomainException;
|
|
|
|
final class PharmacyRemoteSnapshotPolicy
|
|
{
|
|
/**
|
|
* @param array<string,mixed> $order
|
|
* @param array<string,mixed>|null $claim
|
|
*/
|
|
public static function isLocked(array $order, ?array $claim): bool
|
|
{
|
|
// 远端已确认取消(洛阳药房撤单、甘草撤单/驳回)且没有在途的新版本提交:快照不再被药房使用。
|
|
if (self::isRemoteCancelled($order) && !self::isClaimInFlight($claim)) {
|
|
return false;
|
|
}
|
|
if (trim((string) ($order['gancao_reciperl_order_no'] ?? '')) !== '') {
|
|
return true;
|
|
}
|
|
if (trim((string) ($order['ej_pharmacy_order_no'] ?? '')) !== '') {
|
|
return true;
|
|
}
|
|
if ((int) ($order['gancao_submit_time'] ?? 0) > 0 || (int) ($order['ej_pharmacy_submit_time'] ?? 0) > 0) {
|
|
return true;
|
|
}
|
|
|
|
return is_array($claim) && in_array(
|
|
strtoupper((string) ($claim['status'] ?? '')),
|
|
['PENDING', 'UNKNOWN', 'PENDING_RECONCILE', 'SUCCESS'],
|
|
true
|
|
);
|
|
}
|
|
|
|
/** @param array<string,mixed> $order */
|
|
public static function isRemoteCancelled(array $order): bool
|
|
{
|
|
return strtoupper(trim((string) ($order['ej_pharmacy_status'] ?? ''))) === 'CANCELLED'
|
|
|| in_array((int) ($order['gancao_order_state'] ?? 0), [91, 92], true);
|
|
}
|
|
|
|
/** @param array<string,mixed>|null $claim */
|
|
public static function isClaimInFlight(?array $claim): bool
|
|
{
|
|
return is_array($claim) && in_array(
|
|
strtoupper((string) ($claim['status'] ?? '')),
|
|
['PENDING', 'UNKNOWN', 'PENDING_RECONCILE'],
|
|
true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param array<string,mixed> $order
|
|
* @param array<string,mixed>|null $claim
|
|
*/
|
|
public static function assertMutable(array $order, ?array $claim): void
|
|
{
|
|
if (self::isLocked($order, $claim)) {
|
|
throw new DomainException('订单已提交药房,患者、地址、处方与发货药房快照不可修改;请先完成远端取消确认,取消后创建新版本');
|
|
}
|
|
}
|
|
}
|