afa 7 hónapja
szülő
commit
bf411cf69e

+ 6 - 2
application/api/controller/Pledge.php

@@ -8,7 +8,6 @@ use app\common\model\ProductLists;
 use app\common\model\ProductOrder;
 use app\common\model\ProductPledges;
 use Exception;
-use app\api\logic\WelfareLoginc;
 use app\common\model\UserModel;
 use think\Db;
 use app\common\logic\PledgeLogic;
@@ -120,7 +119,12 @@ class Pledge extends Api
       * 收取茶矿
       */
       public function collect(PledgeLogic $pledgeLogic)
-      {
+      {     
+            if($pledgeLogic::getCheckRequestApi('collect', $this->auth->id, 300) == false){
+                  $this->error(__("参数有误,无可用产品"));
+            }
+            echo 'ok';
+            die;
             Db::startTrans();
             try {
                   // 质抵押订单 

+ 26 - 2
application/common/logic/PledgeLogic.php

@@ -4,7 +4,7 @@ namespace app\common\logic;
 
 use Exception;
 use think\Env;
-use think\Error;
+use think\Cache;
 use think\Loader ;
 use app\common\model\UserPledge;
 use app\common\model\ProductPledges;
@@ -89,5 +89,29 @@ class PledgeLogic
         $rows->last_time = $time;
         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;
+    }
 }

+ 3 - 3
application/common/model/ProductLists.php

@@ -38,11 +38,11 @@ class ProductLists extends Model
     ];
 
     //获取产品信息
-    public static function  getBySynthesisProduct($product_id, $lan = 'zh')
+    public static function  getBySynthesisProduct(string $product_id, $lan = 'zh')
     {    
         if(empty($product_id)) return [];
-        $list = self::whereIn('id', $product_id)->column('id,thum,'.$lan.'_name as name');
-        return $list;
+        $product_id = explode(',', $product_id);
+        return self::whereIn('id', $product_id)->column('id,thum,'.$lan.'_name as name');
     }
 
     //地区