Jelajahi Sumber

首页,同城,附近,用户一些接口

lizhen_gitee 1 tahun lalu
induk
melakukan
474cc2911a

+ 23 - 0
application/api/controller/Banner.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 示例接口
+ */
+class Banner extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    //轮播图
+    public function banner()
+    {
+        $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 1])->order('weigh', 'desc')->select();
+        $list = list_domain_image($list, ['image']);
+
+        $this->success(1, $list);
+    }
+}

+ 20 - 4
application/api/controller/Baseconfig.php

@@ -56,23 +56,39 @@ class Baseconfig extends Api
         $this->success_find('success',$info);
     }
 
+    /**
+     * 年龄段列表
+     * @return void
+     */
+    public function ageList()
+    {
+        try {
+            $field = 'id,name';
+            $where['status'] = 1;
+            $result = model('Age')->field($field)->where($where)->order('weigh asc')->select();
+
+            $this->success('获取成功',$result);
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
 
 
     //个人资料的一下枚举
     public function userinfo_enum(){
 //        $enum_hobby = Db::name('enum_hobby')->field('id,name')->order('weight desc,id desc')->select();
-//        $enum_job = Db::name('enum_job')->field('id,name')->order('weight desc,id desc')->select();
+        $enum_job = Db::name('enum_job')->field('id,name')->order('weight desc,id desc')->select();
 //        $enum_marital = Db::name('enum_marital')->field('id,name')->order('weight desc,id desc')->select();
 //        $enum_education = Db::name('enum_education')->field('id,name')->order('weight desc,id desc')->select();
-        $enum_tag = Db::name('enum_tag')->field('id,name')->order('weight desc,id desc')->select();
+//        $enum_tag = Db::name('enum_tag')->field('id,name')->order('weight desc,id desc')->select();
 //        $enum_wages = Db::name('enum_wages')->field('id,name')->order('weight desc,id desc')->select();
 
         $data = [
 //            'enum_hobby' => $enum_hobby,
-//            'enum_job' => $enum_job,
+            'enum_job' => $enum_job,
 //            'enum_marital' => $enum_marital,
 //            'enum_education' => $enum_education,
-            'enum_tag' => $enum_tag,
+//            'enum_tag' => $enum_tag,
 //            'enum_wages' => $enum_wages,
         ];
 

+ 237 - 40
application/api/controller/Index.php

@@ -25,13 +25,13 @@ class Index extends Api
      * 首页
      *
      */
-    public function index()
+    /*public function index()
     {
         // 强制关闭需要退出正在房间的用户
         $tenim = new \app\api\controller\Tenim();
         $tenim->outMemberFromRoom(4);
         $this->success('请求成功');
-    }
+    }*/
 
 
 //    /**
@@ -626,22 +626,7 @@ class Index extends Api
         return $text;
     }
 
-    /**
-     * 年龄段列表
-     * @return void
-     */
-    public function ageList()
-    {
-        try {
-            $field = 'id,name';
-            $where['status'] = 1;
-            $result = model('Age')->field($field)->where($where)->order('weigh asc')->select();
 
-            $this->success('获取成功',$result);
-        } catch (Exception $e) {
-            $this->error($e->getMessage());
-        }
-    }
 
     /**
      * 星座列表
@@ -662,30 +647,8 @@ class Index extends Api
         }
     }
 
-    /**
-     * 轮播图列表
-     * @return void
-     */
-    public function bannerList()
-    {
-        try {
-            $field = 'id,title,image,url';
-            $where['status'] = 1;
-            $result = model('Banner')->field($field)->where($where)->order('weigh asc')->select();
-            if (!$result) {
-                $result = list_domain_image($result,['image']);
-            }
-            $this->success('获取成功',$result);
-        } catch (Exception $e) {
-            $this->error($e->getMessage());
-        }
-    }
 
-    //关键字过滤
-    public function keyworldconfig(){
-        $config = config('keyworld');
-        $this->success('success',$config);
-    }
+
 
     //开关设置
     public function switchenum(){
@@ -697,4 +660,238 @@ class Index extends Api
         $this->success('success',$rs);
     }
 
+    /////////////
+
+    public function index(){
+        echo 'apisuccess';
+        exit;
+    }
+
+
+
+    //附近
+    public function fujin(){
+        $where = [
+            'user.id' => ['neq',$this->auth->id],
+            'user.status' => 1,
+            'user.city_id' => $this->auth->city_id,
+        ];
+
+        //排除黑名单的
+        $where_black = [];
+        $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
+        if(!empty($black_ids)){
+            $where_black['user.id'] = ['NOTIN',$black_ids];
+        }
+
+        $field = [
+            'user.id',
+            'user.u_id',
+            'user.username',
+            'user.nickname',
+            'user.avatar',
+            'user.gender',
+            'user.desc',
+            'age.name as age_text',
+            'job.name as job_text',
+            'area.name as city_text',
+            '(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(user.longitude,user.latitude))*111195) as distance',
+        ];
+        $list = Db::name('user')->alias('user')->field($field)
+            ->join('age age','user.age_id = age.id','LEFT')
+            ->join('enum_job job','user.job_id = job.id','LEFT')
+            ->join('shopro_area area','user.city_id = area.id','LEFT')
+            ->where($where)
+            ->where($where_black)
+            ->order('distance asc')
+            ->autopage()
+            ->select();
+        $list = list_domain_image($list,['avatar']);
+        foreach($list as $key => &$val){
+            $val['distance'] = bcdiv(intval($val['distance']),1000,2).'km';
+        }
+
+        $this->success(1,$list);
+    }
+
+    //同城
+    public function samecity(){
+
+        $where = [
+            'user.id' => ['neq',$this->auth->id],
+            'user.status' => 1,
+            'user.city_id' => $this->auth->city_id,
+        ];
+
+        //排除黑名单的
+        $where_black = [];
+        $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
+        if(!empty($black_ids)){
+            $where_black['user.id'] = ['NOTIN',$black_ids];
+        }
+
+        $field = [
+            'user.id',
+            'user.u_id',
+            'user.username',
+            'user.nickname',
+            'user.avatar',
+            'user.gender',
+            'user.desc',
+            'age.name as age_text',
+            'job.name as job_text',
+            'area.name as city_text',
+        ];
+        $list = Db::name('user')->alias('user')->field($field)
+            ->join('age age','user.age_id = age.id','LEFT')
+            ->join('enum_job job','user.job_id = job.id','LEFT')
+            ->join('shopro_area area','user.city_id = area.id','LEFT')
+            ->where($where)
+            ->where($where_black)
+            ->autopage()
+            ->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success(1,$list);
+    }
+
+    //匹配配置
+    public function pipei_config(){
+        $result = [
+            'index_pipei_switch' => config('site.index_pipei_switch'), //匹配开关
+        ];
+
+        //首页匹配每天每人匹配次数
+        $user_id = $this->auth->id;
+        $is_vip = $this->is_vip($this->auth->id);
+        $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
+
+        $times_limit_redis = 'pipei_times_limit_'.$user_id;
+        $user_times = Cache::get($times_limit_redis) ?: 0;
+
+        if($times_limit > -1){
+            $remain_times = $times_limit - $user_times;
+            if($remain_times < 0){
+                $remain_times = 0;
+            }
+        }else{
+            $remain_times = -1;
+        }
+
+        $result['remain_times'] = $remain_times;
+
+        $this->success(1,$result);
+    }
+
+    //匹配
+    //做防止重复处理,参照荔枝
+    public function pipei(){
+
+        //首页匹配功能开关
+        $index_pipei_switch = config('site.index_pipei_switch');
+        if($index_pipei_switch != 1){
+            $this->error('匹配功能维护中,请稍后再试');
+        }
+
+        //缓存,防重复
+        $user_id = $this->auth->id;
+        $user_id_redis = 'pipei_repeat_'.$user_id;
+        $redis_ids = json_decode(Cache::get($user_id_redis),true);
+
+        //首页匹配每天每人匹配次数
+        $is_vip = $this->is_vip($this->auth->id);
+        $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
+
+        $times_limit_redis = 'pipei_times_limit_'.$user_id;
+        $user_times = Cache::get($times_limit_redis) ?: 0;
+
+        if($times_limit > -1 && $user_times >= $times_limit){
+            $this->error('今日已超匹配上限'.$times_limit.'次');
+        }
+
+        //where
+        $where = [
+            'user.id' => ['neq',$this->auth->id],
+            'user.status' => 1,
+        ];
+
+        //性别
+        $gender = input('gender','all');
+        if($gender != 'all'){
+            $where['user.gender'] = $gender;
+        }
+
+        //排除黑名单的
+        $where_black = [];
+        $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid');
+        if(!empty($black_ids)){
+            $where_black['user.id'] = ['NOTIN',$black_ids];
+        }
+
+        //匹配一个
+        $result = $this->pipei_action($redis_ids,$where,$where_black);
+
+        //匹配不到,移除防重复
+        if(!$result) {
+            Cache::rm($user_id_redis);
+            $redis_ids = [];
+            $result = $this->pipei_action($redis_ids,$where,$where_black);
+        }
+        // 追加一个防重复
+        if($result){
+            if($redis_ids) {
+                $redis_ids[] = $result;
+            } else {
+                $redis_ids = [$result];
+            }
+            Cache::set($user_id_redis,json_encode($redis_ids));
+
+            //设置次数
+            $second = strtotime(date('Y-m-d'))+86400 - time();
+            Cache::set($times_limit_redis,$user_times+1,$second);
+        }else{
+            Cache::rm($user_id_redis);
+        }
+
+        $this->success(1,$result);
+    }
+
+    private function pipei_action($redis_ids,$where,$where_black){
+        $where_op = [];
+        if(!empty($redis_ids)){
+            $where_op['user.id'] = ['NOTIN',$redis_ids];
+        }
+
+        $result = Db::name('user')->alias('user')
+            ->join('user_active active' ,'user.id = active.user_id','LEFT')
+            ->where($where)
+            ->where($where_op)
+            ->where($where_black)
+            ->orderRaw('rand()')
+            ->value('user.id');
+
+        return $result;
+    }
+
+    public function test(){
+        //缓存,防重复
+        $user_id = $this->auth->id;
+        $user_id_redis = 'pipei_repeat_'.$user_id;
+        $redis_ids = json_decode(Cache::get($user_id_redis),true);
+        dump($redis_ids);
+
+
+        $times_limit_redis = 'pipei_times_limit_'.$user_id;
+        $user_times = Cache::get($times_limit_redis) ?: 0;
+        dump($user_times);
+    }
+    public function testrm(){
+        $user_id = $this->auth->id;
+        $user_id_redis = 'pipei_repeat_'.$user_id;
+        Cache::rm($user_id_redis);
+
+        $times_limit_redis = 'pipei_times_limit_'.$user_id;
+        Cache::rm($times_limit_redis);
+    }
+
 }

File diff ditekan karena terlalu besar
+ 46 - 0
application/api/controller/User.php


+ 1 - 1
application/api/library/ExceptionHandle.php

@@ -13,7 +13,7 @@ class ExceptionHandle extends Handle
 
     public function render(Exception $e)
     {
-        //return parent::render($e);
+        return parent::render($e);
         $statuscode = $code = 500;
         $msg = $e->getMessage();
         // 验证异常

+ 1 - 1
application/common/controller/Api.php

@@ -190,7 +190,7 @@ class Api
         $actionname = strtolower($this->request->action());
 
         // token
-        $token = $this->request->server('HTTP_TOKEN', $this->request->param('token', \think\Cookie::get('token')));
+        $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
 
         $path = str_replace('.', '/', $controllername) . '/' . $actionname;
         // 设置当前请求的URI

+ 15 - 18
application/common/library/Auth.php

@@ -98,17 +98,14 @@ class Auth
                 $this->setError('Account not exist');
                 return false;
             }
-            if (!in_array($user['status'],['normal'])) {
-                if ($user['status'] == 'hidden') {
-                    $this->setError('Account is locked');
-                } else if ($user['status'] == 'cancel') {
-                    $this->setError('账号已注销');
-                } else {
-                    $this->setError('账号状态异常');
-                }
+            if ($user['status'] == -1) {
+                $this->setError('账号已注销');
+                return false;
+            }
+            if ($user['status'] != 1) {
+                $this->setError('Account is locked');
                 return false;
             }
-
             //追加权限
             $userpower = UserPower::getByUserId($user_id);
             if(!$userpower){
@@ -206,7 +203,7 @@ class Auth
         //https://bansheng-1304213176.cos.ap-guangzhou.myqcloud.com/
         $params = array_merge($data, [
             'nickname' => "K歌_" . $data["u_id"],
-            'salt'     => Random::alnum(),
+//            'salt'     => Random::alnum(),
             'joinip'    => $ip,
             'logintime' => $time,
             'loginip'   => $ip,
@@ -486,20 +483,20 @@ class Auth
     {
         $data = $this->_user->toArray();
         // 获取粉丝数
-        $fans = \app\common\model\ViewFans::where(["user_id" => $this->_user->id])->value("fans");
-        $follows = \app\common\model\ViewFollows::where(["user_id" => $this->_user->id])->value("follows");
-        $fansfollows["fans"] = $fans ? $fans : 0;
-        $fansfollows["follows"] = $follows ? $follows : 0;
+
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
 
         //用户钱包
         $userwallet = Db::name('user_wallet')->where('user_id',$this->_user->id)->find();
-        $userinfo['money'] = $userwallet['money'];
-        $userinfo['jewel'] = $userwallet['jewel'];
+        $userinfo['wallet'] = $userwallet;
 
         $userinfo = array_merge($userinfo, Token::get($this->_token));
-        $userinfo = array_merge($userinfo, $fansfollows);
+
+        //关注数量
+        $userinfo['follow_num'] = Db::name('user_follow')->where('uid',$this->id)->count('id');
+        //粉丝数量
+        $userinfo['fans_num'] = Db::name('user_follow')->where('follow_uid',$this->id)->count('id');
         // 获取贵族信息
         $nobleInfo = $this->_user->getUserNobleInfo($this->_user->id);
         $userinfo = array_merge($userinfo, $nobleInfo);
@@ -541,7 +538,7 @@ class Auth
         $userInfo['constellation_text'] = $userInfoA['constellation_text'];
         $userInfo['province_text'] = $userInfoA['province_text'];
         $userInfo['city_text'] = $userInfoA['city_text'];
-        $userInfo['friends_num'] = $userInfoA['friends_num'];
+//        $userInfo['friends_num'] = $userInfoA['friends_num'];
         $userInfo['look_num'] = $userInfoA['look_num'];
         // 是否设置密码
         $userinfo['is_setpwd'] = $data['password'] ? 1 : 0;

+ 3 - 3
application/common/model/User.php

@@ -67,7 +67,7 @@ class User extends Model
         return isset($list['name']) ? $list['name'] : '';
     }
 
-    public function getFriendsNumAttr($value, $data)
+    /*public function getFriendsNumAttr($value, $data)
     {
         $value = $value ? $value : (isset($data['id']) ? $data['id'] : 0);
         $num = 0;
@@ -82,7 +82,7 @@ class User extends Model
             }
         }
         return $num;
-    }
+    }*/
 
     public function getLookNumAttr($value, $data)
     {
@@ -458,7 +458,7 @@ class User extends Model
             $areaData = Db::name('shopro_area')->where($areaWhere)->column('id,name');
             $userInfo['province_text'] = isset($areaData[$provinceId]) ? $areaData[$provinceId] : '';
             $userInfo['city_text'] = isset($areaData[$cityId]) ? $areaData[$cityId] : '';
-            $userInfo['friends_num'] = $this->getFriendsNumAttr(false,['id' => $userId]);
+//            $userInfo['friends_num'] = $this->getFriendsNumAttr(false,['id' => $userId]);
             $userInfo['look_num'] = $this->getLookNumAttr(false,['id' => $userId]);
         }
         return $userInfo;

+ 1 - 1
application/config.php

@@ -247,7 +247,7 @@ return [
     // +----------------------------------------------------------------------
     'token'                  => [
         // 驱动方式
-        'type'     => 'Redis',
+        'type'     => 'Mysql',
         // 缓存前缀
         'key'      => 'i3d6o32wo8fvs1fvdpwens',
         // 加密方式

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini