add customer

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

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

Loading…
Cancel
Save