订单退款
parent
7b94a0bcf3
commit
54cb326377
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 现金支付退款
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue