This commit is contained in:
Tokumeikoi 2020-04-20 16:07:06 +08:00
parent 50b5ed6b8e
commit 3b486e4693
10 changed files with 109 additions and 25 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\PlanSave;
use App\Http\Requests\Admin\PlanSort;
use App\Http\Requests\Admin\PlanUpdate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
@ -16,7 +17,7 @@ class PlanController extends Controller
public function fetch(Request $request)
{
return response([
'data' => Plan::get()
'data' => Plan::orderBy('sort', 'ASC')->get()
]);
}
@ -91,4 +92,19 @@ class PlanController extends Controller
'data' => true
]);
}
public function sort(PlanSort $request)
{
DB::beginTransaction();
foreach ($request->input('plan_ids') as $k => $v) {
if (!Plan::find($v)->update(['sort' => $k + 1])) {
DB::rollBack();
abort(500, '保存失败');
}
}
DB::commit();
return response([
'data' => true
]);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\ServerSave;
use App\Http\Requests\Admin\ServerSort;
use App\Http\Requests\Admin\ServerUpdate;
use App\Services\ServerService;
use Illuminate\Http\Request;
@ -12,12 +13,13 @@ use App\Models\Server;
use App\Models\Plan;
use App\Models\User;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class ServerController extends Controller
{
public function fetch(Request $request)
{
$server = Server::get();
$server = Server::orderBy('sort', 'ASC')->get();
for ($i = 0; $i < count($server); $i++) {
if (!empty($server[$i]['tags'])) {
$server[$i]['tags'] = json_decode($server[$i]['tags']);
@ -206,4 +208,19 @@ class ServerController extends Controller
'data' => $config
]);
}
public function sort(ServerSort $request)
{
DB::beginTransaction();
foreach ($request->input('server_ids') as $k => $v) {
if (!Server::find($v)->update(['sort' => $k + 1])) {
DB::rollBack();
abort(500, '保存失败');
}
}
DB::commit();
return response([
'data' => true
]);
}
}

View File

@ -14,7 +14,7 @@ class TutorialController extends Controller
public function fetch(Request $request)
{
return response([
'data' => Tutorial::get()
'data' => Tutorial::orderBy('sort', 'ASC')->get()
]);
}
@ -60,22 +60,10 @@ 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])) {
foreach ($request->input('tutorial_ids') as $k => $v) {
if (!Tutorial::find($v)->update(['sort' => $k + 1])) {
DB::rollBack();
abort(500, '保存失败');
}
}

View File

@ -19,7 +19,7 @@ class ClientController extends Controller
$userService = new UserService();
if ($userService->isAvailable($user)) {
$servers = Server::where('show', 1)
->orderBy('name')
->orderBy('sort', 'ASC')
->get();
foreach ($servers as $item) {
$groupId = json_decode($item['group_id']);

View File

@ -52,6 +52,7 @@ class TutorialController extends Controller
}
$tutorial = Tutorial::select(['id', 'category_id', 'title'])
->where('show', 1)
->orderBy('sort', 'ASC')
->get()
->groupBy('category_id');
$user = User::find($request->session()->get('id'));

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class PlanSort extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'plan_ids' => 'required|array'
];
}
public function messages()
{
return [
'plan_ids.required' => '订阅计划ID不能为空',
'plan_ids.array' => '订阅计划ID格式有误'
];
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class ServerSort extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'server_ids' => 'required|array'
];
}
public function messages()
{
return [
'server_ids.required' => '服务器ID不能为空',
'server_ids.array' => '服务器ID格式有误'
];
}
}

View File

@ -14,17 +14,15 @@ class TutorialSort extends FormRequest
public function rules()
{
return [
'id' => 'required',
'sort' => 'required|integer'
'tutorial_ids' => 'required|array'
];
}
public function messages()
{
return [
'id.required' => '教程ID不能为空',
'sort.required' => '排序不能为空',
'sort.integer' => '排序格式有误'
'tutorial_ids.required' => '教程ID不能为空',
'tutorial_ids.array' => '教程ID格式有误'
];
}
}

View File

@ -20,6 +20,7 @@ class AdminRoute
$router->post('/plan/save', 'Admin\\PlanController@save');
$router->post('/plan/drop', 'Admin\\PlanController@drop');
$router->post('/plan/update', 'Admin\\PlanController@update');
$router->post('/plan/sort', 'Admin\\PlanController@sort');
// Server
$router->get ('/server/fetch', 'Admin\\ServerController@fetch');
$router->post('/server/save', 'Admin\\ServerController@save');
@ -30,6 +31,7 @@ class AdminRoute
$router->post('/server/update', 'Admin\\ServerController@update');
$router->post('/server/copy', 'Admin\\ServerController@copy');
$router->post('/server/viewConfig', 'Admin\\ServerController@viewConfig');
$router->post('/server/sort', 'Admin\\ServerController@sort');
// Order
$router->get ('/order/fetch', 'Admin\\OrderController@fetch');
$router->post('/order/repair', 'Admin\\OrderController@repair');

View File

@ -206,7 +206,7 @@ CHANGE `network` `network` text COLLATE 'utf8_general_ci' NOT NULL AFTER `rate`,
ADD `dnsSettings` text COLLATE 'utf8_general_ci' NULL AFTER `ruleSettings`;
-- 1.3
ALTER TABLE `v2_order`
ADD `surplus_order_ids` varchar(255) NULL COMMENT '折抵订单' AFTER `balance_amount`;
ADD `surplus_order_ids` text NULL COMMENT '折抵订单' AFTER `balance_amount`;
ALTER TABLE `v2_order`
CHANGE `status` `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0待支付1开通中2已取消3已完成4已折抵' AFTER `surplus_order_ids`;
@ -222,3 +222,9 @@ CREATE TABLE `v2_server_stat` (
ALTER TABLE `v2_tutorial`
ADD `sort` int(11) NULL AFTER `show`;
ALTER TABLE `v2_server`
ADD `sort` int(11) NULL AFTER `show`;
ALTER TABLE `v2_plan`
ADD `sort` int(11) NULL AFTER `show`;