This commit is contained in:
Your Name
2026-07-02 14:35:20 +08:00
parent b6cdd20c56
commit efd058bce5
312 changed files with 1376 additions and 400 deletions
@@ -4409,6 +4409,112 @@ class PrescriptionOrderLogic
return true;
}
/**
* 批量将处方业务订单「创建人(医助归属)」改派给其他医助。
* 仅改写 creator_id(业务归属/医助筛选口径),逐单记操作日志;与支付单批量改派口径一致。
*
* @param int[] $orderIds
* @param int $assistantAdminId 目标医助 admin_id(须含医助角色)
* @return array{success:int, fail:int, errors:string[], per_log:array<int,array{order_id:int,summary:string}>}|false
*/
public static function batchAssignAssistant(array $orderIds, int $assistantAdminId, int $adminId, array $adminInfo)
{
self::$error = '';
$assistantAdminId = (int) $assistantAdminId;
if ($assistantAdminId <= 0) {
self::$error = '请选择医助';
return false;
}
// 目标须为医助角色(与支付单批量改派一致)
$assistantRoleId = (int) Config::get('project.prescription_order_stats_assistant_role_id', 2);
if (
\app\common\model\auth\AdminRole::where('admin_id', $assistantAdminId)
->where('role_id', $assistantRoleId)
->count() === 0
) {
self::$error = '目标账号不是医助角色';
return false;
}
$ids = array_values(array_unique(array_filter(
array_map('intval', $orderIds),
static fn (int $id) => $id > 0
)));
if ($ids === []) {
self::$error = '请选择订单';
return false;
}
if (count($ids) > 200) {
self::$error = '单次最多改派200单';
return false;
}
$targetName = (string) Admin::where('id', $assistantAdminId)->whereNull('delete_time')->value('name');
if ($targetName === '') {
$targetName = (string) $assistantAdminId;
}
$perLog = [];
$errors = [];
$success = 0;
foreach ($ids as $oid) {
$order = PrescriptionOrder::where('id', $oid)->whereNull('delete_time')->find();
if (! $order) {
$errors[] = "订单{$oid}不存在或已删除";
continue;
}
$label = (string) ($order->order_no ?: $oid);
if (! self::canAccessOrder($order, $adminId, $adminInfo)) {
$errors[] = "订单{$label}无操作权限";
continue;
}
$oldCreatorId = (int) $order->creator_id;
if ($oldCreatorId === $assistantAdminId) {
$errors[] = "订单{$label}创建人已是该医助,已跳过";
continue;
}
$oldName = $oldCreatorId > 0
? (string) Admin::where('id', $oldCreatorId)->whereNull('delete_time')->value('name')
: '';
if ($oldName === '' && $oldCreatorId > 0) {
$oldName = (string) $oldCreatorId;
} elseif ($oldName === '') {
$oldName = '—';
}
$order->creator_id = $assistantAdminId;
try {
$order->save();
} catch (\Throwable $e) {
$errors[] = "订单{$label}保存失败";
continue;
}
$summary = '创建人(医助)由「' . $oldName . '」改派为「' . $targetName . '」';
self::writeLog($oid, $adminId, $adminInfo, 'assign_assistant', $summary);
$perLog[] = ['order_id' => $oid, 'summary' => $summary];
$success++;
}
if ($success === 0) {
self::$error = $errors !== [] ? implode('', $errors) : '未能改派任何订单';
return false;
}
return [
'success' => $success,
'fail' => count($errors),
'errors' => $errors,
'per_log' => $perLog,
];
}
private static function writeLog(int $orderId, int $adminId, array $adminInfo, string $action, string $summary): void
{
$adminName = $adminInfo['name'] ?? '';