作者 何书鹏
1 个管道 的构建 通过 耗费 0 秒

代码优化

... ... @@ -185,16 +185,11 @@ class Index extends Api
// 哪些人及其下级可查看
if($this->auth->id){
$parentsIds = Tree::instance()->init(collection(User::select())->toArray())->getParentsIds($this->auth->id, true);
if($parentsIds){
foreach ($parentsIds as $pid){
$findinset[] = "find_in_set({$pid},user_ids)";
}
$where .= $where ? ' and ' : '';
$where .= "(".implode(' or ',$findinset)." or user_ids = '')";
}else{
// 未设置哪些人及其下级可查看,默认所有人可以查看
$where .= " or user_ids = ''";
foreach ($parentsIds as $pid){
$findinset[] = "find_in_set({$pid},user_ids)";
}
$where .= $where ? ' and ' : '';
$where .= "(".implode(' or ',$findinset)." or user_ids = '')";
}
// 附近
$distance = '1';
... ... @@ -302,16 +297,11 @@ class Index extends Api
// 哪些人及其下级可查看
if($this->auth->id){
$parentsIds = Tree::instance()->init(collection(User::select())->toArray())->getParentsIds($this->auth->id, true);
if($parentsIds){
foreach ($parentsIds as $pid){
$findinset[] = "find_in_set({$pid},j.user_ids)";
}
$where .= $where ? ' and ' : '';
$where .= "(".implode(' or ',$findinset)." or user_ids = '')";
}else{
// 未设置哪些人及其下级可查看,默认所有人可以查看
$where .= " or user_ids = ''";
foreach ($parentsIds as $pid){
$findinset[] = "find_in_set({$pid},user_ids)";
}
$where .= $where ? ' and ' : '';
$where .= "(".implode(' or ',$findinset)." or user_ids = '')";
}
$data = Job::alias('j')
... ...