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