diff --git a/app/Console/Commands/OrderTimeoutHandlerCommand.php b/app/Console/Commands/OrderTimeoutHandlerCommand.php index b00d12efb..f31baa131 100644 --- a/app/Console/Commands/OrderTimeoutHandlerCommand.php +++ b/app/Console/Commands/OrderTimeoutHandlerCommand.php @@ -12,21 +12,12 @@ use Illuminate\Console\Command; use App\Services\Order\Services\OrderService; use App\Services\Order\Interfaces\OrderServiceInterface; +use Symfony\Component\Console\Command\Command as CommandAlias; class OrderTimeoutHandlerCommand extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'order:pay:timeout'; - /** - * The console command description. - * - * @var string - */ protected $description = '订单超时处理(自动置为已取消=无法继续支付)'; /** @@ -34,33 +25,26 @@ class OrderTimeoutHandlerCommand extends Command */ protected $orderService; - /** - * OrderTimeoutHandlerCommand constructor. - * - * @param OrderServiceInterface $orderService - */ public function __construct(OrderServiceInterface $orderService) { parent::__construct(); $this->orderService = $orderService; } - /** - * @throws \App\Exceptions\ServiceException - */ + public function handle() { - // 超时一个小时未支付订单 $now = Carbon::now()->subMinutes(60); $orders = $this->orderService->getTimeoutOrders($now->toDateTimeString()); if (!$orders) { - return; + return CommandAlias::SUCCESS; } + foreach ($orders as $order) { $this->line($order['order_id']); $this->orderService->cancel($order['id']); } - return 0; + return CommandAlias::SUCCESS; } } diff --git a/app/Http/Controllers/Backend/Api/V1/OrderController.php b/app/Http/Controllers/Backend/Api/V1/OrderController.php index b95a7fbd9..9d0e59ecf 100644 --- a/app/Http/Controllers/Backend/Api/V1/OrderController.php +++ b/app/Http/Controllers/Backend/Api/V1/OrderController.php @@ -21,7 +21,9 @@ use App\Services\Order\Models\Order; use App\Services\Order\Models\OrderGoods; use App\Services\Order\Models\OrderRefund; +use App\Services\Order\Services\OrderService; use App\Services\Order\Models\OrderPaidRecord; +use App\Services\Order\Interfaces\OrderServiceInterface; class OrderController extends BaseController { @@ -160,12 +162,15 @@ public function detail($id) public function finishOrder($id) { $order = Order::query()->where('id', $id)->firstOrFail(); - event(new PaymentSuccessEvent($order->toArray())); + AdministratorLog::storeLog( AdministratorLog::MODULE_ORDER, AdministratorLog::OPT_UPDATE, compact('id') ); + + event(new PaymentSuccessEvent($order->toArray())); + return $this->success(); } @@ -359,7 +364,7 @@ public function refundOrders(Request $request) public function deleteRefundOrder($id) { $refundOrder = OrderRefund::query()->where('id', $id)->firstOrFail(); - $orderAllRefundOrdersCount = (int)OrderRefund::query()->where('order_id', $refundOrder['order_id'])->count(); + $orderAllRefundOrdersCount = OrderRefund::query()->where('order_id', $refundOrder['order_id'])->count(); DB::transaction(function () use ($refundOrder, $orderAllRefundOrdersCount) { AdministratorLog::storeLog( AdministratorLog::MODULE_ORDER, @@ -379,4 +384,27 @@ public function deleteRefundOrder($id) }); return $this->success(); } + + public function cancel(OrderServiceInterface $orderService, $id) + { + + /** + * @var OrderService $orderService + */ + + $order = Order::query()->where('id', $id)->firstOrFail(); + if (!in_array($order['status'], [Order::STATUS_UNPAY, Order::STATUS_PAYING])) { + return $this->error(__('订单状态异常')); + } + + AdministratorLog::storeLog( + AdministratorLog::MODULE_ORDER, + AdministratorLog::OPT_UPDATE, + compact('id') + ); + + $orderService->cancel($order['id']); + + return $this->success(); + } } diff --git a/database/seeders/AdministratorPermissionSeeder.php b/database/seeders/AdministratorPermissionSeeder.php index 75b29f1cb..d7b33bdac 100644 --- a/database/seeders/AdministratorPermissionSeeder.php +++ b/database/seeders/AdministratorPermissionSeeder.php @@ -574,6 +574,12 @@ public function run() 'method' => 'DELETE', 'url' => 'order/refund/\d+', ], + [ + 'display_name' => '订单-取消订单', + 'slug' => 'order.cancel', + 'method' => 'GET', + 'url' => 'order/\d+/cancel', + ], ], ], diff --git a/routes/backend-v1.php b/routes/backend-v1.php index 72520a419..979171145 100644 --- a/routes/backend-v1.php +++ b/routes/backend-v1.php @@ -252,6 +252,7 @@ Route::get('/', 'OrderController@index'); Route::get('/{id}', 'OrderController@detail'); Route::get('/{id}/finish', 'OrderController@finishOrder'); + Route::get('/{id}/cancel', 'OrderController@cancel'); Route::post('/{id}/refund', 'OrderController@submitRefund'); Route::get('/refund/list', 'OrderController@refundOrders'); Route::delete('/refund/{id}', 'OrderController@deleteRefundOrder');