Browse Source

首页附近用户

lizhen_gitee 1 year ago
parent
commit
a7b24db52a

+ 89 - 120
application/api/controller/Index.php

@@ -12,141 +12,110 @@ class Index extends Api
     protected $noNeedLogin = ['index'];
     protected $noNeedRight = ['*'];
 
+
+
     public function index(){
         echo 'apisuccess';
         exit;
     }
 
+    //附近
+    //是vip,且开启了隐身的,不能在内
     public function fujin(){
-        //是vip,且开启了隐身的,不能在内
+        $cityname = input('cityname',$this->auth->cityname);
+
+        $where = [
+            'user.id' => ['neq',$this->auth->id],
+            'user.status' => 1,
+            'user.photo_images' => ['neq',''],
+            'user.cityname' => $cityname,
+            'power.yinshen' => 0,
+        ];
+        //性别
+        $gender = input('gender','all');
+        if($gender != 'all'){
+            $where['user.gender'] = $gender;
+        }
+        //属性
+        $attribute = input('attribute','all');
+        if($attribute != 'all' && $attribute != 'BOTH'){
+            $where['user.attribute'] = $attribute;
+        }
+        //排除黑名单的
+        $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid');
+        if(!empty($black_ids)){
+            $where['user.id'] = ['NOTIN',$black_ids];
+        }
+        //年龄
+        $agemin = input('agemin',18);
+        if($agemin > 18){
+            $where['user.birthday'] = ['lt',time()-$agemin*31536000];
+        }
+        $agemax = input('agemax',100);
+        if($agemax < 100){
+            $where['user.birthday'] = ['gt',time()-$agemax*31536000];
+        }
+        if($agemin > 18 && $agemax < 100){
+            $where['user.birthday'] = ['between',[time()-$agemax*31536000,time()-$agemin*31536000]];
+        }
+        //距离
+        $distancemin = input('distancemin',0);
+        if($distancemin > 0){
+            $where['distance'] = ['gt',$distancemin];
+        }
+        $distancemax = input('distancemax',0);
+        if($distancemax > 0){
+            $where['distance'] = ['lt',$distancemax];
+        }
+        if($distancemin > 0 && $distancemax > 0){
+            $where['distance'] = ['between',[$distancemin,$distancemax]];
+        }
+
+        $field = [
+            'user.id',
+            'user.username',
+            'user.nickname',
+            'user.avatar',
+            'user.photo_images',
+            'user.gender',
+            'user.birthday',
+            'user.cityname',
+            'user.attribute',
+            'user.is_active',
+            'user.longitude',
+            'user.latitude',
+            'user.cityname',
+            'user.attribute',
+
+            'wallet.vip_endtime',
+            '(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('user_wallet wallet','user.id = wallet.user_id','LEFT')
+            ->join('user_power power' ,'user.id = power.user_id','LEFT')
+            ->where($where)
+            ->order('distance asc')
+            ->autopage()
+            ->select();
+        $list = list_domain_image($list,['avatar','photo_images']);
+        foreach($list as $key => &$val){
+            $val['age'] = birthtime_to_age($val['birthday']);
+            $val['photo_images'] = explode(',',$val['photo_images'])[0];
+            $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
+
+            $val['distance'] = bcdiv(intval($val['distance']),1000,2).'km';
+        }
 
+        $this->success(1,$list);
     }
-    public function tuijian(){}
 
+    public function tuijian(){}
 
-    /**
-     * 获取邀请图片
-     */
-    public function getInviteImg() {
-        $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
-        if(!in_array($plat,[1,2])) $this->error("参数错误");
-        // 获取用户的邀请码
-        $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
-
-        // 文字图片合成
-        $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
-        $img = imagecreatefromstring(file_get_contents($bigImgPath));
-        //字体文件
-        $font = realpath('./assets/fonts/lato/lato-black.ttf');
-
-        //字体颜色(RGB)
-        $black = imagecolorallocate($img, 217, 76, 41);
-        //字体大小
-        $fontSize = 30;
-        //旋转角度
-        $circleSize = 0;
-        //左边距
-        $left = 275;
-        //上边距
-        $top = 540;
-        imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
-        $filename = date("YmdH").".jpeg";
-        $path = "/uploads/qrcode/".$filename;
-        $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
-        list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
-        switch ($bgType) {
-            case 1://gif
-                header('Content-Type:image/gif');
-                imagegif($img,$file);
-                break;
-            case 2://jpg
-                header('Content-Type:image/jpg');
-                imagejpeg($img,$file);
-                break;
-            case 3://jpg
-                header('Content-Type:image/png');
-                imagepng($img,$file);
-                break;
-            default:
-                break;
-        }
-        //销毁照片
-        imagedestroy($img);
-
-        // 图片和二维码合成
-        $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
-
-
-        $background = $file;
-        $target = $this->httpurl($qrcode);
-
-        $background_iamge = imagecreatefromstring(file_get_contents($background));
-        $target_image = imagecreatefromstring(file_get_contents($target));
-        list($target_width, $target_height, $target_type) = getimagesize($target);
-        imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
-        list($background_width, $background_height, $background_type) = getimagesize($background);
-        switch ($background_type) {
-            case 1://gif
-                header('Content-Type:image/gif');
-                imagegif($background_iamge,$file);
-                break;
-            case 2://jpg
-                header('Content-Type:image/jpg');
-                imagejpeg($background_iamge,$file);
-                break;
-            case 3://jpg
-                header('Content-Type:image/png');
-                imagepng($background_iamge,$file);
-                break;
-            default:
-                break;
-        }
-        $savepath = $this->httpurlLocal($path);
 
-        $this->success("获取成功!",$savepath);
-    }
 
 
 
 
-    /**
-     * 评论时间转换
-     * @param null $time
-     * @return false|string
-     */
-    private function get_last_time($time = NULL) {
-        $text = '';
-        $time = $time === NULL || $time > time() ? time() : intval($time);
-        $t = time() - $time; //时间差 (秒)
-        $y = date('Y', $time)-date('Y', time());//是否跨年
-        switch($t){
-            case $t == 0:
-                $text = '刚刚';
-                break;
-            case $t < 60:
-                $text = $t . '秒前'; // 一分钟内
-                break;
-            case $t < 60 * 60:
-                $text = floor($t / 60) . '分钟前'; //一小时内
-                break;
-            case $t < 60 * 60 * 24:
-                $text = floor($t / (60 * 60)) . '小时前'; // 一天内
-                break;
-            case $t < 60 * 60 * 24 * 3:
-                $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
-                break;
-            case $t < 60 * 60 * 24 * 30:
-                $text = date('m月d日 H:i', $time); //一个月内
-                break;
-            case $t < 60 * 60 * 24 * 365&&$y==0:
-                $text = date('m月d日', $time); //一年内
-                break;
-            default:
-                $text = date('Y年m月d日', $time); //一年以前
-                break;
-        }
 
-        return $text;
-    }
 
 }

+ 5 - 2
application/common/controller/Api.php

@@ -439,7 +439,8 @@ class Api
         return true;
     }
 
-    //获取用户获取
+    //获取用户是否活跃,7200秒,2小时
+    //1活跃,0不活跃
     protected function user_isactive($user_id = 0){
         if(!$user_id && $this->auth->isLogin()){
             $user_id = $this->auth->id;
@@ -453,7 +454,7 @@ class Api
         return $active;
     }
 
-    //用户是否vip
+    //用户是否vip,1是,0否
     protected function is_vip($user_id){
         $result = 0;
 
@@ -463,6 +464,8 @@ class Api
         return $result;
     }
 
+    //用户是否有某项权限
+    //1有,0没有
     protected function user_power($user_id,$power = ''){
         $is_vip = $this->is_vip($user_id);
         if($is_vip != 1){

+ 2 - 2
application/index/controller/Plantask.php

@@ -19,7 +19,7 @@ class Plantask extends Controller
 
     //定时跑用户活跃,改成离线
     public function auto_user_active(){
-        $actitime = time() - 600;
+        $actitime = time() - 7200;
 
         $sql = 'update `mt_user` set is_active = 0 where id in (select user_id from mt_user_active where requesttime < '.$actitime.')';
         db()->query($sql);
@@ -27,7 +27,7 @@ class Plantask extends Controller
 
     //vip过期的,三个隐私设置改成0
     public function auto_vipend(){
-        $sql = 'update `mt_user_power` set yinsi = 0,yinshen = 0,wuhen = 0 where user_id in (select user_id from mt_user_wallet where vip_endtime < '.time().')';
+        $sql = 'update `mt_user_power` set yinsi = 0,yinshen = 0,wuhen = 0 where user_id in (select user_id from mt_user_wallet where vip_endtime > 0 and vip_endtime < '.time().')';
         db()->query($sql);
     }