diff --git a/app/Http/Controllers/Admin/TutorialController.php b/app/Http/Controllers/Admin/TutorialController.php new file mode 100644 index 00000000..5ccc8b91 --- /dev/null +++ b/app/Http/Controllers/Admin/TutorialController.php @@ -0,0 +1,53 @@ + Tutorial::all() + ]); + } + + public function save (TutorialSave $request) { + $params = $request->only([ + 'title', + 'description' + ]); + + if (!$request->input('id')) { + if (!Tutorial::create($params)) { + abort(500, '创建失败'); + } + } else { + if (!Tutorial::find($request->input('id'))->update($params)) { + abort(500, '保存失败'); + } + } + + return response([ + 'data' => true + ]); + } + + public function show (Request $request) { + if (empty($request->input('id'))) { + abort(500, '参数有误'); + } + $tutorial = Tutorial::find($request->input('id')); + $tutorial->show = $tutorial->show ? 0 : 1; + if (!$tutorial->save()) { + abort(500, '保存失败'); + } + + return response([ + 'data' => true + ]); + } +} \ No newline at end of file diff --git a/app/Http/Requests/Admin/TutorialSave.php b/app/Http/Requests/Admin/TutorialSave.php new file mode 100644 index 00000000..8d5035fe --- /dev/null +++ b/app/Http/Requests/Admin/TutorialSave.php @@ -0,0 +1,29 @@ + 'required', + 'description' => 'required', + ]; + } + + public function messages() + { + return [ + 'title.required' => '标题不能为空', + 'description.required' => '描述不能为空', + ]; + } +} diff --git a/routes/api.php b/routes/api.php index 96b974e5..8259caaa 100755 --- a/routes/api.php +++ b/routes/api.php @@ -59,6 +59,10 @@ Route::prefix('v1') // Coupon Route::get ('coupon/fetch', 'Admin\\CouponController@fetch'); Route::post('coupon/save', 'Admin\\CouponController@save'); + // Tutorial + Route::get ('tutorial/fetch', 'Admin\\TutorialController@fetch'); + Route::post('tutorial/save', 'Admin\\TutorialController@save'); + Route::post('tutorial/show', 'Admin\\TutorialController@show'); }); // User Route::prefix('user') diff --git a/update.sql b/update.sql index f3f0c29d..51b12cf2 100644 --- a/update.sql +++ b/update.sql @@ -105,4 +105,14 @@ CREATE TABLE `v2_coupon` ( ); ALTER TABLE `v2_order` -ADD `discount_amount` int(11) NULL AFTER `total_amount`; \ No newline at end of file +ADD `discount_amount` int(11) NULL AFTER `total_amount`; + +CREATE TABLE `v2_tutorial` ( + `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, + `title` varchar(255) COLLATE 'utf8mb4_general_ci' NOT NULL, + `description` varchar(255) COLLATE 'utf8mb4_general_ci' NOT NULL, + `steps` text NULL, + `show` tinyint(1) NOT NULL DEFAULT '0', + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL +); \ No newline at end of file