Browse Source

避免重复提交

shish 4 years ago
parent
commit
1ff453120a

+ 3 - 0
app-ghs/controllers/ApplyController.php

@@ -67,6 +67,9 @@ class ApplyController extends BaseController
     //申请试用,花店添加新客户 ssh 2021.1.8
     public function actionRegister()
     {
+        //避免重复提交
+        util::checkRepeatCommit($this->adminId);
+
         $post = Yii::$app->request->post();
         $post['adminId'] = $this->adminId;
         $admin = $this->admin->attributes;

+ 3 - 0
app-hd/controllers/ApplyController.php

@@ -69,6 +69,9 @@ class ApplyController extends BaseController
     //申请试用 ssh 2020.1.11
     public function actionRegister()
     {
+        //避免重复提交
+        util::checkRepeatCommit($this->adminId);
+
         $post = Yii::$app->request->post();
         $post['adminId'] = $this->adminId;
         $admin = $this->admin->attributes;

+ 13 - 0
common/components/util.php

@@ -392,4 +392,17 @@ class util
         return $redis->del($key);
     }
 
+    //检查是否有重复提交 shish 20211018
+    public static function checkRepeatCommit($adminId)
+    {
+        $ctl = Yii::$app->controller->id;
+        $action = Yii::$app->controller->action->id;
+        $cacheKey = "checkRepeatCommit_" . $ctl . "_" . $action . "_" . $adminId;
+        $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        if (!empty($has)) {
+            util::fail('请稍候...');
+        }
+        Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 3, 'has']);
+    }
+
 }