Przeglądaj źródła

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

rkljw 1 dzień temu
rodzic
commit
9ebc0e53e8

+ 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;
     
 }

+ 98 - 53
app/JsonRpc/WebsiteService.php

@@ -47,7 +47,8 @@ use Overtrue\Pinyin\Pinyin;
 use App\Tools\buildTree;
 use App\Model\WhiteRouter;
 use App\Model\Size;
-
+use App\Tools\PinyinHelper;
+use Hyperf\HttpServer\Annotation\AutoController;
 #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebsiteService implements WebsiteServiceInterface
 {
@@ -92,41 +93,47 @@ class WebsiteService implements WebsiteServiceInterface
         ];
         return Result::success($data);
     }
-
+    
     /**
      * @param array $data
-     * @return array
      */
     public function createWebsite(array $data): array
     {
         var_dump("网站数据:", $data);
+        // $wzbs = $this->getWebsitetAdkey($data);
+        // return Result::success($wzbs);
+        $web = Website::where('ad_key', $data['ad_key'])->first();
+        if (!empty($web)) {
+            return Result::error("网站名称简写重复,请填写", 0);
+        }
         $insertData = [
             'website_name' => $data['website_name'],
             'logo' => $data['logo'] ?? '',
             'website_url' => $data['website_url'] ?? '',
-            //           'city_id'=>$data['city_id']??0,
+            //'city_id'=>$data['city_id']??0,
             'website_column_id' => $data['website_column_id'],
             'title' => $data['title'] ?? '',
             'keywords' => $data['keywords'] ?? '',
             'description' => $data['description'] ?? '',
             'status' => $data['status'] ?? 1,
             'website_column_arr_id' => $data['website_column_arr_id'],
-            //           'city_arr_id'=>$data['city_arr_id']??[0],
+            //'city_arr_id'=>$data['city_arr_id']??[0],
             'template_id' => $data['template_id'] ?? 0,
             'suffix' => $data['suffix'] ?? "",
-        ];
+           'ad_key' => $data['ad_key']?? "",
+        ];        
         $result = Website::insertGetId($insertData);
         if (empty($result)) {
-            return Result::error("创建失败", 0);
+            return Result::error("创建网站失败", 0);
         } else {
             return Result::success(["id" => $result]);
         }
+       
     }
 
     /**
-     * @param int $id
+     * 修改网站头部基础信息
      * @param array $data
-     * @return array
      */
     public function updateWebsite(int $id, array $data): array
     {
@@ -144,17 +151,28 @@ class WebsiteService implements WebsiteServiceInterface
             //           'city_arr_id'=>$data['city_arr_id']??[0],
             'template_id' => $data['template_id'] ?? 0,
             'suffix' => $data['suffix'] ?? "",
+            'ad_key' => $data['ad_key']?? "",
         ];
-        var_dump("=========:", $insertData);
-        $result = Website::where('id', $id)->update($insertData);
-        var_dump("更新站点", $result);
+        $web_templsate = WebsiteTemplateInfo::where('website_id', $data['id'])->first();
+        // `status` tinyint(1) DEFAULT '0' COMMENT '0:未构建 1:未应用 2:已应用',
+        if (!empty($web_templsate) && $web_templsate['status'] == 2) {
+            return Result::error("此网站已应用,不可修改基本信息", 0);
+        }
+        $web = Website::where(function ($query) use ($data) {
+            $query->where('id','!=', $data['id'])
+                ->where('ad_key', $data['ad_key']);
+        })->first();
+        if (!empty($web)) {
+            return Result::error("网站名称简写重复,请填写", 0);
+        }
+        $result = Website::where('id', $data['id'])->update($insertData);
+        // var_dump("更新站点", $result);
         if (empty($result)) {
-            return Result::error("更新失败", 0);
+            return Result::error("更新网站失败", 0);
         } else {
-            return Result::success();
+            return Result::success("更新成功");
         }
     }
-
     /**
      * @param int $id
      * @return array
@@ -615,44 +633,43 @@ class WebsiteService implements WebsiteServiceInterface
      * @return array
      */
 
-    public function getWebsiteModelCategory(array $data): array
-    {
-        // return Result::success($data);
-        $website_id = [
-            'website_id' => $data['website_id'],
-        ];
-        // 初始化 $pid 数组
-        // $pid = [];
-        // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
-        $pidQuery = WebsiteCategory::where($website_id)
-            ->where('pid', '!=', 0)
-            ->orderBy('sort')
-            ->select('pid', 'category_id', 'alias');
-        $pid = $pidQuery->pluck('pid');
-        $pid = array_values(array_unique($pid->toArray()));
-
-        // 构建查询语句
-        $query = WebsiteCategory::where($website_id)
-            ->where('pid', $data['pid'])
-            ->offset($data['placeid'])
-            ->limit($data['num'])
-            ->orderBy('sort');
-        // 如果 $pid 数组不为空,添加 CASE WHEN 条件
-        if (!empty($pid)) {
-            $placeholders = implode(',', array_fill(0, count($pid), '?'));
-            $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
-        } else {
-            // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
-            $query->select('website_category.*', DB::raw('0 as children_count'));
-        }
-
-        // 执行查询
-        $placeid = $data['placeid'] - 1;
-        $result = $query->offset($placeid)->limit($data['num'])->get();
-
-        if (!empty($result)) {
-            $pidResults = $pidQuery->get();
-            if (isset($data['type']) && $data['type'] == 1) {
+     public function getWebsiteModelCategory(array $data): array
+     {
+         // return Result::success($data);
+         $website_id = [
+             'website_id' => $data['website_id'],
+         ];
+         // 初始化 $pid 数组
+         // $pid = [];
+         // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
+         $pidQuery = WebsiteCategory::where($website_id)
+             ->where('pid', '!=', 0)
+             ->orderBy('sort')
+             ->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'])
+             ->offset($data['placeid'])
+             ->limit($data['num'])
+             ->orderBy('sort');
+         // 如果 $pid 数组不为空,添加 CASE WHEN 条件
+         if (!empty($pid)) {
+             $placeholders = implode(',', array_fill(0, count($pid), '?'));
+             $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
+         } else {
+             // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
+             $query->select('website_category.*', DB::raw('0 as children_count'));
+         }
+ 
+         // 执行查询
+         $placeid = $data['placeid'] - 1;
+         $result = $query->offset($placeid)->limit($data['num'])->get();
+ 
+         if (!empty($result)) {
+             $pidResults = $pidQuery->get();
+             if(isset($data['type']) && $data['type'] == 1){
                 $result = $result->map(function ($item) use ($pidResults) {
                     $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
                         if (!empty($child)) {
@@ -670,6 +687,7 @@ class WebsiteService implements WebsiteServiceInterface
                         $pidResult = $pidMap->get($record->category_id);
                         $record->chilid_id = $pidResult->category_id;
                         $record->chilid_alias = $pidResult->alias;
+                        // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
                     }
                 });
             }
@@ -2729,6 +2747,33 @@ class WebsiteService implements WebsiteServiceInterface
             return Result::success($result);
         }
     }
+   /**
+     * 获取网站名称缩写
+     * @param array $data
+     */
+    public function getWebsiteAdkey(array $data): array
+    {
+       
+        $result = PinyinHelper::getFirstLetter($data['website_name']);
+        if (empty($result)) {
+            return Result::error("没有数据", 0);
+        } else {
+            return Result::success($result);
+        }
+    }
+    /**
+     * 静态资源管理-修改图片别名
+     * @param array $data
+     */
+    public function upStaticResource(array $data): array
+    {
+        $result = WebsiteImg::where('id', $data['id'])->update(['img_alias' => $data['img_alias']]);
+        if (empty($result)) {
+            return Result::error("修改失败", 0);
+        }
+        return Result::success($result);
+
+    }
     // --自助建站-----------20250522fr----------------------end
 
     /**

+ 1 - 0
app/JsonRpc/WebsiteServiceInterface.php

@@ -159,6 +159,7 @@ interface WebsiteServiceInterface
     public function delSize(array $data): array;
     public function upSize(array $data): array;
     public function getSizeInfo(array $data): array;
+    public function getWebsiteAdkey(array $data): array;
 
     /**
      * @param array $data

+ 15 - 0
app/Tools/PinyinHelper.php

@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Tools;
+
+use Overtrue\Pinyin\Pinyin;
+
+class PinyinHelper
+{
+    public static function getFirstLetter(string $string): string
+    {
+        $pinyin = new Pinyin();
+        return strtolower(implode('', $pinyin->abbr($string)->toArray()));
+    }
+}

+ 1 - 1
composer.json

@@ -40,7 +40,7 @@
         "hyperf/service-governance-nacos": "^3.1",
         "hyperf/utils": "^3.1",
         "overtrue/chinese-calendar": "^1.0",
-        "overtrue/pinyin": "*"
+        "overtrue/pinyin": "^5.3"
     },
     "require-dev": {
         "friendsofphp/php-cs-fixer": "^3.0",

+ 3 - 3
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "79c988defdd709048653f0b4f9c7e5c1",
+    "content-hash": "7157c53821ddc81823fdef0acbd9d26c",
     "packages": [
         {
             "name": "aws/aws-crt-php",
@@ -11627,12 +11627,12 @@
     ],
     "aliases": [],
     "minimum-stability": "dev",
-    "stability-flags": {},
+    "stability-flags": [],
     "prefer-stable": true,
     "prefer-lowest": false,
     "platform": {
         "php": ">=8.1"
     },
-    "platform-dev": {},
+    "platform-dev": [],
     "plugin-api-version": "2.6.0"
 }