订单退款任务重命名
parent
e38a17d1ad
commit
27576b78a1
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
use App\Models\OrderRefundTask;
|
use App\Models\OrderRefundJob;
|
||||||
use App\Services\WeChatPayService;
|
use App\Services\WeChatPayService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
@ -32,21 +32,21 @@ class OrderRefundCommand extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
OrderRefundTask::pending()->chunkById(200, function ($tasks) {
|
OrderRefundJob::pending()->chunkById(200, function ($jobs) {
|
||||||
foreach ($tasks as $task) {
|
foreach ($jobs as $job) {
|
||||||
try {
|
try {
|
||||||
$method = 'refundBy'.Str::studly($task->order->pay_way);
|
$method = 'refundBy'.Str::studly($job->order->pay_way);
|
||||||
|
|
||||||
if (! method_exists($this, $method)) {
|
if (! method_exists($this, $method)) {
|
||||||
throw new BizException('退款方式暂不支持');
|
throw new BizException('退款方式暂不支持');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->{$method}($task);
|
$this->{$method}($job);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
report($e);
|
report($e);
|
||||||
|
|
||||||
$task->update([
|
$job->update([
|
||||||
'status' => OrderRefundTask::STATUS_FAILED,
|
'status' => OrderRefundJob::STATUS_FAILED,
|
||||||
'failed_reason' => $e->getMessage(),
|
'failed_reason' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -59,26 +59,26 @@ class OrderRefundCommand extends Command
|
||||||
/**
|
/**
|
||||||
* 微信支付退款
|
* 微信支付退款
|
||||||
*
|
*
|
||||||
* @param \App\Models\OrderRefundTask $orderRefundTask
|
* @param \App\Models\OrderRefundJob $job
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function refundByWxpay(OrderRefundTask $orderRefundTask)
|
protected function refundByWxpay(OrderRefundJob $job)
|
||||||
{
|
{
|
||||||
$order = $orderRefundTask->order;
|
$order = $job->order;
|
||||||
|
|
||||||
(new WeChatPayService())->refundByOutTradeNumber(
|
(new WeChatPayService())->refundByOutTradeNumber(
|
||||||
$order->sn,
|
$order->sn,
|
||||||
$orderRefundTask->sn,
|
$job->sn,
|
||||||
$order->total_amount,
|
$order->total_amount,
|
||||||
$orderRefundTask->amount,
|
$job->amount,
|
||||||
[
|
[
|
||||||
'refund_desc' => $orderRefundTask->reason,
|
'refund_desc' => $job->reason,
|
||||||
'notify_url' => url(route('wxpay.order_refund_notify', [], false), [], true),
|
'notify_url' => url(route('wxpay.order_refund_notify', [], false), [], true),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$orderRefundTask->update([
|
$job->update([
|
||||||
'status' => OrderRefundTask::STATUS_SUCCESS,
|
'status' => OrderRefundJob::STATUS_SUCCESS,
|
||||||
'failed_reason' => null,
|
'failed_reason' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -86,13 +86,13 @@ class OrderRefundCommand extends Command
|
||||||
/**
|
/**
|
||||||
* 现金支付退款
|
* 现金支付退款
|
||||||
*
|
*
|
||||||
* @param \App\Models\OrderRefundTask $orderRefundTask
|
* @param \App\Models\OrderRefundJob $job
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function refundByOffline(OrderRefundTask $orderRefundTask)
|
protected function refundByOffline(OrderRefundJob $job)
|
||||||
{
|
{
|
||||||
$orderRefundTask->update([
|
$job->update([
|
||||||
'status' => OrderRefundTask::STATUS_SUCCESS,
|
'status' => OrderRefundJob::STATUS_SUCCESS,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace App\Endpoint\Callback\Http\Controllers;
|
||||||
use App\Events\OrderPaid;
|
use App\Events\OrderPaid;
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
use App\Models\OrderRefundTask;
|
use App\Models\OrderRefundJob;
|
||||||
use App\Services\OrderService;
|
use App\Services\OrderService;
|
||||||
use App\Services\WeChatPayService;
|
use App\Services\WeChatPayService;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
|
@ -74,10 +74,10 @@ class WeChatPayController extends Controller
|
||||||
|
|
||||||
// 退款失败
|
// 退款失败
|
||||||
if ($reqInfo['refund_status'] !== 'SUCCESS') {
|
if ($reqInfo['refund_status'] !== 'SUCCESS') {
|
||||||
$orderRefundTask = OrderRefundTask::where('sn', $reqInfo['out_refund_no'])->first();
|
$orderRefundJob = OrderRefundJob::where('sn', $reqInfo['out_refund_no'])->first();
|
||||||
|
|
||||||
$orderRefundTask?->update([
|
$orderRefundJob?->update([
|
||||||
'status' => OrderRefundTask::STATUS_FAILED,
|
'status' => OrderRefundJob::STATUS_FAILED,
|
||||||
'failed_reason' => $reqInfo['refund_status'] === 'CHANGE' ? '退款异常' : '退款关闭',
|
'failed_reason' => $reqInfo['refund_status'] === 'CHANGE' ? '退款异常' : '退款关闭',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,9 @@ class Order extends Model
|
||||||
/**
|
/**
|
||||||
* 属于此订单的退款任务
|
* 属于此订单的退款任务
|
||||||
*/
|
*/
|
||||||
public function refundTasks()
|
public function refundJobs()
|
||||||
{
|
{
|
||||||
return $this->hasMany(OrderRefundTask::class);
|
return $this->hasMany(OrderRefundJob::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class OrderRefundTask extends Model
|
class OrderRefundJob extends Model
|
||||||
{
|
{
|
||||||
public const STATUS_PENDING = 0; // 待处理
|
public const STATUS_PENDING = 0; // 待处理
|
||||||
public const STATUS_SUCCESS = 5; // 退款成功
|
public const STATUS_SUCCESS = 5; // 退款成功
|
||||||
|
|
@ -330,7 +330,7 @@ class AfterSaleService
|
||||||
$order = $afterSale->order;
|
$order = $afterSale->order;
|
||||||
if (in_array($afterSale->type, [AfterSale::TYPE_REFUND_AND_RETURN, AfterSale::TYPE_REFUND])) {
|
if (in_array($afterSale->type, [AfterSale::TYPE_REFUND_AND_RETURN, AfterSale::TYPE_REFUND])) {
|
||||||
//todo-执行实际退款操作;
|
//todo-执行实际退款操作;
|
||||||
$order->refundTasks()->create([
|
$order->refundJobs()->create([
|
||||||
'sn' => OrderHelper::serialNumber(),
|
'sn' => OrderHelper::serialNumber(),
|
||||||
'amount' => $afterSale->amount,
|
'amount' => $afterSale->amount,
|
||||||
'reason' => '取消订单',
|
'reason' => '取消订单',
|
||||||
|
|
|
||||||
|
|
@ -784,7 +784,7 @@ class OrderService
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order->isWaitShipping()) {
|
if ($order->isWaitShipping()) {
|
||||||
$order->refundTasks()->create([
|
$order->refundJobs()->create([
|
||||||
'sn' => OrderHelper::serialNumber(),
|
'sn' => OrderHelper::serialNumber(),
|
||||||
'amount' => $order->total_amount,
|
'amount' => $order->total_amount,
|
||||||
'reason' => '取消订单',
|
'reason' => '取消订单',
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class CreateOrderRefundTasksTable extends Migration
|
class CreateOrderRefundJobsTable extends Migration
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
|
|
@ -13,7 +13,7 @@ class CreateOrderRefundTasksTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('order_refund_tasks', function (Blueprint $table) {
|
Schema::create('order_refund_jobs', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('sn')->comment('退款单号');
|
$table->string('sn')->comment('退款单号');
|
||||||
$table->unsignedBigInteger('order_id')->comment('订单ID');
|
$table->unsignedBigInteger('order_id')->comment('订单ID');
|
||||||
|
|
@ -36,6 +36,6 @@ class CreateOrderRefundTasksTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('order_refund_tasks');
|
Schema::dropIfExists('order_refund_jobs');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue