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();