This commit is contained in:
root 2020-01-02 21:38:32 +08:00
parent aceff450ec
commit b8c8335542
4 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,53 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\TutorialSave;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Tutorial;
class TutorialController extends Controller
{
public function fetch (Request $request) {
return response([
'data' => 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
]);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class TutorialSave extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required',
'description' => 'required',
];
}
public function messages()
{
return [
'title.required' => '标题不能为空',
'description.required' => '描述不能为空',
];
}
}

View File

@ -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')

View File

@ -106,3 +106,13 @@ CREATE TABLE `v2_coupon` (
ALTER TABLE `v2_order`
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
);