Browse Source

建立保存到草稿箱的接口

15313670163 3 days ago
parent
commit
ffa4457b74

+ 39 - 7
app/JsonRpc/PublicRpcService.php

@@ -26,6 +26,9 @@ use App\Model\Sector;
 use App\Model\Component;
 use App\Model\Link;
 use App\Model\FooterCategory;
+
+use function Hyperf\Support\retry;
+
 #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class PublicRpcService implements PublicRpcServiceInterface
 {
@@ -1184,7 +1187,8 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
             }
         }
-        // $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
+        $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
+        // return Result::success($template_id);
         if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
             $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
         }else{
@@ -1197,20 +1201,18 @@ class PublicRpcService implements PublicRpcServiceInterface
         $template_page_str = json_encode($template_page);
         if (isset($query)) {
             $result['template'] = $query->where($where)
-                ->whereRaw("JSON_CONTAINS(template.page, ?)", [$template_page_str])
+                ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
                 ->paginate($data['page_size'], ['*'], 'page', $data['page']);
         } else {
             $result['template'] = Template::where($where)
-                ->whereRaw("JSON_CONTAINS(template.page, ?)", [$template_page_str])
+                ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
                 ->paginate($data['page_size'], ['*'], 'page', $data['page']);
         }
-        if (!empty($result['template']['data'])) {
-            return Result::success($result);
-        } else {
+        if (empty($result['template']['data'])) {
             $result['template'] = Template::orderBy('updated_at','desc')
                 ->paginate($data['page_size'], ['*'], 'page', $data['page']);
-            return Result::success($result);
         }
+        return Result::success($result);
     }
     /**
      * 自助建站---流程---4.选择皮肤
@@ -1239,4 +1241,34 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error('选择皮肤失败!');
         }
     }
+    /**
+     * 自助建站---流程---5.选择组件
+     * @param array $data
+     * @return array
+     */
+    public function saveWebsiteTemplate(array $data): array
+    {
+        $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
+        if(empty($website_template_info)){
+            return Result::error('请先填写网站基础信息!');
+        }
+        // 0:未构建 1:未应用 2:已应用   status
+        if($website_template_info['status'] == 2){
+            return Result::error('网站已应用,不可再次保存!');
+        }
+        if($website_template_info['action_id'] != 2){
+            return Result::error('请完成之前的步骤!');
+        }
+        $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
+        if(empty($template_info)){
+            $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'],'template_data' => $data['template_data']]);
+        }else{
+            $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
+        }
+        if(empty($template)){
+            return Result::error('保存失败!');
+        }else{
+            return Result::success($template);
+        }
+    }
 }

+ 1 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -180,5 +180,6 @@ interface PublicRpcServiceInterface
     public function addWebPageType(array $data): array;
 
     public function chooseWebsiteTemplate(array $data): array;
+    public function saveWebsiteTemplate(array $data): array;
     
 }

+ 0 - 1
app/JsonRpc/WebsiteService.php

@@ -648,7 +648,6 @@ class WebsiteService implements WebsiteServiceInterface
              ->select('pid', 'category_id', 'alias','aLIas_pinyin');
          $pid = $pidQuery->pluck('pid');
          $pid = array_values(array_unique($pid->toArray()));
- 
          // 构建查询语句
          $query = WebsiteCategory::where($website_id)
              ->where('pid', $data['pid'])