Explorar o código

自助建站管理流程-获取皮肤 修改此接口

15313670163 hai 5 días
pai
achega
53f4038d51
Modificáronse 1 ficheiros con 7 adicións e 10 borrados
  1. 7 10
      app/JsonRpc/PublicRpcService.php

+ 7 - 10
app/JsonRpc/PublicRpcService.php

@@ -1327,6 +1327,8 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
                 $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
             }
+        }else{
+            $query = Template::where($where);
         }
         $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
         // return Result::success($template_id);
@@ -1340,16 +1342,11 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
         $template_page_str = json_encode($template_page);
-        if (isset($query)) {
-            $result['template'] = $query->where($where)
-                ->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_type, ?)", [$template_page_str])
-                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
-        }
-        if (empty($result['template']['data'])) {
+        $result['template'] = $query->where($where)
+            ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
+            ->orderBy('updated_at','desc')
+            ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        if (empty($result['template'])) {
             $result['template'] = Template::orderBy('updated_at','desc')
                 ->paginate($data['page_size'], ['*'], 'page', $data['page']);
         }