From 42bdfafd4c497dc99463cba346a4ab2ec706b5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 20 Dec 2021 13:59:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=96=E6=B6=88=E8=AE=A2?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/Order/OrderController.php | 12 +++++++----- app/Helpers/Order.php | 6 +----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Order/OrderController.php b/app/Endpoint/Api/Http/Controllers/Order/OrderController.php index db9c1681..fae9b3d0 100644 --- a/app/Endpoint/Api/Http/Controllers/Order/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Order/OrderController.php @@ -6,6 +6,7 @@ use App\Endpoint\Api\Http\Controllers\Controller; use App\Endpoint\Api\Http\Resources\OrderResource; use App\Endpoint\Api\Http\Resources\OrderResourceCollection; use App\Exceptions\BizException; +use App\Helpers\Order as OrderHelper; use App\Helpers\Paginator as PaginatorHelper; use App\Models\Order; use App\Services\OrderService; @@ -72,7 +73,7 @@ class OrderController extends Controller $user = $request->user(); try { - $order = DB::transaction(function () use ($isQuick, $user, $request) { + $order = DB::transaction(function () use ($isQuick, $user, $request) { $orderService = new OrderService(); if ($isQuick) { @@ -94,7 +95,7 @@ class OrderController extends Controller $request->input('note'), ); }, 3); - } catch (BizException | ModelNotFoundException $e) { + } catch (ModelNotFoundException | BizException $e) { throw $e; } catch (Throwable $e) { report($e); @@ -155,6 +156,7 @@ class OrderController extends Controller if ($order->isWaitShipping()) { $order->refundTasks()->create([ + 'sn' => OrderHelper::serialNumber(), 'amount' => $order->total_amount, ]); } @@ -163,12 +165,12 @@ class OrderController extends Controller 'status' => Order::STATUS_CANCELLED, ]); }); - } catch (BizException $e) { + } catch (ModelNotFoundException | BizException $e) { throw $e; } catch (Throwable $e) { report($e); - throw new BizException('订单支付失败,请重试'); + throw new BizException('取消失败,请重试'); } return response()->noContent(); @@ -195,7 +197,7 @@ class OrderController extends Controller return (new OrderService())->pay($order, $input['pay_way']); }); - } catch (BizException $e) { + } catch (ModelNotFoundException | BizException $e) { throw $e; } catch (Throwable $e) { report($e); diff --git a/app/Helpers/Order.php b/app/Helpers/Order.php index d8c07d32..f2ced01d 100644 --- a/app/Helpers/Order.php +++ b/app/Helpers/Order.php @@ -2,8 +2,6 @@ namespace App\Helpers; -use Illuminate\Support\Str; - class Order { /** @@ -13,8 +11,6 @@ class Order */ public static function serialNumber(): string { - $rand = strtoupper(Str::random(6)); - - return date('YmdHis').$rand; + return date('YmdHis').sprintf('%06d', mt_rand(1, 999999)); } }