main
nocode 1 year ago
parent 7036243fe2
commit c795450464
  1. 19
      Modules/Agents/Entities/Customer.php
  2. 10
      Modules/Agents/Services/AgentService.php

@ -11,7 +11,7 @@ class Customer extends Model
protected $table = 'se_customers'; protected $table = 'se_customers';
protected $fillable = ['id', 'name', 'phone', 'email', 'grade', 'msg', 'agent_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'deleted_at']; protected $fillable = ['id', 'name', 'phone', 'email', 'grade', 'msg', 'agent_id', 'created_at', 'created_by', 'updated_at', 'updated_by', 'deleted_at'];
protected $dates = ['deleted_at']; protected $dates = ['deleted_at'];
// protected static function newFactory() // protected static function newFactory()
// { // {
// return \Modules\Agents\Database\factories\CustomerFactory::new(); // return \Modules\Agents\Database\factories\CustomerFactory::new();
@ -23,7 +23,8 @@ class Customer extends Model
* @param mixed $phone * @param mixed $phone
* @return mixed * @return mixed
*/ */
public function scopeByPhone($query, $phone){ public function scopeByPhone($query, $phone)
{
return $query->where('phone', $phone); return $query->where('phone', $phone);
} }
/** /**
@ -32,7 +33,8 @@ class Customer extends Model
* @param mixed $agentId * @param mixed $agentId
* @return mixed * @return mixed
*/ */
public function scopeNotAgent($query, $agentId){ public function scopeNotAgent($query, $agentId)
{
return $query->where('agent_id', '<>', $agentId); return $query->where('agent_id', '<>', $agentId);
} }
/** /**
@ -41,7 +43,16 @@ class Customer extends Model
* @param mixed $agentId * @param mixed $agentId
* @return mixed * @return mixed
* **/ * **/
public function scopeInAgent($query, $agentId){ public function scopeInAgent($query, $agentId)
{
return $query->where('agent_id', '=', $agentId); return $query->where('agent_id', '=', $agentId);
} }
public function scopeSearch($query, $searchKey)
{
return $query->where(function ($query) use ($searchKey) {
$query->where('name', 'LIKE', '%' . $searchKey . '%')
->orWhere('phone', 'LIKE', '%' . $searchKey . '%')
->orWhere('email', 'LIKE', '%' . $searchKey . '%');
});
}
} }

@ -95,7 +95,7 @@ class AgentService
return ['status' => false, 'msg' => $this->getMessageReturn('no_data_agent')]; return ['status' => false, 'msg' => $this->getMessageReturn('no_data_agent')];
} }
$agentId = $myAgent->agent_id; $agentId = $myAgent->agent_id;
$queryAgent = $this->modelCustomer->where('agent_id', $agentId); $queryAgent = $this->modelCustomer->where('agent_id', '=',$agentId);
if (!empty($input['start_date']) && !empty($input['end_date'])) { if (!empty($input['start_date']) && !empty($input['end_date'])) {
$startDate = Carbon::createFromFormat('Y-m-d', $input['start_date']); $startDate = Carbon::createFromFormat('Y-m-d', $input['start_date']);
$endDate = Carbon::createFromFormat('Y-m-d', $input['end_date'])->addDay(); $endDate = Carbon::createFromFormat('Y-m-d', $input['end_date'])->addDay();
@ -103,10 +103,7 @@ class AgentService
$queryAgent->whereBetween('created_at', [$startDate->toDateString(), $endDate->toDateString()]); $queryAgent->whereBetween('created_at', [$startDate->toDateString(), $endDate->toDateString()]);
} }
if (!empty($input['keyword'])) { if (!empty($input['keyword'])) {
$queryAgent->where('name', 'LIKE', '%' . $input['keyword'] . '%') $queryAgent->search($input['keyword']);
->orWhere('phone', 'LIKE', '%' . $input['keyword'] . '%')
->orWhere('email', 'LIKE', '%' . $input['keyword'] . '%');
;
} }
// dd($queryAgent->toSql(),$queryAgent->getBindings()); // dd($queryAgent->toSql(),$queryAgent->getBindings());
$listCustomer = $queryAgent->orderBy('created_at', 'desc')->get(); $listCustomer = $queryAgent->orderBy('created_at', 'desc')->get();
@ -119,7 +116,8 @@ class AgentService
'email' => $listC->email ?? '', 'email' => $listC->email ?? '',
'grade' => $listC->grade ?? '', 'grade' => $listC->grade ?? '',
'date_receive' => $listC->created_at ?? '', 'date_receive' => $listC->created_at ?? '',
'message' => $listC->msg ?? '' 'message' => $listC->msg ?? '',
'agent_id' => $listC->agent_id ?? ''
]; ];
} }
} }

Loading…
Cancel
Save