mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update
This commit is contained in:
parent
2eb594a4fa
commit
9eefb32a4c
@ -9,5 +9,21 @@ use App\Models\Coupon;
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function check (Request $request) {
|
||||
if (empty($request->input('code'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$coupon = Coupon::where('code', $request->input('code'))->first();
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券无效');
|
||||
}
|
||||
if (time() < $coupon->started_at) {
|
||||
abort(500, '优惠券还未到可用时间');
|
||||
}
|
||||
if (time() > $coupon->ended_at) {
|
||||
abort(500, '优惠券已过期');
|
||||
}
|
||||
return response([
|
||||
'data' => $coupon
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,13 @@ SET NAMES utf8mb4;
|
||||
DROP TABLE IF EXISTS `v2_coupon`;
|
||||
CREATE TABLE `v2_coupon` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`code` char(8) NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
|
||||
`type` tinyint(1) NOT NULL,
|
||||
`value` int(11) NOT NULL,
|
||||
`status` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`expired_at` int(11) NOT NULL,
|
||||
`limit_use` int(11) DEFAULT NULL,
|
||||
`started_at` int(11) NOT NULL,
|
||||
`ended_at` int(11) NOT NULL,
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
@ -200,4 +202,4 @@ CREATE TABLE `v2_user` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- 2019-12-31 09:09:02
|
||||
-- 2019-12-31 17:47:41
|
@ -98,6 +98,8 @@ Route::prefix('v1')
|
||||
// Server
|
||||
Route::get ('server/fetch', 'ServerController@fetch');
|
||||
Route::get ('server/log/fetch', 'ServerController@logFetch');
|
||||
// Coupon
|
||||
Route::post('coupon/check', 'CouponController@check');
|
||||
});
|
||||
|
||||
// Passport
|
||||
|
11
update.sql
11
update.sql
@ -102,4 +102,15 @@ CREATE TABLE `v2_coupon` (
|
||||
`ended_at` int(11) NOT NULL,
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL,
|
||||
);
|
||||
|
||||
CREATE TABLE `v2_coupon_log` (
|
||||
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`coupon_id` int(11) NOT NULL,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`order_id` int(11) NOT NULL,
|
||||
`total_amount` int(11) NOT NULL,
|
||||
`discount_amount` int(11) NOT NULL,
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL
|
||||
);
|
Loading…
Reference in New Issue
Block a user