You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.9 KiB
109 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class AgentUser extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'se_agent_user';
|
|
protected $fillable = [
|
|
'id',
|
|
'user_id',
|
|
'agent_root_id',
|
|
'root_id',
|
|
'code',
|
|
'status',
|
|
'created_by',
|
|
'updated_by',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted',
|
|
'deleted_at'
|
|
];
|
|
/**
|
|
* Summary of scopeJoinAgent
|
|
* @param mixed $query
|
|
* @return mixed
|
|
*/
|
|
public function scopeJoinAgent($query)
|
|
{
|
|
return $query->join('se_agent', 'se_agent.id', '=', 'se_agent_user.agent_id')
|
|
->select('se_agent_user.*',
|
|
'se_agent.name as agent_name',
|
|
'se_agent.parent_path',
|
|
'se_agent.grant',
|
|
'se_agent.phone as agent_phone',
|
|
'se_agent.email as agent_email',
|
|
'se_agent.type');
|
|
}
|
|
/**
|
|
* Summary of scopeBetweenDates
|
|
* @param mixed $query
|
|
* @param mixed $startDate
|
|
* @param mixed $endDate
|
|
* @return mixed
|
|
*/
|
|
public function scopeBetweenDates($query, $startDate, $endDate)
|
|
{
|
|
return $query->whereBetween($this->table . '.created_at', [$startDate, $endDate]);
|
|
}
|
|
/**
|
|
* Summary of scopeByAgentRoot
|
|
* @param mixed $query
|
|
* @param mixed $agentRootId
|
|
* @return mixed
|
|
*/
|
|
public function scopeByAgentRoot($query, $agentRootId)
|
|
{
|
|
return $query->where($this->table . '.agent_root_id', $agentRootId);
|
|
}
|
|
/**
|
|
* Summary of scopeByAgentId
|
|
* @param mixed $query
|
|
* @param mixed $agentId
|
|
* @return mixed
|
|
*/
|
|
public function scopeByAgentId($query, $agentId){
|
|
return $query->where($this->table . '.agent_id', $agentId);
|
|
}
|
|
/**
|
|
* Summary of scopeSearchAgentName
|
|
* @param mixed $query
|
|
* @param string $keyword
|
|
* @return mixed
|
|
*/
|
|
public function scopeSearchAgentName($query, $keyword)
|
|
{
|
|
// return $query->where('name', 'LIKE', '%' . $keyword . '%');
|
|
|
|
|
|
return $query->where(function ($query) use ($keyword) {
|
|
$query->where('name', 'LIKE', '%' . $keyword . '%')
|
|
->orWhere('phone', 'LIKE', '%' . $keyword . '%')
|
|
->orWhere('email', 'LIKE', '%' . $keyword . '%');
|
|
});
|
|
}
|
|
/**
|
|
* Summary of scopeOnlyGrant
|
|
* @param mixed $query
|
|
* @param int $grant
|
|
* @return mixed
|
|
*/
|
|
public function scopeOnlyGrant($query, $grant)
|
|
{
|
|
return $query->where('se_agent.grant', $grant);
|
|
}
|
|
/**
|
|
* Summary of scopeByParentPath
|
|
* @param mixed $query
|
|
* @param int $agentId
|
|
* @return mixed
|
|
*/
|
|
public function scopeByParentPath($query, $agentId){
|
|
return $query->where('se_agent.parent_path', 'LIKE', '%-'. $agentId .'-%');
|
|
}
|
|
}
|
|
|