Skip to content

Commit

Permalink
Merge pull request #42 from 974988176/main
Browse files Browse the repository at this point in the history
修改crud查找条件为in或not in查询
  • Loading branch information
walkor authored May 29, 2023
2 parents 366d51d + ee25dd0 commit d8a0149
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/plugin/admin/app/controller/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected function selectInput(Request $request): array
}
foreach ($where as $column => $value) {
if ($value === '' || !isset($allow_column[$column]) ||
(is_array($value) && (count($value) <= 1)) ||
(is_array($value) && (in_array($value[0], ['', 'undefined']) || in_array($value[1], ['', 'undefined'])))) {
unset($where[$column]);
}
Expand Down Expand Up @@ -134,10 +135,20 @@ protected function doSelect(array $where, string $field = null, string $order= '
} elseif (in_array($value[0], ['>', '=', '<', '<>', 'not like'])) {
$model = $model->where($column, $value[0], $value[1]);
} elseif ($value[0] == 'in') {
$model = $model->whereIn($column, $value[1]);
if (is_string($value[1])) {
$valArr = explode(",", trim($value[1]));
$valArr && $model = $model->whereIn($column, $valArr);
} else {
$model = $model->whereIn($column, $value[1]);
}
} elseif ($value[0] == 'not in') {
$model = $model->whereNotIn($column, $value[1]);
} elseif ($value[0] == 'null') {
if (is_string($value[1])) {
$valArr = explode(",", trim($value[1]));
$valArr && $model = $model->whereNotIn($column, $valArr);
} else {
$model = $model->whereNotIn($column, $value[1]);
}
}elseif ($value[0] == 'null') {
$model = $model->whereNull($column, $value[1]);
} elseif ($value[0] == 'not null') {
$model = $model->whereNotNull($column, $value[1]);
Expand Down

0 comments on commit d8a0149

Please sign in to comment.