new-admin-api/app/common/dao/marketing/AgentDao.php

89 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\dao\marketing;
use app\common\dao\BaseDao;
use app\common\model\marketing\Agent;
class AgentDao extends BaseDao{
protected function getModel(): string{
return Agent::class;
}
/**
* Common: 公共搜索查询
* Author: wu-hui
* Time: 2024/01/25 16:42
* @param array $params
* @return Agent
*/
public function searchList(array $params){
return (new Agent())
->where('is_del',0)
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
$query->where('id', (int)$params['id']);
})
->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){
$query->where('uid', (int)$params['uid']);
})
->when(isset($params['pid']) && $params['pid'] !== '',function($query) use ($params){
$query->where('pid', (int)$params['pid']);
})
->when(isset($params['contact_name']) && $params['contact_name'] !== '',function($query) use ($params){
$query->where('contact_name', 'like', "%{$params['contact_name']}%");
})
->when(isset($params['contact_phone']) && $params['contact_phone'] !== '',function($query) use ($params){
$query->where('contact_phone', $params['contact_phone']);
})
->when(isset($params['agent_type']) && $params['agent_type'] !== '',function($query) use ($params){
if(is_array($params['agent_type'])) $query->whereIn('agent_type', (array)$params['agent_type']);
else $query->where('agent_type', (int)$params['agent_type']);
})
->when(isset($params['is_invite_supplier']) && $params['is_invite_supplier'] !== '',function($query) use ($params){
// 仅获取拥有【供应商】邀请权限的代理人员 类型1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商
$query->whereIn('agent_type',[1,2,3,4,5]);
})
->with([
'user' => function($query){
$query->field('uid,nickname,avatar,phone');
},
'province' => function($query){
$query->field('id,name as province_name,code as province_code')
->bind(['province_name','province_code']);
},
'city' => function($query){
$query->field('id,name as city_name,code as city_code')
->bind(['city_name','city_code']);
},
'area' => function($query){
$query->field('id,name as area_name,code as area_code')
->bind(['area_name','area_code']);
},
'street' => function($query){
$query->field('id,name as street_name,code as street_code')
->bind(['street_name','street_code']);
},
'mer' => function($query){
$query->field('mer_id,mer_name,mer_avatar');
},
'merList' => function($query){
$query->field('agent_id,mer_name,mer_avatar');
},
'parent' => function($query){
$query->field('id,uid,agent_type,corporate_name')
->with([
'user' => function($query){
$query->field('uid,nickname,avatar')
->bind(['nickname','avatar']);
}
])
->append(['agent_type_text']);
},
])
->order('create_time DESC,id DESC')
->append(['mer_id_list','children_count','agent_type_text']);
}
}