update
This commit is contained in:
@@ -52,6 +52,54 @@ class CustomerRepository extends BaseRepository implements CustomerRepositoryInt
|
||||
if (isset($data['phone']) && ! empty($data['phone'])) {
|
||||
$model = $model->where("phone", "LIKE", "%" . $data['phone'] . "%");
|
||||
}
|
||||
if (isset($data['service_type']) && ! empty($data['service_type'])) {
|
||||
$types = is_array($data['service_type'])
|
||||
? $data['service_type']
|
||||
: array_filter(array_map('trim', explode(',', (string) $data['service_type'])));
|
||||
|
||||
$simpleMap = [
|
||||
'hosting' => 'hosting',
|
||||
'vps' => 'vps',
|
||||
'domain' => 'domain',
|
||||
'service' => 'service',
|
||||
];
|
||||
|
||||
$simpleRelations = array_values(array_intersect_key($simpleMap, array_flip($types)));
|
||||
$hasDns = in_array('dns', $types, true);
|
||||
|
||||
if (! empty($simpleRelations) || $hasDns) {
|
||||
$dnsIds = $hasDns
|
||||
? \Illuminate\Support\Facades\DB::table('dns_domain_user')->pluck('user_id')
|
||||
: collect();
|
||||
|
||||
$model = $model->where(function ($q) use ($simpleRelations, $dnsIds) {
|
||||
foreach ($simpleRelations as $relation) {
|
||||
$q->orWhereHas($relation);
|
||||
}
|
||||
if ($dnsIds->isNotEmpty()) {
|
||||
$q->orWhereIn('customers.id', $dnsIds);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['domain']) && ! empty($data['domain'])) {
|
||||
$domain = trim((string) $data['domain']);
|
||||
$dnsCustomerIds = \Illuminate\Support\Facades\DB::table('dns_domain_user')
|
||||
->join('dns_manager_domain', 'dns_manager_domain.id', '=', 'dns_domain_user.domain_id')
|
||||
->where('dns_manager_domain.domain_name', 'like', "%{$domain}%")
|
||||
->pluck('dns_domain_user.user_id');
|
||||
|
||||
$model = $model->where(function ($q) use ($domain, $dnsCustomerIds) {
|
||||
$q->whereHas('domain', function ($sub) use ($domain) {
|
||||
$sub->where('name', 'like', "%{$domain}%");
|
||||
});
|
||||
if ($dnsCustomerIds->isNotEmpty()) {
|
||||
$q->orWhereIn('customers.id', $dnsCustomerIds);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($data['status']) && ! empty($data['status']) && $data['status'] != 'full') {
|
||||
$status = (string) $data['status'];
|
||||
$statusValue = is_numeric($status)
|
||||
|
||||
Reference in New Issue
Block a user