Jelajahi Sumber

清理缓存

bianjunhui 11 jam lalu
induk
melakukan
a99f074ec3

+ 102 - 0
application/admin/controller/functional/Deal.php

@@ -62,6 +62,108 @@ class Deal extends Backend
         $result = ['total' => $list->total(), 'rows' => $list->items()];
         return json($result);
     }
+
+
+    public function deletecache()
+    {
+        $ra_id=input('ids');
+        if(empty($ra_id)){
+            $ra_id=session('xids');
+        }else{
+            session('xids',$ra_id);
+        }
+
+        $model = new \app\admin\model\functional\Fal;
+        $row = $model->get($ra_id);
+        $data['name']=$row->name;
+        $website=$row->website;
+        $url ='';
+        if($website=='alipearlhair'){
+            $url ='https://www.alipearlhair.com/app-api/cache/deleteImageCache';
+        }
+        if($website=='wigginshair'){
+            $url ='https://www.wigginshair.com/app-api/cache/deleteImageCache';
+        }
+        if(empty($url)){
+            $this->error(__('网站出错'));
+        }
+        self::request($url, $data, 'POST');
+        $this->success();
+    }
+    public static function request($url, $params = [], $method = 'GET', $headers = [], $options = [])
+    {
+        $ch = curl_init();
+
+        // 设置请求方法
+        $method = strtoupper($method);
+
+        // 设置参数
+        if ($method == 'GET' && !empty($params)) {
+            $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($params);
+        }
+
+        // 设置 URL
+        curl_setopt($ch, CURLOPT_URL, $url);
+
+        // 设置请求方法
+        if ($method == 'POST') {
+            curl_setopt($ch, CURLOPT_POST, true);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
+        } elseif ($method == 'PUT' || $method == 'DELETE') {
+            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
+        }
+
+        // 设置请求头
+        if (!empty($headers)) {
+            $headerArr = [];
+            foreach ($headers as $key => $value) {
+                $headerArr[] = $key . ': ' . $value;
+            }
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
+        }
+
+        // 默认选项
+        $defaultOptions = [
+            CURLOPT_RETURNTRANSFER => true,      // 返回结果而不输出
+            CURLOPT_HEADER => false,             // 不包含响应头
+            CURLOPT_FOLLOWLOCATION => true,      // 跟随重定向
+            CURLOPT_MAXREDIRS => 10,             // 最大重定向次数
+            CURLOPT_TIMEOUT => 30,               // 超时时间(秒)
+            CURLOPT_CONNECTTIMEOUT => 10,        // 连接超时时间
+            CURLOPT_SSL_VERIFYPEER => false,     // 不验证 SSL 证书
+            CURLOPT_SSL_VERIFYHOST => false,     // 不验证主机名
+            CURLOPT_USERAGENT => 'FastAdmin/' . config('fastadmin.version'), // User-Agent
+        ];
+
+        // 合并选项
+        foreach ($defaultOptions as $key => $value) {
+            if (!isset($options[$key])) {
+                $options[$key] = $value;
+            }
+        }
+
+        // 设置 cURL 选项
+        foreach ($options as $key => $value) {
+            curl_setopt($ch, $key, $value);
+        }
+
+        // 执行请求
+        $response = curl_exec($ch);
+        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+        $error = curl_error($ch);
+        $errno = curl_errno($ch);
+
+        curl_close($ch);
+
+        return [
+            'success' => $errno === 0 && $response !== false,
+            'http_code' => $httpCode,
+            'response' => $response,
+            'error' => $error,
+            'errno' => $errno
+        ];
+    }
     /**
      * 添加
      *

+ 7 - 1
public/assets/js/backend/functional/fal.js

@@ -41,7 +41,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     classname: 'btn btn-xs btn-success btn-dialog',
                                     icon: 'fa fa-github-alt',
                                     url: 'functional/deal/index',
-                                },
+                                },{
+                                    name: 'detail',
+                                    text: __('清理缓存'),
+                                    icon: 'fa fa-list',
+                                    classname: 'btn btn-info btn-xs btn-detail btn-ajax',
+                                    url: 'functional/deal/deletecache'
+                                }
                             ], formatter: Table.api.formatter.operate}
                     ]
                 ]