|
|
@ -48,7 +48,8 @@ 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 { |
|
|
|
$dataInsert = Arr::except($dataInput, ['agents_code']); // remove agents_code array |
|
|
|
$dataInsert = Arr::except($dataInput, ['agents_code']); // remove agents_code array |
|
|
@ -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{ |
|
|
|
|
|
|
|
// $idAgentInsert = $agentId; |
|
|
|
|
|
|
|
// $this->modelCustomer->byPhone($dataInput['phone'])->notAgent($agentIdBelonging)->delete(); |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
$idAgentInsert = $agentId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dataInsert['agent_id'] = $agentIdBelonging; |
|
|
|
if(!empty($customerAgentAllTime[0])){ |
|
|
|
$this->modelCustomer->insert($dataInsert); |
|
|
|
$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; |
|
|
|
|
|
|
|
$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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|