Skip to content

Commit

Permalink
chore: improve error message when failing to create order (#22)
Browse files Browse the repository at this point in the history
* chore: improve error message when failing to create order

* chore: update text

---------

Co-authored-by: M1Screw <14369594+M1Screw@users.noreply.github.com>
  • Loading branch information
pplulee and AutisticShark committed Apr 4, 2024
1 parent 4dc80dc commit 908e754
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/Controllers/User/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ final class OrderController extends BaseController
],
];

private static string $err_msg = '订单创建失败';

/**
* @throws Exception
*/
Expand Down Expand Up @@ -124,7 +122,7 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($product === null || $product->stock === 0) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '商品不存在或库存不足',
]);
}

Expand All @@ -134,7 +132,7 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($user->is_shadow_banned) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '商品不存在或库存不足',
]);
}

Expand All @@ -144,7 +142,7 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($coupon === null || ($coupon->expire_time !== 0 && $coupon->expire_time < time())) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '优惠码不存在或已过期',
]);
}

Expand All @@ -153,14 +151,14 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($coupon_limit->disabled) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '优惠码已被禁用',
]);
}

if ($coupon_limit->product_id !== '' && ! in_array($product_id, explode(',', $coupon_limit->product_id))) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '优惠码不适用于此商品',
]);
}

Expand All @@ -171,7 +169,7 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($user_use_count >= $coupon_use_limit) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '优惠码使用次数已达上限',
]);
}
}
Expand All @@ -185,7 +183,7 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($coupon_total_use_limit > 0 && $coupon->use_count >= $coupon_total_use_limit) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '优惠码使用次数已达上限',
]);
}

Expand All @@ -205,15 +203,15 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($product_limit->class_required !== '' && $user->class < (int) $product_limit->class_required) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '您的账户等级不足,无法购买此商品',
]);
}

if ($product_limit->node_group_required !== ''
&& $user->node_group !== (int) $product_limit->node_group_required) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '您所在的用户组无法购买此商品',
]);
}

Expand All @@ -222,7 +220,7 @@ public function process(ServerRequest $request, Response $response, array $args)
if ($order_count > 0) {
return $response->withJson([
'ret' => 0,
'msg' => self::$err_msg,
'msg' => '此商品仅限新用户购买',
]);
}
}
Expand Down

0 comments on commit 908e754

Please sign in to comment.