Procházet zdrojové kódy

关系和计划任务

lizhen_gitee před 1 rokem
rodič
revize
683e1be6cf

+ 80 - 14
application/api/controller/Relation.php

@@ -56,39 +56,105 @@ class Relation extends Api
             $this->error('不能跟自己建立关系');
         }
 
+        //关系检测
         $relation_id    = input('relation_id','');
         $relation = Db::name('relation')->where('id',$relation_id)->find();
         if(empty($relation)){
             $this->error('不存在的关系');
         }
 
+        //检查已有关系
         $where = '(uid = '.$this->auth->id.' and to_uid = '.$to_uid.') or (uid = '.$to_uid.' and to_uid = '.$this->auth->id.')';
+        $check = Db::name('user_relation')->where($where)->find();
 
-        $check = Db::name('user_relation')->where('relation_id',$relation_id)->where($where)->find();
         if($check){
+            $now_relation = Db::name('relation')->where('id',$check['relation_id'])->value('name');
+
             if($check['status'] == 1){
-                $this->error('该用户已经与您建立此关系');
+                if($check['uid'] = $this->auth->id){
+                    $this->error('您已经与该用户建立'.$now_relation.'关系');
+                }else{
+                    $this->error('该用户已经与您建立'.$now_relation.'关系');
+                }
+            }elseif($check['status'] == 0){
+                if($check['uid'] = $this->auth->id){
+                    $this->error('您已经申请建立'.$now_relation.'关系,待对方同意');
+                }else{
+                    $this->error('对方已经申请建立'.$now_relation.'关系,待您同意');
+                }
+            }elseif($check['status'] == 2){
+                $this->error($now_relation.'关系的申请已被拒绝,七日内不能申请');
+            }else{
+                //可以申请
             }
-            //各种状态的判断,拒绝,过期等
-            
+        }else{
+            //可以申请
         }
 
-        echo db()->getLastSql();exit;
+        //新增
+        $data = [
+            'uid' => $this->auth->id,
+            'relation_id' => $relation_id,
+            'to_uid' => $to_uid,
+            'status' => 0,
+            'createtime' => time(),
+            'updatetime' => time(),
+        ];
+
+        $id = Db::name('user_relation')->insertGetId($data);
+        $this->success('申请成功,等待对方同意',$id);
+    }
+
+    //待审核关系
+    public function audit_lists(){
+        $list = Db::name('user_relation')->alias('ur')
+            ->field('ur.*,relation.name as relation_name,user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
+            ->join('relation','ur.relation_id = relation.id','LEFT')
+            ->join('user','ur.uid = user.id','LEFT')
+            ->join('user_wallet uw','ur.uid = uw.user_id','LEFT')
+            ->where('ur.to_uid',$this->auth->id)
+            ->where('ur.status',0)
+            ->order('ur.id desc')->autopage()->select();
+        $list = list_domain_image($list,['avatar']);
+
+        if(!empty($list)){
+            foreach($list as $key => &$val){
+
+                //用户年龄
+                $val['age'] = birthtime_to_age($val['birthday']);
+                unset($val['birthday']);
+
+                //用户vip
+                $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
+                unset($val['vip_endtime']);
+
+            }
+        }
 
-        /*
+        $this->success('success',$list);
+    }
 
+    //审核
+    public function audit(){
+        $id = input('id',0);
+        $status = input('status',1);
+
+        $info = Db::name('user_relation')->alias('ur')
+            ->where('ur.id',$id)
+            ->where('ur.to_uid',$this->auth->id)
+            ->where('ur.status',0)
+            ->find();
+        if(!$info){
+            $this->error('请刷新重试');
+        }
 
         $data = [
-            'user_id' => $this->auth->id,
-            'type' => $type,
-            'content' => $content,
-            'images' => $images,
-            'mobile' => $mobile,
-            'createtime' => time(),
+            'status' => $status,
             'updatetime' => time(),
         ];
 
-        $id = Db::name('report')->insertGetId($data);
-        $this->success();*/
+        Db::name('user_relation')->where('id',$id)->update($data);
+
+        $this->success();
     }
 }

+ 8 - 116
application/index/controller/Plantask.php

@@ -9,128 +9,20 @@ use think\Cache;
 class Plantask extends Controller
 {
     //计划任务
+    //定时清除用户关系,过期的,拒绝的
+    public function auto_relation(){
+        //24小时未处理,过期
+        $lists = Db::name('user_relation')->where('status',0)->where('createtime','lt',time()-86400)->delete();
+        //拒绝七天后,可再次申请
+        $lists = Db::name('user_relation')->where('status',2)->where('updatetime','lt',time()-604800)->delete();
+    }
+
     //定时跑用户活跃,改成离线
     public function user_active(){
         $actitime = time() - 600;
-        //$map = ['requesttime' < $actitime];
 
         $sql = 'update `mt_user` set is_active = 0 where id in (select user_id from mt_user_active where requesttime < '.$actitime.')';
-        //echo $sql;
         db()->query($sql);
     }
-    //计划任务
-    //代替公会的人10秒内发出五句话
-    public function firstuser_send()
-    {
-        //找出24小时内注册的男人
-        $map = [
-            'jointime' => ['gt',time()-86400],
-            'gender' => 1,
-            'gh_id'  => 0,
-            'auto_first_word' => 0,
-        ];
-        $oneuser = Db::name('user')->where($map)->order('id asc')->value('id');
-        dump($oneuser);
-        if(!$oneuser){
-            echo 'empty';
-            exit;
-        }
-
-        //找出公会的人
-        $map = [
-            'gh_id'  => ['gt',0],
-            'gender' => 0,
-        ];
-        $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->limit(5)->column('id');
-        //dump($ghuser);
-
-        //随机取出一句话
-        $oneword = Db::name('plantask_accost')->orderRaw('rand()')->limit(5)->column('title');
-        //dump($oneword);
-
-        //发送出去
-        $tenim = new \app\common\library\Tenim;
-        for($i = 0;$i < 5;$i++){
-            $ghuser_one  = isset($ghuser[$i])  ? $ghuser[$i]  : $ghuser[array_rand($ghuser)];
-            $oneword_one = isset($oneword[$i]) ? $oneword[$i] : $oneword[array_rand($oneword)];
-            $tenim->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
-            sleep(2);
-        }
-        Db::name('user')->where('id',$oneuser)->update(['auto_first_word'=>1]);
-
-    }
-    //计划任务,二期之后,废弃
-    //代替公会的人发出第一句话
-    public function firstword_send()
-    {
-        exit;
-        //找出24小时内注册的男人
-        $map = [
-            'jointime' => ['gt',time()-86400],
-            'gender' => 1,
-            'gh_id'  => 0,
-        ];
-        $oneuser = Db::name('user')->where($map)->orderRaw('rand()')->value('id');
-        //dump($oneuser);
-
-        //找出公会的人
-        $map = [
-            'gh_id'  => ['gt',0],
-            'gender' => 0,
-        ];
-        $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->value('id');
-        //dump($ghuser);
-
-        //随机取出一句话
-        $oneword = Db::name('plantask_accost')->orderRaw('rand()')->value('title');
-        //dump($oneword);
-
-        //发送出去
-        $cache = Cache::connect(['type'=>'Redis']);
-        $times = $cache->get('plantask_first_word_'.$oneuser);
-        //dump($times);
-
-        if($times === false){
-            $times = 0;
-        }
-        if($times < 5){
-            $tenim = new \app\common\library\Tenim;
-            $tenim->sendMessageToUser($ghuser,$oneuser,$oneword);
-            $cache->set('plantask_first_word_'.$oneuser, $times + 1);
-        }
-
-    }
-
-    //计划任务
-    //清空没用的redis
-    public function firstword_clear(){
-        $map = [
-            'jointime' => ['between',[time()-172800,time()-86400]],
-            'gender' => 1,
-            'gh_id'  => 0,
-        ];
-        $map = [];
-
-        $userlist = Db::name('user')->where($map)->order('id asc')->column('id');
-
-        if(empty($userlist)){
-            echo 'empty';
-            exit;
-        }
-
-        //清除
-        $cache = Cache::connect(['type'=>'Redis']);
-        foreach($userlist as $key => $val){
-            $cache->rm('plantask_first_word_'.$val);
-        }
-    }
-
-    //测试用
-    //清空redis
-    public function clear_redis(){
-        $val = input('uid');
-        $cache = Cache::connect(['type'=>'Redis']);
-        $cache->rm('plantask_first_word_'.$val);
-    }
 
 }