mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update sql
This commit is contained in:
parent
39ae037080
commit
50b5ed6b8e
@ -3,9 +3,11 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\TutorialSave;
|
||||
use App\Http\Requests\Admin\TutorialSort;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Tutorial;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TutorialController extends Controller
|
||||
{
|
||||
@ -56,6 +58,33 @@ class TutorialController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function sort(TutorialSort $request)
|
||||
{
|
||||
$sort = $request->input('sort');
|
||||
$tutorial = Tutorial::find($request->input('id'))->first();
|
||||
if (!$tutorial) {
|
||||
abort(500, '教程不存在');
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$tutorial->sort = $sort;
|
||||
if (!$tutorial->save()) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
$tutorials = Tutorial::where('sort', '>', $sort)->get();
|
||||
foreach ($tutorials as $tutorial) {
|
||||
$sort++;
|
||||
if (!$tutorial->save(['sort' => $sort])) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Tutorial;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TutorialController extends Controller
|
||||
{
|
||||
|
30
app/Http/Requests/Admin/TutorialSort.php
Normal file
30
app/Http/Requests/Admin/TutorialSort.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TutorialSort extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'id' => 'required',
|
||||
'sort' => 'required|integer'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'id.required' => '教程ID不能为空',
|
||||
'sort.required' => '排序不能为空',
|
||||
'sort.integer' => '排序格式有误'
|
||||
];
|
||||
}
|
||||
}
|
@ -60,6 +60,7 @@ class AdminRoute
|
||||
$router->post('/tutorial/save', 'Admin\\TutorialController@save');
|
||||
$router->post('/tutorial/show', 'Admin\\TutorialController@show');
|
||||
$router->post('/tutorial/drop', 'Admin\\TutorialController@drop');
|
||||
$router->post('/tutorial/sort', 'Admin\\TutorialController@sort');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -210,3 +210,15 @@ ADD `surplus_order_ids` varchar(255) NULL COMMENT '折抵订单' AFTER `balance_
|
||||
|
||||
ALTER TABLE `v2_order`
|
||||
CHANGE `status` `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0待支付1开通中2已取消3已完成4已折抵' AFTER `surplus_order_ids`;
|
||||
|
||||
CREATE TABLE `v2_server_stat` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`server_id` int(11) NOT NULL,
|
||||
`u` varchar(255) NOT NULL,
|
||||
`d` varchar(25) NOT NULL,
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE `v2_tutorial`
|
||||
ADD `sort` int(11) NULL AFTER `show`;
|
||||
|
Loading…
Reference in New Issue
Block a user