Browse Source

消息,关系,关注等

lizhen_gitee 1 year ago
parent
commit
eb7335fee0

+ 14 - 2
application/api/controller/Message.php

@@ -5,14 +5,14 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use think\Db;
 /**
- * 系统消息
+ * 消息
  */
 class Message extends Api
 {
     protected $noNeedLogin = [];
     protected $noNeedRight = ['*'];
 
-    //我的消息列表
+    //我的个人消息列表
     public function mylist(){
         $list = Db::name('message')->where('user_id',$this->auth->id)->autopage()->order('id desc')->select();
 
@@ -25,4 +25,16 @@ class Message extends Api
         $this->success('success',$list);
     }
 
+    /*
+     * 获取系统消息列表
+     */
+    public function getMessageSys() {
+
+        $list = Db::name('message_sys')->autopage()->order('id desc')->select();
+
+        $this->success("获取成功!",$list);
+    }
+
+
+
 }

+ 35 - 1
application/api/controller/Relation.php

@@ -49,7 +49,7 @@ class Relation extends Api
         $this->success('success',$list);
     }
 
-    //新增举报
+    //新增
     public function addone(){
         $to_uid = input('to_uid',0);
         if($to_uid == $this->auth->id){
@@ -91,6 +91,8 @@ class Relation extends Api
             //可以申请
         }
 
+        //扣钱或道具
+
         //新增
         $data = [
             'uid' => $this->auth->id,
@@ -102,6 +104,20 @@ class Relation extends Api
         ];
 
         $id = Db::name('user_relation')->insertGetId($data);
+
+        //给对方一条消息
+        $message = [
+            'user_id' => $to_uid,
+            'title'   => '关系审核',
+            'content' => '有人想和你成为'.$relation['name'],
+            'createtime' => time(),
+            'status' => 0,
+            'infotype' => 'newrelation',//建立关系
+            'infotype_id' => 0,
+        ];
+        Db::name('message')->insertGetId($message);
+
+
         $this->success('申请成功,等待对方同意',$id);
     }
 
@@ -139,6 +155,7 @@ class Relation extends Api
         $id = input('id',0);
         $status = input('status',1);
 
+        //查询
         $info = Db::name('user_relation')->alias('ur')
             ->where('ur.id',$id)
             ->where('ur.to_uid',$this->auth->id)
@@ -148,6 +165,7 @@ class Relation extends Api
             $this->error('请刷新重试');
         }
 
+        //更新
         $data = [
             'status' => $status,
             'updatetime' => time(),
@@ -157,10 +175,26 @@ class Relation extends Api
 
         if($status == 1){
             $remark = '您已同意建立关系';
+            $remark2 = '已同意';
         }else{
             $remark = '已拒绝';
+            $remark2 = '已拒绝';
         }
 
+        //给发起方一条消息
+        $relation_name = Db::name('relation')->where('id',$info['relation_id'])->value('name');
+        $message = [
+            'user_id' => $info['uid'],
+            'title'   => '关系申请结果',
+            'content' => '和'.$this->auth->nickname.'成为'.$relation_name.':'.$remark2,
+            'createtime' => time(),
+            'status' => 0,
+            'infotype' => '',//建立关系
+            'infotype_id' => 0,
+        ];
+        Db::name('message')->insertGetId($message);
+
+        //
         $this->success($remark);
     }
 }

+ 1 - 1
application/api/controller/Report.php

@@ -5,7 +5,7 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use think\Db;
 /**
- * 举报
+ * 意见反馈
  */
 class Report extends Api
 {

+ 100 - 4
application/api/controller/Userfollow.php

@@ -17,12 +17,23 @@ class Userfollow extends Api
         $list = Db::name('user_follow')
             ->alias('follow')
             ->join('user','follow.follow_uid = user.id','LEFT')
-            ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
+            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
+            ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
             ->where('follow.uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
 
         $list = list_domain_image($list,['avatar']);
         $list = list_birthday_age($list);
 
+        if(!empty($list)){
+            foreach($list as $key => &$val){
+                //用户vip
+                $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
+                unset($val['vip_endtime']);
+                //是否关注
+                $val['is_follow'] = 1;
+            }
+        }
+
         $this->success('success',$list);
     }
 
@@ -31,15 +42,64 @@ class Userfollow extends Api
         $list = Db::name('user_follow')
             ->alias('follow')
             ->join('user','follow.uid = user.id','LEFT')
-            ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
+            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
+            ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
             ->where('follow.follow_uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
 
         $list = list_domain_image($list,['avatar']);
         $list = list_birthday_age($list);
 
+        //我的关注uids
+        $my_follow_uids = $this->my_follow_uids();
+
+        if(!empty($list)){
+            foreach($list as $key => &$val){
+                //用户vip
+                $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
+                unset($val['vip_endtime']);
+                //是否关注
+                $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0;
+            }
+        }
+
         $this->success('success',$list);
     }
 
+    //我的好友,拿粉丝列表改的
+    public function my_friend_list(){
+        $list = Db::name('user_follow')
+            ->alias('follow')
+            ->join('user','follow.uid = user.id','LEFT')
+            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
+            ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
+            ->where('follow.follow_uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
+
+        $list = list_domain_image($list,['avatar']);
+        $list = list_birthday_age($list);
+
+        //我的关注uids
+        $my_follow_uids = $this->my_follow_uids();
+
+        $new_rs = []; //另起
+        if(!empty($list)){
+            foreach($list as $key => &$val){
+                //用户vip
+                $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
+                unset($val['vip_endtime']);
+                //是否关注
+                $val['is_follow'] = in_array($val['id'],$my_follow_uids) ? 1 : 0;
+                //我的粉丝,且是我的关注的,另起
+                if($val['is_follow'] == 1){
+                    $new_rs[] = $val;
+                }
+            }
+
+        }
+
+        $this->success('success',$new_rs);
+    }
+
+
     //关注某人
     public function follow_one(){
         $follow_uid = input('follow_uid',0);
@@ -73,13 +133,33 @@ class Userfollow extends Api
             $this->error('关注失败');
         }
 
+        //被关注人如果没有关注我,发一条消息,让他加好友,也就是让他回关
+        $map2 = [
+            'uid' => $follow_uid,
+            'follow_uid' => $this->auth->id,
+        ];
+
+        $check = Db::name('user_follow')->where($map2)->find();
+        if(!$check){
+            $message = [
+                'user_id' => $follow_uid,
+                'title'   => '好友请求',
+                'content' => '有人关注了你,回关TA成为好友',
+                'createtime' => time(),
+                'status' => 0,
+                'infotype' => 'newfriend',//关注,请求好友
+                'infotype_id' => 0,
+            ];
+            Db::name('message')->insertGetId($message);
+        }
+
         //tag任务赠送金币
         //关注3人加3金币
-        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
+        /*$task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
         if($task_rs === false){
             Db::rollback();
             $this->error('完成任务赠送奖励失败');
-        }
+        }*/
 
         Db::commit();
         $this->success('操作成功',$id);
@@ -107,4 +187,20 @@ class Userfollow extends Api
         $rs = Db::name('user_follow')->where($map)->delete();
         $this->success('操作成功');
     }
+
+    //是否关注
+    private function is_follow($uid,$follow_uid){
+        $is_follow = Db::name('user_follow')->where(['uid'=>$uid,'follow_uid'=>$follow_uid])->find();
+        return $is_follow ? 1 : 0;
+    }
+
+    //我的关注uids
+    private function my_follow_uids(){
+        return Db::name('user_follow')->where('uid',$this->auth->id)->column('follow_uid');
+    }
+
+    //我的粉丝uids
+    private function my_fans_uids(){
+        return Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
+    }
 }