|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|