Bladeren bron

匹配文字聊天的人,和扣费接口

lizhen_gitee 3 jaren geleden
bovenliggende
commit
382761ae7a
2 gewijzigde bestanden met toevoegingen van 81 en 12 verwijderingen
  1. 79 10
      application/api/controller/Usercenter.php
  2. 2 2
      thinkphp/helper.php

+ 79 - 10
application/api/controller/Usercenter.php

@@ -49,8 +49,8 @@ class Usercenter extends Api
     ];
 
     public function testredis(){
-        //redis_set(1,125);
-        dump(redis_get(1));
+        //redis_matching_set(1,125);
+        dump(redis_matching_get(1));
         $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
         dump($a);
     }
@@ -307,7 +307,43 @@ class Usercenter extends Api
 
         //扣费
         if(!empty($check) && $log_id){
-            $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'','user_match_audio_log',$log_id);
+            $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'','user_match_audio_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+
+        Db::commit();
+        $this->success('success');
+    }
+    //打字聊天每句话调用一次
+    public function typing_once(){
+        $to_user_id = input_post('to_user_id');
+
+
+        //设置价格
+        $price = config('site.typing_min_price');
+
+        Db::startTrans();
+
+        //记录日志
+        $data = [
+            'user_id' => $this->auth->id,
+            'price'   => $price,
+            'createtime' => time(),
+            'to_user_id' => $to_user_id,
+        ];
+
+        $log_id = Db::name('user_match_typing_log')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('扣费失败');
+        }
+
+        //扣费
+        if(!empty($check) && $log_id){
+            $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'','user_match_typing_log',$log_id);
             if($rs['status'] === false){
                 Db::rollback();
                 $this->error($rs['msg']);
@@ -357,8 +393,8 @@ class Usercenter extends Api
             'gender' => $this->auth->gender == 1 ? 0 : 1,
             'real_status' => 1,
             'idcard_status' => 1,
-            //打开视频开关的
-            'open_match_video' => 1,
+            //打开语音开关的
+            'open_match_audio' => 1,
             'id' => ['NOT IN',$my_follow]
         ];*/
         $map = [];
@@ -433,8 +469,41 @@ class Usercenter extends Api
         $this->success('success',$result);
     }
 
+    //聊天匹配
+    public function gettypinguser(){
+
+        //找到互关的人,排除
+        $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
+        //dump($follow_me);
+        $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
+        //dump($my_follow);exit;
+
+        //给出备选用户
+        /*$map = [
+            'status' =>1,
+            'gender' => $this->auth->gender == 1 ? 0 : 1,
+            'real_status' => 1,
+            'idcard_status' => 1,
+            //打开聊天开关的
+            'open_match_typing' => 1,
+            'id' => ['NOT IN',$my_follow]
+        ];*/
+        $map = [];
+
+        $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
+        $lists = $this->fliter_user($lists,10);
+
+        $result = [];
+        if(!empty($lists)){
+            foreach($lists as $key => $val){
+                $result[] = ['id'=>$val];
+            }
+        }
+        $this->success('success',$result);
+    }
+
     //过滤规则
-    private function fliter_user($lists){
+    private function fliter_user($lists,$number = 1){
 
         if(empty($lists)){
             return $lists;
@@ -443,8 +512,8 @@ class Usercenter extends Api
 
         //过滤掉通话中的
         foreach($lists as $key => $val){
-            if(redis_get($val['id']) == 1){
-                //unset($lists[$key]);
+            if(redis_matching_get($val['id']) == 1){
+                unset($lists[$key]);
             }
         }
 
@@ -481,7 +550,7 @@ class Usercenter extends Api
             $double_data = array_intersect($citydata,$tagdata);
         }
         //dump($double_data);
-        if(count($double_data) >= 1){
+        if(count($double_data) >= $number){
             return $double_data;
         }
 
@@ -489,7 +558,7 @@ class Usercenter extends Api
         $merge_data = array_merge($citydata,$tagdata);
         $merge_data = array_flip(array_flip($merge_data));
         //dump($merge_data);
-        if(count($merge_data) >= 1){
+        if(count($merge_data) >= $number){
             return $merge_data;
         }
 

+ 2 - 2
thinkphp/helper.php

@@ -364,11 +364,11 @@ if (!function_exists('cache')) {
      * @param string    $tag 缓存标签
      * @return mixed
      */
-    function redis_set($name,$value,$expire = null){
+    function redis_matching_set($name,$value,$expire = null){
         $cache = Cache::connect(['type'=>'Redis']);
         return $cache->set('mt_matching_uid_'.$name, $value, $expire);
     }
-    function redis_get($name){
+    function redis_matching_get($name){
         $cache = Cache::connect(['type'=>'Redis']);
         return $cache->get('mt_matching_uid_'.$name);
     }