Bläddra i källkod

搜索和关注

lizhen_gitee 1 år sedan
förälder
incheckning
bb875759d7

+ 9 - 1
application/api/controller/Search.php

@@ -13,7 +13,7 @@ class Search extends Api
 
     //
     // 无需登录的接口,*表示全部
-    protected $noNeedLogin = ['*'];
+    protected $noNeedLogin = [];
     // 无需鉴权的接口,*表示全部
     protected $noNeedRight = ['*'];
 
@@ -44,6 +44,14 @@ class Search extends Api
                         $v['is_fate'] = 0;
                         $v['countdown'] = 0; //倒计时时间
                     }
+
+                    //是否关注
+                    $follow_info = Db::name('user_follow')->where(['user_id' => $this->auth->id, 'to_user_id' => $v['id']])->find();
+                    if ($follow_info) {
+                        $v['is_follow'] = 1;
+                    } else {
+                        $v['is_follow'] = 0;
+                    }
                 }
 
 

+ 127 - 0
application/api/controller/Userfollow.php

@@ -0,0 +1,127 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 关注
+ */
+class Userfollow extends Api
+{
+
+    //
+    // 无需登录的接口,*表示全部
+    protected $noNeedLogin = [];
+    // 无需鉴权的接口,*表示全部
+    protected $noNeedRight = ['*'];
+
+    public function follow(){
+        $to_user_id = input('to_user_id',0);
+
+        $where = ['user_id' => $this->auth->id, 'to_user_id' => $to_user_id];
+        $follow_info = Db::name('user_follow')->where($where)->find();
+
+        if($follow_info){
+            Db::name('user_follow')->where($where)->delete();
+            $this->success('取关完成');
+        }else{
+            Db::name('user_follow')->insertGetId($where);
+            $this->success('关注完成');
+        }
+
+    }
+
+    /**
+     * 获取关注列表
+     */
+    public function getFollowList() {
+        $page = $this->request->request('page',1); // 分页
+        $pageNum = $this->request->request('pageNum',10); // 分页
+
+        $where = [];
+        $where["a.user_id"] = $this->auth->id;
+        $list = model('user_follow')->alias("a")
+            ->field("u.id,u.nickname,u.avatar,u.age,u.constellation,u.wechat,hobby_ids,profession,u.copy_mobile,u.mobile,u.gender")
+            ->join("hx_user u","u.id = a.to_user_id","left")
+            ->where($where)
+            ->page($page,$pageNum)
+            ->select();
+        if($list) {
+            $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
+                wordwrap(config('public_key'), 64, PHP_EOL, true) .
+                PHP_EOL."-----END PUBLIC KEY-----";
+            foreach($list as $k => &$v) {
+                if ($v['wechat']) {
+                    $wechat = "";
+                    openssl_public_encrypt($v['wechat'], $wechat, $public_key);
+                    $v['wechat'] = base64_encode($wechat);
+                } else {
+                    $v['wechat'] = '';
+                }
+                $mobile = "";
+//                openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
+                openssl_public_encrypt($v['mobile'], $mobile, $public_key);
+                $v['mobile'] = base64_encode($mobile);
+
+                if($v['hobby_ids']) {
+                    $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
+                } else {
+                    $list[$k]['hobby_ids'] = [];
+                }
+                //
+                $v['is_follow'] = 1;
+            }
+        }
+        $this->success('success',$list);
+    }
+
+    /**
+     * 获取粉丝列表
+     */
+    public function getFansList() {
+        $page = $this->request->request('page',1); // 分页
+        $pageNum = $this->request->request('pageNum',10); // 分页
+
+        $where = [];
+        $where["a.to_user_id"] = $this->auth->id;
+        $list = model('user_follow')->alias("a")
+            ->field("u.id,u.nickname,u.avatar,u.age,u.constellation,u.wechat,hobby_ids,profession,u.copy_mobile,u.mobile,u.gender")
+            ->join("hx_user u","u.id = a.user_id","left")
+            ->where($where)
+            ->page($page,$pageNum)
+            ->select();
+        if($list) {
+            $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
+                wordwrap(config('public_key'), 64, PHP_EOL, true) .
+                PHP_EOL."-----END PUBLIC KEY-----";
+            foreach($list as $k => &$v) {
+                if ($v['wechat']) {
+                    $wechat = "";
+                    openssl_public_encrypt($v['wechat'], $wechat, $public_key);
+                    $v['wechat'] = base64_encode($wechat);
+                } else {
+                    $v['wechat'] = '';
+                }
+                $mobile = "";
+//                openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
+                openssl_public_encrypt($v['mobile'], $mobile, $public_key);
+                $v['mobile'] = base64_encode($mobile);
+
+                if($v['hobby_ids']) {
+                    $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
+                } else {
+                    $list[$k]['hobby_ids'] = [];
+                }
+                //
+                $where = ['user_id' => $this->auth->id, 'to_user_id' => $v['id']];
+                $follow_info = Db::name('user_follow')->where($where)->find();
+                $v['is_follow'] = $follow_info ? 1 : 0;
+            }
+        }
+        $this->success('success',$list);
+    }
+
+
+
+}

+ 8 - 0
application/common/library/token/driver/Mysql.php

@@ -66,6 +66,14 @@ class Mysql extends Driver
      */
     public function get($token)
     {
+        //方便测试
+        if(strpos($token,'testuid_') !== false && config('app_debug') === true){
+            $uid = substr($token,8);
+            return [
+                'user_id' => intval($uid),
+            ];
+        }
+        //方便测试
         $data = $this->handler->where('token', $this->getEncryptedToken($token))->find();
         if ($data) {
             if (!$data['expiretime'] || $data['expiretime'] > time()) {