forked from kvnZero/hyperf-APIJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhereSubQueryHandle.php
More file actions
32 lines (29 loc) · 1.01 KB
/
WhereSubQueryHandle.php
File metadata and controls
32 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace App\ApiJson\Handle;
class WhereSubQueryHandle extends AbstractHandle
{
protected function buildModel()
{
foreach (array_filter($this->condition->getCondition(), function($key){
return str_ends_with($key, '@');
}, ARRAY_FILTER_USE_KEY) as $key => $value)
{
$query = $this->subTableQuery($value);
$op = ' = ';
if(str_ends_with($key, '>=@')) {
$op = ' >= ';
} else if(str_ends_with($key, '<=@')) {
$op = ' <= ';
} else if(str_ends_with($key, '>@')) {
$op = ' > ';
} else if(str_ends_with($key, '<@')) {
$op = ' < ';
} else if(str_ends_with($key, '{}@')) {
$op = ' IN ';
}
$sql = sprintf('`%s`%s(%s)', $this->sanitizeKey($key), $op, $query->toSql());
$this->condition->addQueryWhere($key, $sql, $query->getBindings());
$this->unsetKey[] = $key;
}
}
}