diff --git a/app/common/model/community/Community.php b/app/common/model/community/Community.php index 71af1fb3..87185850 100644 --- a/app/common/model/community/Community.php +++ b/app/common/model/community/Community.php @@ -142,5 +142,13 @@ class Community extends BaseModel ->column('left_id'); $query->where('community_id','in', $id); } + public function searchNoCategoryIdAttr($query, $value) + { + $query->where('category_id', '<>',$value); + } + public function searchIdAndInAttr($query, $value) + { + $query->where('community_id', 'in',$value); + } } diff --git a/app/common/repositories/community/CommunityRepository.php b/app/common/repositories/community/CommunityRepository.php index 8a1952fd..c34e8089 100644 --- a/app/common/repositories/community/CommunityRepository.php +++ b/app/common/repositories/community/CommunityRepository.php @@ -96,7 +96,58 @@ class CommunityRepository extends BaseRepository return compact('count','list'); } + public function getApiListTwo(array $where, int $page, int $limit, $userInfo) + { + if (!$userInfo){ + $count=0; + $list=[]; + return compact('count','list'); + } + $village_id=Db::name('nk_user')->where('user_id',$userInfo->uid)->value('village_id'); + if (!$village_id){ + $count=0; + $list=[]; + return compact('count','list'); + } + $arr=Db::name('community_address')->where('village_id',$village_id)->page($page, $limit)->select(); + if (count($arr)==0){ + $count=0; + $list=[]; + return compact('count','list'); + } + $arr2=[]; + foreach ($arr as $k=>$v){ + $arr2[]=$v['community_id']; + } + $arrWhere=['id_and_in'=>$arr2]; + $query = $this->dao->getSearch($arrWhere)->order('start DESC,create_time DESC,community_id DESC'); + $query->with([ + 'author' => function($query) use($userInfo){ + $query->field('uid,real_name,status,avatar,nickname,count_start'); + }, + 'is_start' => function($query) use ($userInfo) { + $query->where('left_id',$userInfo->uid ?? null); + }, + 'topic' => function($query) { + $query->where('status', 1)->where('is_del',0); + $query->field('topic_id,topic_name,status,category_id,pic,is_del'); + }, + 'relevance' => [ + 'spu' => function($query) { + $query->field('spu_id,store_name,image,price,product_type,activity_id,product_id'); + } + ], + 'is_fans' => function($query) use($userInfo){ + $query->where('left_id',$userInfo->uid?? 0); + } + ]); + $count = Db::name('community_address')->where('village_id',$village_id)->count(); + $list = $query->setOption('field',[]) + ->field('community_id,title,image,topic_id,count_start,count_reply,start,create_time,uid,status,is_show,content') + ->select()->append(['time']); + return compact('count','list'); + } /** * TODO 后台详情 * @param int $id diff --git a/app/controller/api/community/Community.php b/app/controller/api/community/Community.php index 0c3389ab..27b2ce14 100644 --- a/app/controller/api/community/Community.php +++ b/app/controller/api/community/Community.php @@ -54,7 +54,17 @@ class Community extends BaseController public function lst() { $where = $this->request->params(['keyword','topic_id','is_hot','category_id','spu_id']); - if (!$where['category_id']) unset($where['category_id']); + $a=true; + if (!$where['category_id']){ + unset($where['category_id']); + //查询非社区数据 + $where['no_category_id']=69; + $a=false; + } + if ($a &&$where['category_id']==69){ + [$page, $limit] = $this->getPage(); + return app('json')->success($this->repository->getApiListTwo($where, $page, $limit, $this->user)); + } $where = array_merge($where,$this->repository::IS_SHOW_WHERE); [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->getApiList($where, $page, $limit, $this->user)); @@ -178,9 +188,11 @@ class Community extends BaseController $data['status'] = 0; $data['is_show'] = 0; } - $res = $this->repository->create($data); - + if ($data['category_id']==69){ + $data['community_id']=$res; + event('community_address',$data); + } return app('json')->success(['community_id' => $res]); } @@ -231,7 +243,7 @@ class Community extends BaseController public function checkParams() { - $data = $this->request->params(['image','topic_id','content','spu_id','order_id']); + $data = $this->request->params(['image','topic_id','content','spu_id','order_id','category_id']); $data['content'] = filter_emoji($data['content']); app()->make(CommunityValidate::class)->check($data); diff --git a/app/event.php b/app/event.php index ffa4f55b..4717e53b 100644 --- a/app/event.php +++ b/app/event.php @@ -58,6 +58,7 @@ return [ 'pay_success_order' => [\crmeb\listens\pay\OrderPaySuccessListen::class], 'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class], 'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class], + 'community_address'=>[\app\listener\CommunityAddress::class] ], 'subscribe' => [],