From 8a951d644a8fd8ae4f50317af971ed99aa0a5b65 Mon Sep 17 00:00:00 2001 From: nocode Date: Wed, 17 Jul 2024 18:37:59 +0700 Subject: [PATCH] fix add customer --- Modules/Agents/Services/AgentService.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Modules/Agents/Services/AgentService.php b/Modules/Agents/Services/AgentService.php index 43d16fc..adc7eea 100644 --- a/Modules/Agents/Services/AgentService.php +++ b/Modules/Agents/Services/AgentService.php @@ -59,8 +59,8 @@ class AgentService // $isInAgentDistance = $this->modelCustomer->byPhone($dataInput['phone'])->whereDate('created_at', '>', $dateNotToo)->orderBy('created_at','asc')->get(); - - if (empty($isInAgentDistance)) { // ko co trong DS 15 ngay + // dd(empty($isInAgentDistance[0])); + if (empty($isInAgentDistance[0])) { // ko co trong DS 15 ngay $dataInsert['agent_id'] = $agentId; $this->modelCustomer->insert($dataInsert); $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentId)->delete(); @@ -68,13 +68,14 @@ class AgentService $agentIdBelonging = $isInAgentDistance[0]->agent_id; if($agentIdBelonging == $agentId){ - $dataInsert['agent_id'] = $agentId; - $this->modelCustomer->insert($dataInsert); + $idAgentInsert = $agentIdBelonging; }else{ - $dataInsert['agent_id'] = $agentIdBelonging; - $this->modelCustomer->insert($dataInsert); - $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentIdBelonging)->delete(); + $idAgentInsert = $agentId; + $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentId)->delete(); } + $dataInsert['agent_id'] = $agentIdBelonging; + $this->modelCustomer->insert($dataInsert); + } \DB::commit();