mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 19:40:53 +08:00
feat: Add TUIC protocol support and fix user filtering/export issues
This commit is contained in:
66
app/Traits/QueryOperators.php
Normal file
66
app/Traits/QueryOperators.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait QueryOperators
|
||||
{
|
||||
/**
|
||||
* 获取查询运算符映射
|
||||
*
|
||||
* @param string $operator
|
||||
* @return string
|
||||
*/
|
||||
protected function getQueryOperator(string $operator): string
|
||||
{
|
||||
return match (strtolower($operator)) {
|
||||
'eq' => '=',
|
||||
'gt' => '>',
|
||||
'gte' => '>=',
|
||||
'lt' => '<',
|
||||
'lte' => '<=',
|
||||
'like' => 'like',
|
||||
'notlike' => 'not like',
|
||||
'null' => 'null',
|
||||
'notnull' => 'notnull',
|
||||
default => 'like'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询值格式化
|
||||
*
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function formatQueryValue(string $operator, mixed $value): mixed
|
||||
{
|
||||
return match (strtolower($operator)) {
|
||||
'like', 'notlike' => "%{$value}%",
|
||||
'null', 'notnull' => null,
|
||||
default => $value
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用查询条件
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $field
|
||||
* @param string $operator
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
protected function applyQueryCondition($query, string $field, string $operator, mixed $value): void
|
||||
{
|
||||
$queryOperator = $this->getQueryOperator($operator);
|
||||
|
||||
if ($queryOperator === 'null') {
|
||||
$query->whereNull($field);
|
||||
} elseif ($queryOperator === 'notnull') {
|
||||
$query->whereNotNull($field);
|
||||
} else {
|
||||
$query->where($field, $queryOperator, $this->formatQueryValue($operator, $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user