59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\admin\model\v1;
|
|
|
|
use app\common\model\AgentBaseModel;
|
|
|
|
/**
|
|
* 代理商数据模型
|
|
* @mixin \think\Model
|
|
*/
|
|
class AgentModel extends AgentBaseModel
|
|
{
|
|
// 关联业务类型
|
|
public function businessType()
|
|
{
|
|
return $this->belongsTo(AgentBusinessTypeModel::class, 'business_type', 'value');
|
|
}
|
|
|
|
// 关联企业规模类型
|
|
public function enterpriseSizeType()
|
|
{
|
|
return $this->belongsTo(AgentEnterpriseSizeTypeModel::class, 'enterprise_size', 'value');
|
|
}
|
|
|
|
// 按放言查询
|
|
public function scopeLanguage($query, $value)
|
|
{
|
|
$query->where('language_id', '=', $value);
|
|
}
|
|
|
|
// 按企业规模查询
|
|
public function scopeEnterpriseSize($query, $value)
|
|
{
|
|
if (is_null($value)) return;
|
|
$query->where('enterprise_size', '=', $value);
|
|
}
|
|
|
|
// 根据公司名称搜索
|
|
public function searchCorpNameAttr($query, $value)
|
|
{
|
|
if (is_null($value)) return;
|
|
$query->where('corp_name', 'like', "%{$value}%");
|
|
}
|
|
|
|
// 根据提交时间搜索
|
|
public function searchCreatedAtAttr($query, $value)
|
|
{
|
|
if (is_null($value)) return;
|
|
if (is_array($value)) {
|
|
if (count($value) > 1) {
|
|
$query->whereBetweenTime('created_at', $value[0], $value[1]);
|
|
} else {
|
|
$query->whereTime('created_at', '>=', $value[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|