forked from summerblue/laravel-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\CouponCode; | ||
use Carbon\Carbon; | ||
|
||
class CouponCodesController extends Controller | ||
{ | ||
public function show($code) | ||
{ | ||
// 判断优惠券是否存在 | ||
if (!$record = CouponCode::where('code', $code)->first()) { | ||
abort(404); | ||
} | ||
|
||
// 如果优惠券没有启用,则等同于优惠券不存在 | ||
if (!$record->enabled) { | ||
abort(404); | ||
} | ||
|
||
if ($record->total - $record->used <= 0) { | ||
return response()->json(['msg' => '该优惠券已被兑完'], 403); | ||
} | ||
|
||
if ($record->not_before && $record->not_before->gt(Carbon::now())) { | ||
return response()->json(['msg' => '该优惠券现在还不能使用'], 403); | ||
} | ||
|
||
if ($record->not_after && $record->not_after->lt(Carbon::now())) { | ||
return response()->json(['msg' => '该优惠券已过期'], 403); | ||
} | ||
|
||
return $record; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters