add customer

main
nocode 1 year ago
parent 8137b89e69
commit 5c0960d33b
  1. 23
      Modules/Agents/Services/AgentService.php

@ -48,6 +48,7 @@ class AgentService
return array('status' => false, 'msg' => $this->getMessageReturn('no_data_agent'));
}
$agentId = $checkAgentUser->agent_id;
$today = Carbon::today();
\DB::beginTransaction();
try {
@ -67,18 +68,22 @@ class AgentService
$this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentId)->delete();
} else { // co DS 15 ngay
$agentIdBelonging = $isInAgentDistance[0]->agent_id;
$customerAgentAllTime = $this->modelCustomer->byPhone($dataInput['phone'])->orderBy('created_at','asc')->get();
// if($agentIdBelonging == $agentId){
// $idAgentInsert = $agentIdBelonging;
// }else{
// $idAgentInsert = $agentId;
// $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentIdBelonging)->delete();
// }
$idAgentInsert = $agentId;
$dataInsert['agent_id'] = $agentIdBelonging;
if(!empty($customerAgentAllTime[0])){
$differenceInDays = $today->diffInDays($customerAgentAllTime[0]->created_at);
if($differenceInDays > self::DISTANCE_DAY_DEFAULT){
$dataInsert['agent_id'] = $agentId;
$this->modelCustomer->insert($dataInsert);
}else{
$dataInsert['agent_id'] = $customerAgentAllTime[0]->agent_id;
$this->modelCustomer->insert($dataInsert);
}
}else{
$dataInsert['agent_id'] = $agentId;
$this->modelCustomer->insert($dataInsert);
$this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentIdBelonging)->delete();
}
}

Loading…
Cancel
Save