From 9eefb32a4cb1e7efbc33e154a384f88caf32305e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Jan 2020 15:59:53 +0800 Subject: [PATCH] update --- app/Http/Controllers/CoponController.php | 16 ++++++++++++++++ install.sql | 8 +++++--- routes/api.php | 2 ++ update.sql | 11 +++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/CoponController.php b/app/Http/Controllers/CoponController.php index 7bb88b09..b2c5a0b3 100644 --- a/app/Http/Controllers/CoponController.php +++ b/app/Http/Controllers/CoponController.php @@ -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 + ]); } } diff --git a/install.sql b/install.sql index 5dfee6a3..bcaadee2 100644 --- a/install.sql +++ b/install.sql @@ -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 \ No newline at end of file +-- 2019-12-31 17:47:41 \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index eee6b7ca..65b3ae40 100755 --- a/routes/api.php +++ b/routes/api.php @@ -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 diff --git a/update.sql b/update.sql index 268907c1..9741eeef 100644 --- a/update.sql +++ b/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 ); \ No newline at end of file