|
@@ -0,0 +1,84 @@
|
|
|
|
+<?php
|
|
|
|
+/**
|
|
|
|
+ * Created by PhpStorm.
|
|
|
|
+ * User: Administrator
|
|
|
|
+ * Date: 2019-06-15
|
|
|
|
+ * Time: 15:01
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+namespace App\Repositories;
|
|
|
|
+
|
|
|
|
+use App\Models\MemberFollowTopic;
|
|
|
|
+use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
|
+
|
|
|
|
+class MemberFollowTopicRepository {
|
|
|
|
+ public function __construct(MemberFollowTopic $memberFollowTopic,CategoryRepository $categoryRepository) {
|
|
|
|
+ $this->memberFollowTopic = $memberFollowTopic;
|
|
|
|
+ $this->categoryRepository = $categoryRepository;
|
|
|
|
+ }
|
|
|
|
+ //关注话题
|
|
|
|
+ public function setMemberFollowTopic($topic_group_ids){
|
|
|
|
+
|
|
|
|
+ $data = $this->categoryRepository->getTopics($topic_group_ids);
|
|
|
|
+ //获取uid
|
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
|
+ if($data){
|
|
|
|
+ $category_topic_data = [];
|
|
|
|
+ foreach($data as $value){
|
|
|
|
+ $category_topic_data[] = [
|
|
|
|
+ 'uid' => $token['user']->uid,
|
|
|
|
+ 'topic_id' => $value['id'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $res = $this->memberFollowTopic->insert($category_topic_data);
|
|
|
|
+ if($res){
|
|
|
|
+ return jsonSuccess();
|
|
|
|
+ }else{
|
|
|
|
+ return jsonError('关注失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //关注单个话题
|
|
|
|
+ public function follow($topic_id){
|
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
|
+ $info = $this->memberFollowTopic->where(['topic_id'=>$topic_id,'uid'=>$token['user']->uid])->first();
|
|
|
|
+ if($info){
|
|
|
|
+ return jsonError('您已关注该话题');
|
|
|
|
+ }
|
|
|
|
+ $data = ['uid'=>$token['user']->uid,'topic_id'=>$topic_id];
|
|
|
|
+ $res = $this->memberFollowTopic->create($data);
|
|
|
|
+ if($res){
|
|
|
|
+ return jsonSuccess();
|
|
|
|
+ }else{
|
|
|
|
+ return jsonError('关注失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //取消关注话题
|
|
|
|
+ public function cancel($topic_id){
|
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
|
+ $info = $this->memberFollowTopic->where(['topic_id'=>$topic_id,'uid'=>$token['user']->uid])->first();
|
|
|
|
+ if(!$info){
|
|
|
|
+ return jsonError('您没有关注该话题');
|
|
|
|
+ }
|
|
|
|
+ $res = $this->memberFollowTopic->where('id',$info->id)->delete();
|
|
|
|
+ if($res){
|
|
|
|
+ return jsonSuccess();
|
|
|
|
+ }else{
|
|
|
|
+ return jsonError('取关失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public function list($request){
|
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
+ $where[] = ['uid',$token['user']->uid];
|
|
|
|
+ if(isset($request['name'])){
|
|
|
|
+ $where[] = ['topic.name', 'like', "%{$request['name']}%"];
|
|
|
|
+ }
|
|
|
|
+ return $this->memberFollowTopic
|
|
|
|
+ ->leftJoin('topic', 'member_follow_topic.topic_id', '=', 'topic.id')
|
|
|
|
+ ->where($where)
|
|
|
|
+ ->select('member_follow_topic.id','uid','topic_id','topic.name as topic_name','topic.is_suggest')
|
|
|
|
+ ->paginate($perPage);
|
|
|
|
+ }
|
|
|
|
+}
|