update: user filter

This commit is contained in:
Tokumeikoi 2020-10-18 19:21:21 +08:00
parent 392c3677bc
commit 550a787c1a
3 changed files with 9 additions and 9 deletions

View File

@ -19,17 +19,17 @@ class UserController extends Controller
private function filter(Request $request, $builder)
{
if ($request->input('filter')) {
$request->validate([
'filter' => 'array',
'filter.*.key' => 'required|in:email,transfer_enable,d,expired_at,uuid,token',
'filter.*.condition' => 'required|in:>,<,=,>=,<=',
'filter.*.value' => 'required'
]);
foreach ($request->input('filter') as $filter) {
if ($filter['key'] === 'email' && $filter['condition'] === '=') {
if ($filter['key'] === 'email') {
$builder->where($filter['key'], 'like', '%' . $filter['value'] . '%');
continue;
}
if ($filter['key'] === 'invite_by_email') {
$user = User::where('email', $filter['value'])->first();
if (!$user) continue;
$builder->where('invite_user_id', $user->id);
continue;
}
if ($filter['key'] === 'd' || $filter['key'] === 'transfer_enable') {
$filter['value'] = $filter['value'] * 1073741824;
}

View File

@ -14,7 +14,7 @@ class UserFetch extends FormRequest
public function rules()
{
return [
'filter.*.key' => 'required|in:email,transfer_enable,d,expired_at,uuid,token',
'filter.*.key' => 'required|in:id,email,transfer_enable,d,expired_at,uuid,token,invite_by_email,invite_user_id',
'filter.*.condition' => 'required|in:>,<,=,>=,<=',
'filter.*.value' => 'required'
];

File diff suppressed because one or more lines are too long