6
0
Fork 0

订单退款

release
李静 2021-12-28 11:47:23 +08:00
parent 7b94a0bcf3
commit 54cb326377
4 changed files with 46 additions and 4 deletions

View File

@ -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,
]);
}
/**
* 现金支付退款
*

View File

@ -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);
}
}

View File

@ -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

View File

@ -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