update
This commit is contained in:
@@ -111,8 +111,20 @@ final class OrdersRepository
|
||||
$params['source'] = $source;
|
||||
}
|
||||
|
||||
$statusGroup = trim((string) ($filters['status_group'] ?? ''));
|
||||
$status = trim((string) ($filters['status'] ?? ''));
|
||||
if ($status !== '') {
|
||||
if ($statusGroup !== '' && ctype_digit($statusGroup)) {
|
||||
$groupCodes = $this->statusCodesByGroupId((int) $statusGroup);
|
||||
if ($groupCodes !== []) {
|
||||
$placeholders = [];
|
||||
foreach ($groupCodes as $i => $code) {
|
||||
$key = 'sg' . $i;
|
||||
$placeholders[] = ':' . $key;
|
||||
$params[$key] = $code;
|
||||
}
|
||||
$where[] = $effectiveStatusSql . ' IN (' . implode(', ', $placeholders) . ')';
|
||||
}
|
||||
} elseif ($status !== '') {
|
||||
$where[] = $effectiveStatusSql . ' = :status';
|
||||
$params['status'] = $status;
|
||||
}
|
||||
@@ -398,6 +410,7 @@ final class OrdersRepository
|
||||
|
||||
if (!isset($groupMap[$groupId])) {
|
||||
$groupMap[$groupId] = [
|
||||
'id' => $groupId,
|
||||
'name' => trim((string) ($row['group_name'] ?? '')),
|
||||
'color_hex' => StringHelper::normalizeColorHex((string) ($row['group_color_hex'] ?? '#64748b')),
|
||||
'items' => [],
|
||||
@@ -418,6 +431,35 @@ final class OrdersRepository
|
||||
return array_values($groupMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function statusCodesByGroupId(int $groupId): array
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare(
|
||||
'SELECT code FROM order_statuses WHERE group_id = :gid AND is_active = 1 ORDER BY sort_order ASC'
|
||||
);
|
||||
$stmt->execute(['gid' => $groupId]);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
foreach ($rows as $code) {
|
||||
$trimmed = strtolower(trim((string) $code));
|
||||
if ($trimmed !== '') {
|
||||
$codes[] = $trimmed;
|
||||
}
|
||||
}
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user