From 54cb3263779b3cce2c12502f8393486743e05ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 28 Dec 2021 11:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/OrderRefundCommand.php | 40 +++++++++++++++++++ .../Controllers/Account/WalletController.php | 4 +- app/Models/BalanceLog.php | 3 +- app/Models/WalletLog.php | 3 +- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/OrderRefundCommand.php b/app/Console/Commands/OrderRefundCommand.php index a4fc1117..848f7299 100644 --- a/app/Console/Commands/OrderRefundCommand.php +++ b/app/Console/Commands/OrderRefundCommand.php @@ -3,7 +3,11 @@ namespace App\Console\Commands; use App\Exceptions\BizException; +use App\Models\BalanceLog; use App\Models\OrderRefundLog; +use App\Models\WalletLog; +use App\Services\BalanceService; +use App\Services\WalletService; use App\Services\WeChatPayService; use Illuminate\Console\Command; use Illuminate\Support\Str; @@ -83,6 +87,42 @@ class OrderRefundCommand extends Command ]); } + /** + * 可提支付退款 + * + * @param \App\Models\OrderRefundLog $log + * @return void + */ + protected function refundByWallet(OrderRefundLog $log) + { + $order = $log->order; + + (new WalletService())->changeBalance($order->user, $order->total_amount, WalletLog::ACTION_ORDER_CANCELLED, '订单-取消', $order); + + $log->update([ + 'status' => OrderRefundLog::STATUS_SUCCESS, + 'failed_reason' => null, + ]); + } + + /** + * 余额支付退款 + * + * @param \App\Models\OrderRefundLog $log + * @return void + */ + protected function refundByBalance(OrderRefundLog $log) + { + $order = $log->order; + + (new BalanceService())->changeBalance($order->user, $order->total_amount, BalanceLog::ACTION_ORDER_CANCELLED, '订单-取消', $order); + + $log->update([ + 'status' => OrderRefundLog::STATUS_SUCCESS, + 'failed_reason' => null, + ]); + } + /** * 现金支付退款 * diff --git a/app/Endpoint/Api/Http/Controllers/Account/WalletController.php b/app/Endpoint/Api/Http/Controllers/Account/WalletController.php index 6c6fe66e..a5b91dc8 100644 --- a/app/Endpoint/Api/Http/Controllers/Account/WalletController.php +++ b/app/Endpoint/Api/Http/Controllers/Account/WalletController.php @@ -117,9 +117,9 @@ class WalletController extends Controller if ($payable instanceof Order) { if ($payLog->isWallet()) { - (new WalletService())->changeBalance($user, -$payable->total_amount, WalletLog::ACTION_ORDER_PAY, '订单-支付', $payable); + (new WalletService())->changeBalance($user, -$payable->total_amount, WalletLog::ACTION_ORDER_PAID, '订单-支付', $payable); } else { - (new BalanceService())->changeBalance($user, -$payable->total_amount, BalanceLog::ACTION_ORDER_PAY, '订单-支付', $payable); + (new BalanceService())->changeBalance($user, -$payable->total_amount, BalanceLog::ACTION_ORDER_PAID, '订单-支付', $payable); } } diff --git a/app/Models/BalanceLog.php b/app/Models/BalanceLog.php index 412fb67d..ec586bd3 100644 --- a/app/Models/BalanceLog.php +++ b/app/Models/BalanceLog.php @@ -6,7 +6,8 @@ use Illuminate\Database\Eloquent\Model; class BalanceLog extends Model { - public const ACTION_ORDER_PAY = 1; + public const ACTION_ORDER_PAID = 1; + public const ACTION_ORDER_CANCELLED = 1; /** * @var array diff --git a/app/Models/WalletLog.php b/app/Models/WalletLog.php index c9d58a92..8a911e66 100644 --- a/app/Models/WalletLog.php +++ b/app/Models/WalletLog.php @@ -6,7 +6,8 @@ use Illuminate\Database\Eloquent\Model; class WalletLog extends Model { - public const ACTION_ORDER_PAY = 1; + public const ACTION_ORDER_PAID = 1; + public const ACTION_ORDER_CANCELLED = 1; /** * @var array