|
|
|
@ -171,10 +171,12 @@ class AgentService |
|
|
|
|
$agentParent = $listAgentById[$vByAgent->grant_parent_id]; |
|
|
|
|
$upGrant = $agentParent->code ?? null; |
|
|
|
|
} |
|
|
|
|
if($agentId == $vByAgent->agent_id) continue; // skip agent root |
|
|
|
|
|
|
|
|
|
if(!empty($input['up_grant'])){ // if existing up_geant |
|
|
|
|
if($upGrant != $input['up_grant']) continue; // skip |
|
|
|
|
if ($agentId == $vByAgent->agent_id) |
|
|
|
|
continue; // skip agent root |
|
|
|
|
|
|
|
|
|
if (!empty($input['up_grant'])) { // if existing up_geant |
|
|
|
|
if ($upGrant != $input['up_grant']) |
|
|
|
|
continue; // skip |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$finalDataTemp[] = [ |
|
|
|
@ -219,10 +221,99 @@ class AgentService |
|
|
|
|
{ |
|
|
|
|
$data = []; |
|
|
|
|
//get data general |
|
|
|
|
$myAgent = $this->modelAgentUser->where('user_id', auth()->user()->id)->latest()->first(); |
|
|
|
|
|
|
|
|
|
if (empty($myAgent) || empty($myAgent->agent_id)) { |
|
|
|
|
return ['status' => false, 'msg' => $this->getMessageReturn('no_data_agent')]; |
|
|
|
|
} else { |
|
|
|
|
$myAgentInfo = $this->modelAgent->find($myAgent->agent_id); |
|
|
|
|
if (empty($myAgentInfo)) { |
|
|
|
|
return ['status' => false, 'msg' => $this->getMessageReturn('no_agent')]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$agentId = $myAgentInfo->id; |
|
|
|
|
$myAgentDown = $this->modelAgentUser->byParentPath($agentId)->joinAgent(); |
|
|
|
|
|
|
|
|
|
if (!empty($input['start_date']) && !empty($input['end_date'])) { |
|
|
|
|
$myAgentDown->betweenDates($input['start_date'], $input['end_date']); |
|
|
|
|
} |
|
|
|
|
if (!empty($input['keyword'])) { |
|
|
|
|
$myAgentDown->searchAgentName($input['keyword']); |
|
|
|
|
} |
|
|
|
|
if (!empty($input['grant'])) { |
|
|
|
|
$myAgentDown->onlyGrant($input['grant']); |
|
|
|
|
} |
|
|
|
|
$listAgentGet = $myAgentDown->get(); |
|
|
|
|
$finalData = []; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
foreach ($listAgentGet as $vAgent) { |
|
|
|
|
if (!empty($listAgentById[$vAgent->grant_parent_id])) { |
|
|
|
|
$agentParent = $listAgentById[$vAgent->grant_parent_id]; |
|
|
|
|
$upGrant = $agentParent->code ?? null; |
|
|
|
|
} |
|
|
|
|
if (!empty($input['up_grant'])) { // if existing up_geant |
|
|
|
|
if ($upGrant != $input['up_grant']) |
|
|
|
|
continue; // skip |
|
|
|
|
} |
|
|
|
|
// lay danh sach 2 con cua parent |
|
|
|
|
$processPath = $this->processParentPath($agentId, $vAgent->parent_path); |
|
|
|
|
if (!empty($processPath) && in_array($vAgent->agent_id, $processPath)) { |
|
|
|
|
// $finalData[] = $vAgent; |
|
|
|
|
$finalData[] = [ |
|
|
|
|
'id' => $vAgent->id ?? '', |
|
|
|
|
'name' => $vAgent->agent_name ?? '', |
|
|
|
|
'agents_code' => $vAgent->code ?? '', |
|
|
|
|
'created_date' => $vAgent->created_at ?? '', |
|
|
|
|
'phone' => $vAgent->agent_phone ?? '', |
|
|
|
|
'email' => $vAgent->agent_email ?? '', |
|
|
|
|
'grant' => $vAgent->grant ?? '', |
|
|
|
|
'up_grant' => $upGrant ?? '' |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$data = $finalData; |
|
|
|
|
return ['status' => true, 'data' => $data, 'msg' => $this->getMessageReturn('success')]; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Summary of processPath |
|
|
|
|
* @param mixed $parentPath |
|
|
|
|
* @param mixed $agentId |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function processParentPath($agentId, $parentPath) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
// find index agentId |
|
|
|
|
$position = strpos($parentPath, '-' . $agentId . '-'); |
|
|
|
|
|
|
|
|
|
if ($position !== false) { |
|
|
|
|
// cat chuoi tu vi tri ngay sau agentId |
|
|
|
|
$substring = substr($parentPath, $position + strlen('-' . $agentId . '-')); |
|
|
|
|
if (empty($substring)) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
// tach chuoi thanh cac mang phan tu |
|
|
|
|
$numbers = explode('-', trim($substring, '-')); |
|
|
|
|
|
|
|
|
|
// lay 2 mang dau tien sau agentId |
|
|
|
|
$result = array_slice($numbers, 0, 2); |
|
|
|
|
|
|
|
|
|
// ghep lai thanh chuoi |
|
|
|
|
// $final_path = '-' . implode('-', $result) . '-'; |
|
|
|
|
$final_path = $result; |
|
|
|
|
} else { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $final_path; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Summary of formatCreateCustomer |
|
|
|
|
* @param array $data |
|
|
|
|