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()
{
// TODO: default should be in Dict
return response([
'data' => [
'invite' => [
@ -24,6 +25,7 @@ class ConfigController extends Controller
'stop_register' => (int)config('v2board.stop_register', 0),
'email_verify' => (int)config('v2board.email_verify', 0),
'app_name' => config('v2board.app_name', 'V2Board'),
'app_description' => config('v2board.app_description', 'V2Board is best!'),
'app_url' => config('v2board.app_url'),
'subscribe_url' => config('v2board.subscribe_url'),
'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;
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
$sortType = $request->input('sort_type') ? 'ASC' : 'DESC';
$userModel = User::orderBy('created_at', 'DESC');
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
$userModel = User::orderBy($sort, $sortType);
if ($request->input('email')) {
$userModel->where('email', $request->input('email'));
}
if ($request->input('sort')) {
$userModel->orderBy($request->input('sort'), $sortType);
}
$total = $userModel->count();
$res = $userModel->forPage($current, $pageSize)
->get();

View File

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