fix user sorter

This commit is contained in:
Tokumeikoi 2020-02-09 18:53:45 +08:00
parent 5db26d862b
commit cb8cdb2e0e
3 changed files with 6 additions and 5 deletions

View File

@ -11,6 +11,7 @@ class ConfigController extends Controller
{ {
public function fetch() public function fetch()
{ {
// TODO: default should be in Dict
return response([ return response([
'data' => [ 'data' => [
'invite' => [ 'invite' => [
@ -24,6 +25,7 @@ class ConfigController extends Controller
'stop_register' => (int)config('v2board.stop_register', 0), 'stop_register' => (int)config('v2board.stop_register', 0),
'email_verify' => (int)config('v2board.email_verify', 0), 'email_verify' => (int)config('v2board.email_verify', 0),
'app_name' => config('v2board.app_name', 'V2Board'), 'app_name' => config('v2board.app_name', 'V2Board'),
'app_description' => config('v2board.app_description', 'V2Board is best!'),
'app_url' => config('v2board.app_url'), 'app_url' => config('v2board.app_url'),
'subscribe_url' => config('v2board.subscribe_url'), 'subscribe_url' => config('v2board.subscribe_url'),
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1), 'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),

View File

@ -15,14 +15,12 @@ class UserController extends Controller
{ {
$current = $request->input('current') ? $request->input('current') : 1; $current = $request->input('current') ? $request->input('current') : 1;
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
$sortType = $request->input('sort_type') ? 'ASC' : 'DESC'; $sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
$userModel = User::orderBy('created_at', 'DESC'); $sort = $request->input('sort') ? $request->input('sort') : 'created_at';
$userModel = User::orderBy($sort, $sortType);
if ($request->input('email')) { if ($request->input('email')) {
$userModel->where('email', $request->input('email')); $userModel->where('email', $request->input('email'));
} }
if ($request->input('sort')) {
$userModel->orderBy($request->input('sort'), $sortType);
}
$total = $userModel->count(); $total = $userModel->count();
$res = $userModel->forPage($current, $pageSize) $res = $userModel->forPage($current, $pageSize)
->get(); ->get();

View File

@ -15,6 +15,7 @@ class ConfigSave extends FormRequest
'stop_register' => 'in:0,1', 'stop_register' => 'in:0,1',
'email_verify' => 'in:0,1', 'email_verify' => 'in:0,1',
'app_name' => '', 'app_name' => '',
'app_description' => '',
'app_url' => 'url', 'app_url' => 'url',
'subscribe_url' => 'url', 'subscribe_url' => 'url',
'plan_transfer_hour' => 'numeric', 'plan_transfer_hour' => 'numeric',