feat(platform-orders): 支持支付回执留痕(meta.payment_receipts)
This commit is contained in:
@@ -302,6 +302,24 @@ class PlatformOrderController extends Controller
|
||||
$order->paid_at = $order->paid_at ?: $now;
|
||||
$order->activated_at = $order->activated_at ?: $now;
|
||||
$order->paid_amount = $order->paid_amount > 0 ? $order->paid_amount : $order->payable_amount;
|
||||
|
||||
// 兼容:若尚未写入“支付回执”,则自动补一条(可治理)
|
||||
$meta = (array) ($order->meta ?? []);
|
||||
$receipts = (array) (data_get($meta, 'payment_receipts', []) ?? []);
|
||||
if (count($receipts) === 0) {
|
||||
$receipts[] = [
|
||||
'type' => 'manual_mark_paid',
|
||||
'channel' => (string) ($order->payment_channel ?? ''),
|
||||
'amount' => (float) $order->paid_amount,
|
||||
'paid_at' => $order->paid_at ? $order->paid_at->format('Y-m-d H:i:s') : $now->toDateTimeString(),
|
||||
'note' => '由【标记支付并生效】自动补记(可治理)',
|
||||
'created_at' => $now->toDateTimeString(),
|
||||
'admin_id' => $admin->id,
|
||||
];
|
||||
data_set($meta, 'payment_receipts', $receipts);
|
||||
$order->meta = $meta;
|
||||
}
|
||||
|
||||
$order->save();
|
||||
|
||||
// 立刻同步订阅
|
||||
@@ -328,6 +346,40 @@ class PlatformOrderController extends Controller
|
||||
return redirect()->back()->with('success', '订单已标记支付并生效,订阅已同步:' . $subscription->subscription_no);
|
||||
}
|
||||
|
||||
public function addPaymentReceipt(Request $request, PlatformOrder $order): RedirectResponse
|
||||
{
|
||||
$admin = $this->ensurePlatformAdmin($request);
|
||||
|
||||
$data = $request->validate([
|
||||
'type' => ['required', 'string', 'max:30'],
|
||||
'channel' => ['nullable', 'string', 'max:30'],
|
||||
'amount' => ['required', 'numeric', 'min:0'],
|
||||
'paid_at' => ['nullable', 'date'],
|
||||
'note' => ['nullable', 'string', 'max:2000'],
|
||||
]);
|
||||
|
||||
$now = now();
|
||||
|
||||
$meta = (array) ($order->meta ?? []);
|
||||
$receipts = (array) (data_get($meta, 'payment_receipts', []) ?? []);
|
||||
|
||||
$receipts[] = [
|
||||
'type' => (string) $data['type'],
|
||||
'channel' => (string) ($data['channel'] ?? ''),
|
||||
'amount' => (float) $data['amount'],
|
||||
'paid_at' => $data['paid_at'] ? (string) $data['paid_at'] : null,
|
||||
'note' => (string) ($data['note'] ?? ''),
|
||||
'created_at' => $now->toDateTimeString(),
|
||||
'admin_id' => $admin->id,
|
||||
];
|
||||
|
||||
data_set($meta, 'payment_receipts', $receipts);
|
||||
$order->meta = $meta;
|
||||
$order->save();
|
||||
|
||||
return redirect()->back()->with('success', '已追加支付回执记录(仅用于对账留痕,不自动改状态)。');
|
||||
}
|
||||
|
||||
public function markActivated(Request $request, PlatformOrder $order): RedirectResponse
|
||||
{
|
||||
$admin = $this->ensurePlatformAdmin($request);
|
||||
|
||||
Reference in New Issue
Block a user