소스 검색

匹配设置开关与次数

lizhen_gitee 1 년 전
부모
커밋
ca1f68a92e
2개의 변경된 파일33개의 추가작업 그리고 4개의 파일을 삭제
  1. 31 4
      application/api/controller/Index.php
  2. 2 0
      application/extra/site.php

+ 31 - 4
application/api/controller/Index.php

@@ -219,13 +219,28 @@ class Index extends Api
     //做防止重复处理,参照荔枝
     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 = 'u_'.$user_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($user_times >= $times_limit){
+            $this->error('今日已经超过匹配次数上限');
+        }
+
         //where
         $where = [
             'user.id' => ['neq',$this->auth->id],
@@ -261,6 +276,10 @@ class Index extends Api
                 $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);
         }
@@ -287,14 +306,22 @@ class Index extends Api
     public function test(){
         //缓存,防重复
         $user_id = $this->auth->id;
-        $user_id_redis = 'u_'.$user_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 = 'u_'.$user_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);
     }
 
 

+ 2 - 0
application/extra/site.php

@@ -28,6 +28,7 @@ return array (
     'takecash' => '提现配置',
     'androidversion' => '安卓版本配置',
     'iosversion' => 'ios版本配置',
+    'indexpipei' => '匹配设置',
   ),
   'mail_type' => '1',
   'mail_smtp_host' => 'smtp.qq.com',
@@ -80,4 +81,5 @@ return array (
   'iso_desc' => '这次更新了很多内容',
   'iso_versioncode' => '1',
   'ios_pay_sandbox' => '0',
+  'pipei_oneday_vipuser_times' => '10',
 );