This commit is contained in:
Your Name
2026-04-30 17:36:47 +08:00
parent 4c21ee5938
commit 7e557b1ea2
33 changed files with 8718 additions and 94 deletions
@@ -289,6 +289,45 @@ class OrderController extends BaseAdminController
return $this->success($msg, $result);
}
/**
* @notes 拆分订单:生成多笔子单(待支付/待审核/已支付继承支付信息),金额合计须等于原单;原单软删除;业务订单关联自动迁移
* @return \think\response\Json
*/
public function split()
{
$params = (new OrderValidate())->post()->goCheck('split');
$orderId = (int) $params['id'];
$amounts = $params['amounts'] ?? [];
if (! is_array($amounts)) {
return $this->fail('子单金额格式错误');
}
$orderTypes = $params['order_types'] ?? [];
if (! is_array($orderTypes)) {
return $this->fail('子单订单类型格式错误');
}
$order = \app\common\model\Order::find($orderId);
if (! $order) {
return $this->fail('订单不存在');
}
if (! $this->canEditOrder($order)) {
return $this->fail('无权限拆分此订单');
}
$result = OrderLogic::split($orderId, $amounts, $orderTypes);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
$summary = '拆分为子单 id=' . implode(',', $result['new_order_ids'] ?? []);
$this->logOrderAction($orderId, 'split', $summary);
foreach ($result['new_order_ids'] ?? [] as $nid) {
$this->logOrderAction((int) $nid, 'split_child', '来源原单 id=' . $orderId . ' ' . (string) ($order->order_no ?? ''));
}
return $this->success('拆分成功', $result);
}
/**
* @notes 编辑订单(关联患者、订单类型)
* 权限:超管或指定角色组可修改任意订单;其他用户只能修改自己创建的订单