diff --git a/app/common/repositories/community/CommunityRepository.php b/app/common/repositories/community/CommunityRepository.php index 25ef518b..cd9f6467 100644 --- a/app/common/repositories/community/CommunityRepository.php +++ b/app/common/repositories/community/CommunityRepository.php @@ -109,9 +109,17 @@ class CommunityRepository extends BaseRepository $config = systemConfig("community_app_switch"); // if (!isset($where['is_type']) && $config) $where['is_type'] = is_array($config) ? implode(',', $config) : $config; if (empty($where['is_type'])) $where['is_type'] = '1,2'; + $uIdArray = []; + if ($where['is_type'] == 3) { + $categoryId = Db::name('merchant')->where('uid', $userInfo->uid)->where('status', 1)->value('category_id'); + $uIdArray = Db::name('merchant')->where('category_id', $categoryId)->where('status', 1)->where('uid', '>', 0)->column('uid'); + } $where['is_del'] = 0; - $query = $this->dao->search($where)->when(in_array(self::COMMUNITY_TYPE_RESALE, explode(',', $where['is_type'])), function ($query) { - $query->where('is_sale', 0); + $query = $this->dao->search($where)->when(in_array(self::COMMUNITY_TYPE_RESALE, explode(',', $where['is_type'])), function ($query) use ($where, $uIdArray) { + $query->where('Community.is_sale', 0); + if (is_array($uIdArray) && count($uIdArray) > 0) { + $query->whereIn('Community.uid', $uIdArray); + } })->order('start DESC,Community.create_time DESC,community_id DESC'); $query->with([ 'author' => function($query) use($userInfo){ @@ -138,7 +146,6 @@ class CommunityRepository extends BaseRepository $list = $query->page($page, $limit)->setOption('field',[]) ->field('community_id,title,image,resale_type,topic_id,Community.count_start,count_reply,start,Community.create_time,Community.uid,Community.status,is_show,content,video_link,is_type,refusal') ->select()->append(['time']); - if ($list) $list = $list->toArray(); foreach ($list as $k => $item) { if ($item['is_type'] == self::COMMUNITY_TYPE_RESALE) {