|
|
@ -102,7 +102,10 @@ class AgentService |
|
|
|
$queryAgent->whereBetween('created_at', [$startDate->toDateString(), $endDate->toDateString()]); |
|
|
|
$queryAgent->whereBetween('created_at', [$startDate->toDateString(), $endDate->toDateString()]); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!empty($input['keyword'])) { |
|
|
|
if (!empty($input['keyword'])) { |
|
|
|
$queryAgent->where('name', 'LIKE', '%' . $input['keyword'] . '%'); |
|
|
|
$queryAgent->where('name', 'LIKE', '%' . $input['keyword'] . '%') |
|
|
|
|
|
|
|
->orWhere('phone', 'LIKE', '%' . $input['keyword'] . '%') |
|
|
|
|
|
|
|
->orWhere('email', 'LIKE', '%' . $input['keyword'] . '%'); |
|
|
|
|
|
|
|
; |
|
|
|
} |
|
|
|
} |
|
|
|
$listCustomer = $queryAgent->orderBy('name', 'asc')->get(); |
|
|
|
$listCustomer = $queryAgent->orderBy('name', 'asc')->get(); |
|
|
|
if (!empty($listCustomer)) { |
|
|
|
if (!empty($listCustomer)) { |
|
|
@ -150,10 +153,54 @@ class AgentService |
|
|
|
if (!empty($input['grant'])) { |
|
|
|
if (!empty($input['grant'])) { |
|
|
|
$myAgentDown->onlyGrant($input['grant']); |
|
|
|
$myAgentDown->onlyGrant($input['grant']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$listAgentGet = $myAgentDown->get(); |
|
|
|
|
|
|
|
if (!empty($listAgentGet)) { |
|
|
|
|
|
|
|
$listAgentById = []; |
|
|
|
|
|
|
|
foreach ($listAgentGet as $kAgent) { |
|
|
|
|
|
|
|
// get parent id by path |
|
|
|
|
|
|
|
$kAgent->grant_parent_id = $this->getParentAgent($kAgent->parent_path); |
|
|
|
|
|
|
|
$listAgentById[$kAgent->agent_id] = $kAgent; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($listAgentById)) { |
|
|
|
|
|
|
|
foreach ($listAgentById as $vByAgent) { |
|
|
|
|
|
|
|
|
|
|
|
dd($myAgentDown->get()); |
|
|
|
if (!empty($listAgentById[$vByAgent->grant_parent_id])) { |
|
|
|
|
|
|
|
$agentParent = $listAgentById[$vByAgent->grant_parent_id]; |
|
|
|
|
|
|
|
$upGrant = $agentParent->code ?? null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$data[] = [ |
|
|
|
|
|
|
|
'id' => $vByAgent->id ?? '', |
|
|
|
|
|
|
|
'name' => $vByAgent->agent_name ?? '', |
|
|
|
|
|
|
|
'agents_code' => $vByAgent->code ?? '', |
|
|
|
|
|
|
|
'created_date' => $vByAgent->created_at ?? '', |
|
|
|
|
|
|
|
'phone' => $vByAgent->agent_phone ?? '', |
|
|
|
|
|
|
|
'email' => $vByAgent->email ?? '', |
|
|
|
|
|
|
|
'grant' => $vByAgent->grant ?? '', |
|
|
|
|
|
|
|
'up_grant' => $upGrant ?? '' |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return ['status' => true, 'data' => $data, 'msg' => $this->getMessageReturn('success')]; |
|
|
|
return ['status' => true, 'data' => $data, 'msg' => $this->getMessageReturn('success')]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Summary of getChildAgent |
|
|
|
|
|
|
|
* @param mixed $input |
|
|
|
|
|
|
|
* @return array |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function getParentAgent($parentPath) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$parts = explode('-', $parentPath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove element null |
|
|
|
|
|
|
|
$parts = array_filter($parts, fn($part) => $part !== ''); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count($parts) == 1) { |
|
|
|
|
|
|
|
return min($parts); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return $parts[count($parts) - 1] ?? null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Summary of myAgentList |
|
|
|
* Summary of myAgentList |
|
|
|
* @param mixed $input |
|
|
|
* @param mixed $input |
|
|
|