|
@@ -4,7 +4,7 @@ namespace app\common\logic;
|
|
|
|
|
|
|
|
use Exception;
|
|
use Exception;
|
|
|
use think\Env;
|
|
use think\Env;
|
|
|
-use think\Error;
|
|
|
|
|
|
|
+use think\Cache;
|
|
|
use think\Loader ;
|
|
use think\Loader ;
|
|
|
use app\common\model\UserPledge;
|
|
use app\common\model\UserPledge;
|
|
|
use app\common\model\ProductPledges;
|
|
use app\common\model\ProductPledges;
|
|
@@ -89,5 +89,29 @@ class PledgeLogic
|
|
|
$rows->last_time = $time;
|
|
$rows->last_time = $time;
|
|
|
return $rows->save();
|
|
return $rows->save();
|
|
|
}
|
|
}
|
|
|
- //
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //判断请求限制
|
|
|
|
|
+ public static function getCheckRequestApi(string $key, int $user_id, int $time = 300)
|
|
|
|
|
+ {
|
|
|
|
|
+ $timestampsKey = $key.'_'.$user_id;
|
|
|
|
|
+ $currentTime = time();
|
|
|
|
|
+ $timestamps = Cache::get($timestampsKey, []);
|
|
|
|
|
+ if (count($timestamps) >= 5) {
|
|
|
|
|
+ // 检查最早的记录是否超过5分钟前
|
|
|
|
|
+ $oldestTime = min($timestamps);
|
|
|
|
|
+ if ($currentTime - $oldestTime < $time) { // 5分钟内
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 移除最早的记录并添加新的时间戳
|
|
|
|
|
+ $timestamps = array_diff($timestamps, [$oldestTime]);
|
|
|
|
|
+ $timestamps[] = $currentTime;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 添加新的时间戳
|
|
|
|
|
+ $timestamps[] = $currentTime;
|
|
|
|
|
+ }
|
|
|
|
|
+ Cache::set($timestampsKey, $timestamps, $time); // 设置5分钟过期时间
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|