LiuJ 5 months ago
parent
commit
859d76c7e5
1 changed files with 38 additions and 15 deletions
  1. 38 15
      app/JsonRpc/ClientService.php

+ 38 - 15
app/JsonRpc/ClientService.php

@@ -16,6 +16,7 @@ use Hyperf\Redis\Redis;
 use Hyperf\Di\Annotation\Inject;
 use function Hyperf\Support\env;
 use Symfony\Component\Filesystem\Filesystem;
+use Hyperf\Paginator\Paginator;
 
 #[RpcService(name: "ClientService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 
@@ -831,7 +832,8 @@ class ClientService implements ClientServiceInterface
             ->where($where)
             ->leftJoin('website', 'website.id', '=', 'website_template.website_id')
             ->select('website_template.*', 'website.website_name as website_name', 'website.website_url as website_url')
-            ->get();
+            ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
+
         if ($result) {
             return Result::success($result);
         } else {
@@ -840,7 +842,9 @@ class ClientService implements ClientServiceInterface
     }
     public function updateWebConfig($data)
     {
-        var_dump($data, 'data');
+        var_dump($data, 'data1');
+        // return Result::success($data);
+
 
         $where = [];
 
@@ -850,24 +854,29 @@ class ClientService implements ClientServiceInterface
         $result = WebsiteTemplate::where([])
             ->where($where)
             ->leftJoin('website', 'website.id', '=', 'website_template.website_id')
-            ->select('website_template.id', 'website_template.port', 'website.website_name as website_name', 'website.website_url as website_url')
+            ->select('website_template.id', 'website_template.port', 'website.website_name as website_name', 'website.website_url as website_url', 'website_template.siteId')
+
             ->first()->toArray();
-        var_dump($result);
+        var_dump($result, 'result');
+
         $domain = json_decode($result['website_url'], true);
         $domainlist = $domain;
-
+        var_dump(empty($result['port']), 'port');
         $domain = $domain[3];
-        if (empty($domain)) {
-            return Result::error(500, '域名不存在');
+        if ($domain == null || empty($domain) || !isset($domain)) {
+            return Result::error('域名不存在');
         }
         $port = $result['port'];
-        if (empty($port)) {
-            return Result::error(500, '端口不存在');
+        if ($port == null || empty($port) || !isset($port)) {
+            var_dump($port, 'youp0------port');
+            return Result::error('端口不存在');
         }
         $postData = [
             'domain' => $domain,
             'port' => $port
         ];
+        var_dump(empty($result['siteId']), 'siteId---');
+
         if (empty($result['siteId'])) {
             //实例化对象
             $api = new bt_api();
@@ -906,13 +915,22 @@ class ClientService implements ClientServiceInterface
             "gitStatus": false
              }
             */
-            if ($r_data['siteStatus'] == false) {
-                return Result::error('宝塔添加失败');
-            } elseif ($r_data['siteStatus'] == true) {
+            var_dump($r_data, '----------1--r_data--------');
+            if (isset($r_data['status']) && $r_data['status'] == false) {
+
+                return Result::error('宝塔添加失败' . $r_data['msg']);
+            }
+            if (isset($r_data['siteStatus']) && $r_data['siteStatus'] == true) {
+
                 //记录siteId
                 $siteId = $r_data['siteId'];
                 //更新网站模板的siteId     WebsiteTemplate  
-                WebsiteTemplate::update(['siteId' => $siteId, 'dir' => '/www2/www/wwwroot/' . $domain], ['id' => $data['website_id']]);
+                WebsiteTemplate::where('website_id', $data['website_id'])
+                    ->update([
+                        'siteId' => $siteId,
+                        'dir' => '/www2/www/wwwroot/' . $domain,
+                        'status' => 2
+                    ]);
             }
             // return Result::success($r_data);
         }
@@ -930,13 +948,18 @@ class ClientService implements ClientServiceInterface
             // 获取响应内容
             $responseBody = $response->getBody()->getContents();
             $responseData = json_decode($responseBody, true);
+            var_dump($responseData, '脚本返回数据------------------------');
 
             // 检查响应是否为有效的JSON
             if (json_last_error() === JSON_ERROR_NONE) {
                 // 如果远程服务器返回成功结果
-                if (isset($responseData['success']) && $responseData['success']) {
+                if (isset($responseData['code']) && $responseData['code'] === 1) {
                     return Result::success([
-                        'message' => '远程服务器处理成功',
+                        'message' => '远程服务器处理成功' . $responseData['message'],
+                        'output' => $responseData['output'],
+                        'file' => $responseData['file'],
+                        'code' => $responseData['code'],
+                        'exec' => $responseData['exec'],
                         'domain' => $domain,
                         'port' => $port,
                         'remote_response' => $responseData