добавил возможность поиска клиента по номеру в произвольном формате
This commit is contained in:
parent
e1f3b522bb
commit
ca37aa4776
@ -21,7 +21,7 @@ class ClientsTable extends Component
|
|||||||
{
|
{
|
||||||
public $status;
|
public $status;
|
||||||
public $count;
|
public $count;
|
||||||
public $mode;//short || full
|
public $mode; //short || full
|
||||||
public $filter = [];
|
public $filter = [];
|
||||||
public $clientsCount;
|
public $clientsCount;
|
||||||
public $currentPage;
|
public $currentPage;
|
||||||
@ -34,7 +34,8 @@ public function mount($status = null, $count = 10, $mode = 'full')
|
|||||||
$this->filter = [];
|
$this->filter = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function goToPage($page) {
|
public function goToPage($page)
|
||||||
|
{
|
||||||
$this->currentPage = $page;
|
$this->currentPage = $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ function getClients()
|
|||||||
})
|
})
|
||||||
->orderBy('deal_clients.id', 'desc')
|
->orderBy('deal_clients.id', 'desc')
|
||||||
->with('deals');
|
->with('deals');
|
||||||
$clients->select('users.id','users.name','users.phone','users.email');
|
$clients->select('users.id', 'users.name', 'users.phone', 'users.email');
|
||||||
$clients->orderBy('name');
|
$clients->orderBy('name');
|
||||||
$clients->join('deals', 'deal_clients.deal_id', '=', 'deals.id');
|
$clients->join('deals', 'deal_clients.deal_id', '=', 'deals.id');
|
||||||
if (array_key_exists('status', $this->filter)) {
|
if (array_key_exists('status', $this->filter)) {
|
||||||
@ -119,7 +120,7 @@ function getClients()
|
|||||||
$searchString = mb_strtolower(trim($this->filter['search']));
|
$searchString = mb_strtolower(trim($this->filter['search']));
|
||||||
// $clients->whereFullText(['name', 'phone', 'email', 'normalized_name', 'normalized_phone'], $searchString);
|
// $clients->whereFullText(['name', 'phone', 'email', 'normalized_name', 'normalized_phone'], $searchString);
|
||||||
$clients->orWhere('normalized_name', 'like', "%{$searchString}%")
|
$clients->orWhere('normalized_name', 'like', "%{$searchString}%")
|
||||||
->orWhere('normalized_phone', 'like', "%{$searchString}%")
|
->orWhere('normalized_phone', 'like', "%{$this->normilizePhone($searchString)}%")
|
||||||
->orWhere('email', 'like', "%{$searchString}%");
|
->orWhere('email', 'like', "%{$searchString}%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,15 +130,26 @@ function getClients()
|
|||||||
});
|
});
|
||||||
} elseif (array_key_exists('status', $this->filter) && $this->status == DealStatus::NOT_UNIQUE) {
|
} elseif (array_key_exists('status', $this->filter) && $this->status == DealStatus::NOT_UNIQUE) {
|
||||||
$clients = $clients->whereHas('deals', function ($query) {
|
$clients = $clients->whereHas('deals', function ($query) {
|
||||||
$query->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW , DealStatus::NOT_UNIQUE]);
|
$query->whereIn('status', [DealStatus::MODERATION, DealStatus::NEW, DealStatus::NOT_UNIQUE]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return $clients;
|
return $clients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function normilizePhone($value)
|
||||||
|
{
|
||||||
|
$digits = preg_replace('/\D+/', '', $value);
|
||||||
|
|
||||||
|
if (strlen($digits) >= 2 && ($digits[0] === '7' || $digits[0] === '8')) {
|
||||||
|
return substr($digits, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $digits;
|
||||||
|
}
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$clients = $this->getClients();
|
$clients = $this->getClients();
|
||||||
$clients->groupBy('users.id','users.name','users.phone','users.email');
|
$clients->groupBy('users.id', 'users.name', 'users.phone', 'users.email');
|
||||||
if ($this->clientsCount != $clients->count()) {
|
if ($this->clientsCount != $clients->count()) {
|
||||||
$this->clientsCount = $clients->count();
|
$this->clientsCount = $clients->count();
|
||||||
$this->currentPage = 1;
|
$this->currentPage = 1;
|
||||||
@ -151,5 +163,4 @@ public function render()
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user