|
|
@@ -417,6 +417,30 @@ class util
|
|
|
Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, 'has']);
|
|
|
}
|
|
|
|
|
|
+ //每天限制请求次数
|
|
|
+ public static function perDayCommitTimeLimit($uniqueId, $num = 0)
|
|
|
+ {
|
|
|
+ if ($num == 0) {
|
|
|
+ //0表示不限制请求次数
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $second = 86400;
|
|
|
+ $ctl = Yii::$app->controller->id;
|
|
|
+ $action = Yii::$app->controller->action->id;
|
|
|
+ $cacheKey = "perDayCommitTimeLimit_" . $ctl . "_" . $action . "_" . $uniqueId;
|
|
|
+ $hasNum = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
|
|
|
+ if (!empty($hasNum) && $hasNum > 0) {
|
|
|
+ if ($hasNum > $num) {
|
|
|
+ util::fail("已拉取{$num}次,请明天再试");
|
|
|
+ }
|
|
|
+ $newNum = bcadd($hasNum, 1);
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, $newNum]);
|
|
|
+ } else {
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$cacheKey, $second, 1]);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用 mainId 验证操作权限
|
|
|
* @param array $arr 模型数据数组
|