добавил возможность поиска клиента по номеру в произвольном формате
This commit is contained in:
parent
e1f3b522bb
commit
ca37aa4776
@ -21,7 +21,7 @@ class ClientsTable extends Component
|
||||
{
|
||||
public $status;
|
||||
public $count;
|
||||
public $mode;//short || full
|
||||
public $mode; //short || full
|
||||
public $filter = [];
|
||||
public $clientsCount;
|
||||
public $currentPage;
|
||||
@ -34,7 +34,8 @@ public function mount($status = null, $count = 10, $mode = 'full')
|
||||
$this->filter = [];
|
||||
}
|
||||
|
||||
public function goToPage($page) {
|
||||
public function goToPage($page)
|
||||
{
|
||||
$this->currentPage = $page;
|
||||
}
|
||||
|
||||
@ -100,7 +101,7 @@ function getClients()
|
||||
})
|
||||
->orderBy('deal_clients.id', 'desc')
|
||||
->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->join('deals', 'deal_clients.deal_id', '=', 'deals.id');
|
||||
if (array_key_exists('status', $this->filter)) {
|
||||
@ -117,9 +118,9 @@ function getClients()
|
||||
|
||||
if (array_key_exists('search', $this->filter) && $searchString = 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}%")
|
||||
->orWhere('normalized_phone', 'like', "%{$searchString}%")
|
||||
->orWhere('normalized_phone', 'like', "%{$this->normilizePhone($searchString)}%")
|
||||
->orWhere('email', 'like', "%{$searchString}%");
|
||||
}
|
||||
|
||||
@ -129,15 +130,26 @@ function getClients()
|
||||
});
|
||||
} elseif (array_key_exists('status', $this->filter) && $this->status == DealStatus::NOT_UNIQUE) {
|
||||
$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;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$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()) {
|
||||
$this->clientsCount = $clients->count();
|
||||
$this->currentPage = 1;
|
||||
@ -151,5 +163,4 @@ public function render()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user