Browse Source

语言包

lizhen_gitee 1 year ago
parent
commit
3a76fcb5b3
2 changed files with 53 additions and 1 deletions
  1. 12 0
      application/api/lang/en/coach/Lesson.php
  2. 41 1
      application/common/controller/Apic.php

+ 12 - 0
application/api/lang/en/coach/Lesson.php

@@ -0,0 +1,12 @@
+<?php
+
+return [
+    '此课程已经点过名了'                => 'This course has already been named',
+    '此课程不能提交点名'                => 'This course cannot be submitted for roll call',
+    '点名数据错误'                    => 'Roll call data error',
+    '无人报名,请取消课程'                => 'No one has reservation, please cancel the course',
+    '点名数据错误'                    => 'Roll call data error',
+    '点名失败'                     => 'Roll call failed',
+    '点名已完成'                    => 'Roll call completed',
+    '你好'                    => 'Hello',
+];

+ 41 - 1
application/common/controller/Apic.php

@@ -254,7 +254,7 @@ class Apic
     {
         $result = [
             'code' => $code,
-            'msg'  => $msg,
+            'msg'  => __($msg),
             'time' => Request::instance()->server('REQUEST_TIME'),
             'data' => $data,
         ];
@@ -417,5 +417,45 @@ class Apic
         }
     }
 
+    /**
+     * 接口请求限制
+     * @param int $apiLimit
+     * @param int $apiLimitTime
+     * @param string $key
+     * @return bool | true:通过 false:拒绝
+     */
+    public function apiLimit($apiLimit = 1, $apiLimitTime = 1000, $key = '')
+    {
+        $userId = $this->auth->id;
+        $controller = request()->controller();
+        $action = request()->action();
+
+        if (!$key) {
+            $key = strtolower($controller) . '_' . strtolower($action) . '_' . $userId;
+        }
+
+        $redis = new Redis();
+        $redisconfig = config("redis");
+        $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth($redisconfig['redis_pwd']);
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select($redisconfig['redis_selectdb']);
+        }
+        $check = $redis->exists($key);
+        if ($check) {
+            $redis->incr($key);
+            $count = $redis->get($key);
+            if ($count > $apiLimit) {
+                return false;
+            }
+        } else {
+            $redis->incr($key);
+            $redis->pExpire($key, $apiLimitTime);
+        }
+        return true;
+    }
+
 
 }