fix add customer

main
nocode 1 year ago
parent 1e6e24b143
commit 8a951d644a
  1. 15
      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(); $isInAgentDistance = $this->modelCustomer->byPhone($dataInput['phone'])->whereDate('created_at', '>', $dateNotToo)->orderBy('created_at','asc')->get();
// dd(empty($isInAgentDistance[0]));
if (empty($isInAgentDistance)) { // ko co trong DS 15 ngay if (empty($isInAgentDistance[0])) { // ko co trong DS 15 ngay
$dataInsert['agent_id'] = $agentId; $dataInsert['agent_id'] = $agentId;
$this->modelCustomer->insert($dataInsert); $this->modelCustomer->insert($dataInsert);
$this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentId)->delete(); $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentId)->delete();
@ -68,13 +68,14 @@ class AgentService
$agentIdBelonging = $isInAgentDistance[0]->agent_id; $agentIdBelonging = $isInAgentDistance[0]->agent_id;
if($agentIdBelonging == $agentId){ if($agentIdBelonging == $agentId){
$dataInsert['agent_id'] = $agentId; $idAgentInsert = $agentIdBelonging;
$this->modelCustomer->insert($dataInsert);
}else{ }else{
$dataInsert['agent_id'] = $agentIdBelonging; $idAgentInsert = $agentId;
$this->modelCustomer->insert($dataInsert); $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentId)->delete();
$this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentIdBelonging)->delete();
} }
$dataInsert['agent_id'] = $agentIdBelonging;
$this->modelCustomer->insert($dataInsert);
} }
\DB::commit(); \DB::commit();

Loading…
Cancel
Save