NEW LIST AGENT FOR USER

main
nocode 1 year ago
parent e6f210314a
commit 7036243fe2
  1. 28
      Modules/Agents/Entities/Customer.php
  2. 14
      Modules/Agents/Services/AgentService.php

@ -16,4 +16,32 @@ class Customer extends Model
// {
// return \Modules\Agents\Database\factories\CustomerFactory::new();
// }
/**
* Summary of scopeByPhone
* @param mixed $query
* @param mixed $phone
* @return mixed
*/
public function scopeByPhone($query, $phone){
return $query->where('phone', $phone);
}
/**
* Summary of scopeNotAgent
* @param mixed $query
* @param mixed $agentId
* @return mixed
*/
public function scopeNotAgent($query, $agentId){
return $query->where('agent_id', '<>', $agentId);
}
/**
* Summary of scopeInAgent
* @param mixed $query
* @param mixed $agentId
* @return mixed
* **/
public function scopeInAgent($query, $agentId){
return $query->where('agent_id', '=', $agentId);
}
}

@ -52,17 +52,17 @@ class AgentService
\DB::beginTransaction();
try {
$dataInsert = Arr::except($dataInput, ['agents_code']); // remove agents_code array
$dataInsert['created_at'] = now();
$dateNotToo = Carbon::now()->subDays(self::DISTANCE_DAY_DEFAULT);
$customerAgent = $this->modelCustomer->where('agent_id', $agentId)->where('phone', $dataInput['phone'])->latest()->first();
// tìm các dữ liệu từ ngày hiện tại trừ đi không được quá 15 ngày
$customerAgentAll = $this->modelCustomer->where('phone', $dataInput['phone'])->where('agent_id', '<>', $agentId)->where('created_at', '>=', $dateNotToo)->latest()->first();
$dataInsert['created_at'] = now();
// $customerAgent = $this->modelCustomer->where('agent_id', $agentId)->where('phone', $dataInput['phone'])->latest()->first();
if (!empty($customerAgentAll)) {
// tìm các dữ liệu của đại lý từ mã gửi lên từ ngày hiện tại trừ đi co trong 15 ngày
$customerInAgent = $this->modelCustomer->byPhone($dataInput['phone'])->inAgent($agentId)->whereDate('created_at', '>', $dateNotToo)->orderBy('created_at','asc')->first();
if (!empty($customerInAgent)) {
// chưa quá 15 ngày thì lấy cái agent_id cũ, đang trực thuộc
$dataInsert['agent_id'] = $customerAgentAll->agent_id;
$dataInsert['agent_id'] = $customerInAgent->agent_id;
$result = $this->modelCustomer->insert($dataInsert);
} else {
// quá 15 ngày thì lấy agent_id check ra từ mã đại lý

Loading…
Cancel
Save