From 34bb1fdbcfeb47c9c2f1b2bfca4f897074fd7de3 Mon Sep 17 00:00:00 2001 From: socksprox <36358673+socksprox@users.noreply.github.com> Date: Tue, 2 Jun 2026 05:49:58 +0200 Subject: [PATCH] Rename v2_order.refund_amount to surplus_credit (#967) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old name was misleading — this column tracks surplus credit returned to the user's internal balance during plan upgrades, not a payment gateway refund. The new name aligns with the existing surplus_amount and surplus_order_ids naming convention. Co-authored-by: socksprox Co-authored-by: Cursor --- app/Models/Order.php | 2 +- app/Services/OrderService.php | 8 +++---- ...rename_refund_amount_to_surplus_credit.php | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2026_05_30_000000_rename_refund_amount_to_surplus_credit.php diff --git a/app/Models/Order.php b/app/Models/Order.php index dda0581..fea63ee 100755 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -18,7 +18,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property int $total_amount * @property int|null $handling_amount * @property int|null $balance_amount - * @property int|null $refund_amount + * @property int|null $surplus_credit * @property int|null $surplus_amount * @property int $type * @property int $status diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 900be59..1761315 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -103,8 +103,8 @@ class OrderService DB::transaction(function () use ($order, $plan) { $this->user = User::lockForUpdate()->find($order->user_id); - if ($order->refund_amount) { - $this->user->balance += $order->refund_amount; + if ($order->surplus_credit) { + $this->user->balance += $order->surplus_credit; } if ($order->surplus_order_ids) { @@ -158,7 +158,7 @@ class OrderService if ((int) admin_setting('surplus_enable', 1)) $this->getSurplusValue($user, $order); if ($order->surplus_amount >= $order->total_amount) { - $order->refund_amount = (int) ($order->surplus_amount - $order->total_amount); + $order->surplus_credit = (int) ($order->surplus_amount - $order->total_amount); $order->total_amount = 0; } else { $order->total_amount = (int) ($order->total_amount - $order->surplus_amount); @@ -256,7 +256,7 @@ class OrderService return; } - $orderAmountSum = $orders->sum(fn($item) => $item->total_amount + $item->balance_amount + $item->surplus_amount - $item->refund_amount); + $orderAmountSum = $orders->sum(fn($item) => $item->total_amount + $item->balance_amount + $item->surplus_amount - $item->surplus_credit); $orderMonthSum = $orders->sum(fn($item) => self::STR_TO_TIME[PlanService::getPeriodKey($item->period)] ?? 0); $firstOrderAt = $orders->min('created_at'); $expiredAt = Carbon::createFromTimestamp($firstOrderAt)->addMonths($orderMonthSum); diff --git a/database/migrations/2026_05_30_000000_rename_refund_amount_to_surplus_credit.php b/database/migrations/2026_05_30_000000_rename_refund_amount_to_surplus_credit.php new file mode 100644 index 0000000..e60af2c --- /dev/null +++ b/database/migrations/2026_05_30_000000_rename_refund_amount_to_surplus_credit.php @@ -0,0 +1,22 @@ +renameColumn('refund_amount', 'surplus_credit'); + }); + } + + public function down(): void + { + Schema::table('v2_order', function (Blueprint $table) { + $table->renameColumn('surplus_credit', 'refund_amount'); + }); + } +}; \ No newline at end of file