123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?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);
- }
- }
|