|
|
|
@ -85,7 +85,8 @@ class AgentService |
|
|
|
|
* @param array $input |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function myCustomer($input){ |
|
|
|
|
public function myCustomer($input) |
|
|
|
|
{ |
|
|
|
|
$listCustomer = []; |
|
|
|
|
$finalAgentData = []; |
|
|
|
|
$myAgent = $this->modelAgentUser->where('user_id', auth()->user()->id)->latest()->first(); |
|
|
|
@ -95,7 +96,10 @@ class AgentService |
|
|
|
|
$agentId = $myAgent->agent_id; |
|
|
|
|
$queryAgent = $this->modelCustomer->where('agent_id', $agentId); |
|
|
|
|
if (!empty($input['start_date']) && !empty($input['end_date'])) { |
|
|
|
|
$queryAgent->whereBetween('created_at', [$input['start_date'], $input['end_date']]); |
|
|
|
|
$startDate = Carbon::createFromFormat('Y-m-d', $input['start_date']); |
|
|
|
|
$endDate = Carbon::createFromFormat('Y-m-d', $input['end_date'])->addDay(); |
|
|
|
|
|
|
|
|
|
$queryAgent->whereBetween('created_at', [$startDate->toDateString(), $endDate->toDateString()]); |
|
|
|
|
} |
|
|
|
|
if (!empty($input['keyword'])) { |
|
|
|
|
$queryAgent->where('name', 'LIKE', '%' . $input['keyword'] . '%'); |
|
|
|
@ -116,6 +120,53 @@ class AgentService |
|
|
|
|
} |
|
|
|
|
return ['status' => true, 'data' => $finalAgentData, 'msg' => $this->getMessageReturn('success')]; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Summary of listAgentOfGeneral |
|
|
|
|
* @param mixed $input |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function listAgentOfGeneral($input) |
|
|
|
|
{ |
|
|
|
|
$data = []; |
|
|
|
|
$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->byAgentRoot($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']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dd($myAgentDown->get()); |
|
|
|
|
return ['status' => true, 'data' => $data, 'msg' => $this->getMessageReturn('success')]; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Summary of myAgentList |
|
|
|
|
* @param mixed $input |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function myAgentList($input) |
|
|
|
|
{ |
|
|
|
|
$data = []; |
|
|
|
|
//get data general |
|
|
|
|
|
|
|
|
|
return ['status' => true, 'data' => $data, 'msg' => $this->getMessageReturn('success')]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Summary of formatCreateCustomer |
|
|
|
|
* @param array $data |
|
|
|
@ -158,7 +209,8 @@ class AgentService |
|
|
|
|
'no_data_agent' => 'Đại lý không tồn tại.', |
|
|
|
|
'success_insert_customer' => 'Thêm khách hàng thành công.', |
|
|
|
|
'failed_insert' => 'Thêm khách hàng thành công.', |
|
|
|
|
'success' => 'Load data thành công.' |
|
|
|
|
'success' => 'Load data thành công.', |
|
|
|
|
'no_agent' => 'Không tìm thấy đại lý.', |
|
|
|
|
]; |
|
|
|
|
return $msgArr[$errorKey] ?? "Không có dữ liệu."; |
|
|
|
|
} |
|
|
|
|