wesmiler 2 سال پیش
والد
کامیت
bb72e64049
2فایلهای تغییر یافته به همراه11 افزوده شده و 3 حذف شده
  1. 9 1
      app/Services/Api/MemberSettingService.php
  2. 2 2
      app/Services/Api/MessageService.php

+ 9 - 1
app/Services/Api/MemberSettingService.php

@@ -91,6 +91,12 @@ class MemberSettingService extends BaseService
             return false;
         }
 
+        // 频繁操作
+        if(RedisService::get("caches:m_setting:lock_{$userId}_{$type}")){
+            $this->error = 1034;
+            return false;
+        }
+
         // 参数值验证
         if(!in_array($value, [1,2])){
             $this->error =1022;
@@ -105,6 +111,7 @@ class MemberSettingService extends BaseService
 
         // 更新设置
         $data[$type] = $value;
+        RedisService::set("caches:m_setting:lock_{$userId}_{$type}", rand(2,3));
         if($id = $this->model->where(['user_id'=> $userId])->value('id')){
             $id = $this->model->where(['id'=> $id])->update($data);
         }else{
@@ -112,7 +119,8 @@ class MemberSettingService extends BaseService
         }
 
         RedisService::clear("caches:m_setting:{$userId}_{$type}");
-        RedisService::clear("caches:messages:topList_{$userId}");
+        RedisService::clear("caches:message:topList_{$userId}");
+        RedisService::clear("caches:m_setting:lock_{$userId}_{$type}");
         return $id;
     }
 

+ 2 - 2
app/Services/Api/MessageService.php

@@ -138,7 +138,7 @@ class MessageService extends BaseService
      */
     public function getGroupList($userId)
     {
-        $cachekey = "caches:messages:topList_{$userId}";
+        $cachekey = "caches:message:topList_{$userId}";
         $datas = RedisService::get($cachekey);
         if($datas){
             $datas['cache'] = true;
@@ -188,7 +188,7 @@ class MessageService extends BaseService
                 $item['unread'] = intval($unread);
                 $total += intval($unread);
             }
-            RedisService::set($cachekey, ['list'=>$datas,'total'=>$total,'types'=>$types], rand(3,5));
+            RedisService::set($cachekey, ['list'=>$datas,'total'=>$total,'types'=>$types], rand(2,3));
         }
 
         return ['list'=>$datas,'total'=> $total,'types'=>$types];