瀏覽代碼

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/public_producer

rkljw 3 天之前
父節點
當前提交
d74c067e20
共有 3 個文件被更改,包括 152 次插入24 次删除
  1. 143 21
      app/JsonRpc/PublicRpcService.php
  2. 6 0
      app/JsonRpc/PublicRpcServiceInterface.php
  3. 3 3
      app/JsonRpc/WebsiteService.php

+ 143 - 21
app/JsonRpc/PublicRpcService.php

@@ -24,7 +24,8 @@ use App\Model\WebsiteTemplate;
 use App\Model\WebsiteTemplateInfo;
 use App\Model\Sector;
 use App\Model\Component;
-
+use App\Model\Link;
+use App\Model\FooterCategory;
 #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class PublicRpcService implements PublicRpcServiceInterface
 {
@@ -805,11 +806,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->select('template.*', 'template_class.name as template_class_name')
             ->orderBy('template.id', 'desc')
             ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
-        // 使用 items 方法获取分页数据
-        // $items = collect($result->items());
-        // $items->each(function ($item) {
-        //     $item['template_content'] = json_decode($item['template_content'], true);
-        // });
+        if(empty($result)){
+            return Result::error("暂无皮肤", 0);
+        }
         return Result::success($result);
     }
     public function getTemplateInfo(array $data): array
@@ -818,6 +817,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
             ->select('template.*', 'template_class.name as template_class_name')
             ->first();
+        if(empty($result)){
+            return Result::error("暂无皮肤", 0);
+        }
         return Result::success($result);
     }
     /**
@@ -836,6 +838,8 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
         }
         $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
+        $page_type = json_decode($data['page_type'], true);
+        $data['page_type'] = json_encode(array_values(array_unique($page_type)));
         $result = Template::insertGetId($data);
         if(empty($result)){
             return Result::error("创建失败", 0);
@@ -881,6 +885,8 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
         }
         $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
+        $page_type = json_decode($data['page_type'], true);
+        $data['page_type'] = json_encode(array_values(array_unique($page_type)));
         $result = Template::where('id', $data['id'])->update($data);
         var_dump($result, '-------------------update');
         if (!$result) {
@@ -1084,37 +1090,153 @@ class PublicRpcService implements PublicRpcServiceInterface
         $result = Component::where('id', $data['id'])->update($data);
         return Result::success($result);
     }
-    public function getWebsiteTemplateList(array $data): array
+    
+    public function getWebsiteTemplateInfo(array $data)
     {
         $where = [];
-
+        if (isset($data['id'])) {
+            $where[] = ['id', '=', $data['id']];
+        }
         $result = WebsiteTemplateInfo::where($where)
             ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
+            ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
             ->select('website_template_info.*', 'website.website_name')
-            ->orderBy('website_template_info.id', 'desc')
-            ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+            ->get();
         if ($result) {
             return Result::success($result);
         } else {
             return Result::error('暂无数据');
         }
     }
-    public function getWebsiteTemplateInfo(array $data)
+    /**
+     * 自助建站----1.获取页面类型回显
+     * @param array $data
+     * @return array
+     */
+    public function getWebPageType(array $data): array
     {
-        $where = [];
-        if (isset($data['id'])) {
-            $where[] = ['id', '=', $data['id']];
+        // 1:图片 2:文字 3:底部
+        $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
+        if(empty($friend_link->toArray())){
+            return Result::error('暂无友情链接数据!');
         }
-        $result = WebsiteTemplateInfo::where($where)
-            ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
-            ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
-            ->select('website_template_info.*', 'website.website_name')
-            ->get();
+        $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
+        if(empty($footer_category->toArray())){
+            return Result::error('暂无底部导航数据!');
+        }
+        $result = [
+            'friend_link' => $friend_link,
+            'footer_category' => $footer_category,
+        ];
+        return Result::success($result);
+    }
+    /**
+     * 自助建站----2.添加页面类型
+     * @param array $data
+     * @return array
+     */
+    public function addWebPageType(array $data): array
+    {
+        // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
+        if($data['is_search'] == 1){
+            $page_type = json_encode([1,2,3,4,5,6,7]);
+        }else{
+            $page_type = json_encode([1,2,3,4,6,7]);
+        }
+        // 0:未构建;1:已填写基础信息;2:已选择模板;    action_id
+        $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1]);
         if ($result) {
             return Result::success($result);
         } else {
-            return Result::error('暂无数据');
+            return Result::error('添加失败');
+        }
+    }
+    /**
+     * 自助建站---流程---3.选择皮肤列表
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteTemplateList(array $data): array
+    {
+        $where = [];
+        if(isset($data['template_class_id']) && $data['template_class_id']){
+            $where[] = ['template_class_id', '=', $data['template_class_id']];
+        }
+        // 0:未构建 1:未应用 2:已应用   status
+        $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
+        if(empty($templste_info)){
+            return Result::error('请先填写网站基础信息!');
+        }
+        if($templste_info['status'] == 2){
+            return Result::error('网站已应用,不可再次修改!');
+        }
+        
+        if(isset($data['keyword']) && !empty($data['keyword'])){
+            if (is_array($data['keyword'])) {
+                // 拼接多个模糊查询条件
+                $query = Template::query();
+                foreach ($data['keyword'] as $kw) {
+                    $escapedKw = addcslashes($kw, '%_'); // 转义通配符
+                    $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
+                }
+            } else {
+                $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
+                $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
+            }
+        }
+        // $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
+        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{
+            $template_page = [];
+        }
+        if(!empty($template_id['template_id'])){
+            $result['template_id'] = $templste_info['template_id'];
+        }
+        // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
+        $template_page_str = json_encode($template_page);
+        if (isset($query)) {
+            $result['template'] = $query->where($where)
+                ->whereRaw("JSON_CONTAINS(template.page, ?)", [$template_page_str])
+                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        } else {
+            $result['template'] = Template::where($where)
+                ->whereRaw("JSON_CONTAINS(template.page, ?)", [$template_page_str])
+                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        }
+        if (!empty($result['template']['data'])) {
+            return Result::success($result);
+        } else {
+            $result['template'] = Template::orderBy('updated_at','desc')
+                ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+            return Result::success($result);
+        }
+    }
+    /**
+     * 自助建站---流程---4.选择皮肤
+     * @param array $data
+     * @return array
+     */
+    public function chooseWebsiteTemplate(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('网站已应用,不可再次修改!');
+        }
+        $template = Template::where('id', $data['template_id'])->first();
+        if(empty($template)){
+            return Result::error('未查询到皮肤!');
+        }
+        // 0:未构建;1:已填写基础信息;2:已选择模板;    action_id
+        $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
+        if ($web_template) {
+            return Result::success($web_template);
+        } else {
+            return Result::error('选择皮肤失败!');
         }
     }
-
 }

+ 6 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -175,4 +175,10 @@ interface PublicRpcServiceInterface
     public function getIpInfo(array $data): array;
     public function getWeatherInfo(array $data): array;
     public function getCalendar(array $data): array;
+    // --------------自助建站-----------
+    public function getWebPageType(array $data): array;
+    public function addWebPageType(array $data): array;
+
+    public function chooseWebsiteTemplate(array $data): array;
+    
 }

+ 3 - 3
app/JsonRpc/WebsiteService.php

@@ -1704,6 +1704,7 @@ class WebsiteService implements WebsiteServiceInterface
             // 删除重复元素并重新索引数组
             $data['page_type'] = array_unique($data['page_type']);
             $data['page_type'] = array_values($data['page_type']);
+            // 1:首页 2:分类页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页
             if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
                 // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
                 $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
@@ -1712,7 +1713,6 @@ class WebsiteService implements WebsiteServiceInterface
                     $data['page_type'] = json_encode($data['page_type']) ?? '';
                     // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
                     $data['action_id'] = 1;
-
                     try {
                         $result = WebsiteTemplateInfo::insertGetId($data);
                     } catch (\Exception $e) {
@@ -1740,8 +1740,8 @@ class WebsiteService implements WebsiteServiceInterface
     }
     /**
      * 获取网站基础信息
-     *
      * @return array
+     * 
      */
     public function getWebsiteTemplateintel(array $data): array
     {
@@ -1966,7 +1966,7 @@ class WebsiteService implements WebsiteServiceInterface
         // 获取指定网站下的基础信息和模板及风格信息
         $result = WebsiteTemplateInfo::where([
             ['website_template_info.website_id', $data['website_id']],
-            ['template_id', '!=', null],
+            ['website_template_info.template_id', '!=', null],
         ])
             ->leftJoin('template', 'template.id', 'website_template_info.template_id')
             ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')