LiuJ 1 month ago
parent
commit
3324d10d84
2 changed files with 25 additions and 20 deletions
  1. 24 18
      app/JsonRpc/WebsiteService.php
  2. 1 2
      app/Model/WebsiteCategory.php

+ 24 - 18
app/JsonRpc/WebsiteService.php

@@ -1003,6 +1003,9 @@ class WebsiteService implements WebsiteServiceInterface
      */
      */
     public function upWebsiteCategory(array $data): array
     public function upWebsiteCategory(array $data): array
     {
     {
+
+        var_dump("更新数据:", $data);
+        $pinyin = new Pinyin();
         Db::beginTransaction();
         Db::beginTransaction();
         try {
         try {
             if ($data['category_arr_id']) {
             if ($data['category_arr_id']) {
@@ -1032,10 +1035,13 @@ class WebsiteService implements WebsiteServiceInterface
                             'category_id' => end($value),
                             'category_id' => end($value),
                         ];
                         ];
                         // 先复制一份要更新或创建的数据
                         // 先复制一份要更新或创建的数据
+                        $aLIas_pinyin = $pinyin->permalink($info['name'], '');
+                        var_dump($aLIas_pinyin, '别名');
                         $values = [
                         $values = [
                             'website_id' => $data['website_id'],
                             'website_id' => $data['website_id'],
                             'name' => $info['name'] ?? '',
                             'name' => $info['name'] ?? '',
                             'alias' => $info['name'] ?? '',
                             'alias' => $info['name'] ?? '',
+                            'aLIas_pinyin' => $aLIas_pinyin ?? '',
                             'sort' => $info['sort'] ?? 0,
                             'sort' => $info['sort'] ?? 0,
                             'pid' => $info['pid'] ?? 0,
                             'pid' => $info['pid'] ?? 0,
                             'pid_arr' => $info['pid_arr'] ?? json_encode([]),
                             'pid_arr' => $info['pid_arr'] ?? json_encode([]),
@@ -1068,6 +1074,7 @@ class WebsiteService implements WebsiteServiceInterface
                             unset($values['alias']);
                             unset($values['alias']);
                         }
                         }
                         // 执行 updateOrCreate 操作
                         // 执行 updateOrCreate 操作
+                        var_dump("更新数据:",  $values);
                         WebsiteCategory::updateOrCreate($attributes, $values);
                         WebsiteCategory::updateOrCreate($attributes, $values);
                     }
                     }
                 }
                 }
@@ -1168,10 +1175,9 @@ class WebsiteService implements WebsiteServiceInterface
             $pinyin = new Pinyin();
             $pinyin = new Pinyin();
             $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             for ($i = 0; $i < count($result); $i++) {
             for ($i = 0; $i < count($result); $i++) {
-                $randss = substr(str_shuffle($letters), 0, 4);
-                $result[$i]['alias_pinyin'] = $pinyin->permalink($result[$i]['alias'], '') . $randss;
-                var_dump($result[$i]['alias_pinyin'], $i . '----------');
-                WebsiteCategory::where(['id' => $result[$i]['id']])->update(['alias_pinyin' => $result[$i]['alias_pinyin']]);
+                // $randss = substr(str_shuffle($letters), 0, 4);
+                $result[$i]['aLIas_pinyin'] = $pinyin->permalink($result[$i]['alias'], '');
+                WebsiteCategory::where(['id' => $result[$i]['id']])->update(['aLIas_pinyin' => $result[$i]['aLIas_pinyin']]);
             }
             }
             var_dump($result, '--------222----');
             var_dump($result, '--------222----');
             if ($result) {
             if ($result) {
@@ -1187,16 +1193,16 @@ class WebsiteService implements WebsiteServiceInterface
         ];
         ];
         $alias = $data['alias'];
         $alias = $data['alias'];
         $pinyin = new Pinyin();
         $pinyin = new Pinyin();
-        $alias_pinyin = $pinyin->permalink($alias, '');
-        //从WebsiteCategory取出alis ,并转成拼音存放到alias_pinyin
+        $aLIas_pinyin = $pinyin->permalink($alias, '');
+        //从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
         $result = WebsiteCategory::where($where)->first();
         $result = WebsiteCategory::where($where)->first();
         $result = $result->toArray();
         $result = $result->toArray();
         //+四位随机字母
         //+四位随机字母
         $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         // 打乱字符串顺序并截取前四位
         // 打乱字符串顺序并截取前四位
-        $randss = substr(str_shuffle($letters), 0, 4);
-        if (!isset($data['alias_pinyin']) || $data['alias_pinyin'] == '') {
-            $data['alias_pinyin'] = $alias_pinyin . $randss;
+        // $randss = substr(str_shuffle($letters), 0, 4);
+        if (!isset($data['aLIas_pinyin']) || $data['aLIas_pinyin'] == '') {
+            $data['aLIas_pinyin'] = $aLIas_pinyin;
         }
         }
         $result = WebsiteCategory::where($where)->update($data);
         $result = WebsiteCategory::where($where)->update($data);
         if ($result) {
         if ($result) {
@@ -2127,15 +2133,15 @@ class WebsiteService implements WebsiteServiceInterface
         $category['child'] = $child->map(function ($item) use ($parentCategories) {
         $category['child'] = $child->map(function ($item) use ($parentCategories) {
             $alias = $item->alias;
             $alias = $item->alias;
             $category_id = $item->category_id;
             $category_id = $item->category_id;
-            $alias_pinyin = $item->aLIas_pinyin;
+            $aLIas_pinyin = $item->aLIas_pinyin;
             $parent = $parentCategories->get($item->pid);
             $parent = $parentCategories->get($item->pid);
             $parentAlias = $parent ? $parent->aLIas_pinyin : '';
             $parentAlias = $parent ? $parent->aLIas_pinyin : '';
             $result = [
             $result = [
                 'name' => $alias,
                 'name' => $alias,
                 'cid' => $category_id
                 'cid' => $category_id
             ];
             ];
-            if (!empty($alias_pinyin) && !empty($parentAlias)) {
-                $result['path'] = "/{$parentAlias}/{$alias_pinyin}/";
+            if (!empty($aLIas_pinyin) && !empty($parentAlias)) {
+                $result['path'] = "/{$parentAlias}/{$aLIas_pinyin}/";
             }
             }
             return $result;
             return $result;
         })->values()->all();
         })->values()->all();
@@ -2190,16 +2196,16 @@ class WebsiteService implements WebsiteServiceInterface
             return Result::error("暂无该网站", 0);
             return Result::error("暂无该网站", 0);
         }
         }
         // return Result::success($data);
         // return Result::success($data);
-        if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
-            $result = WebsiteCategory::where('website_id',$data['website_id'])->where('aLIas_pinyin',$data['pinyin'])->first(['category_id']);
+        if (isset($data['pinyin']) && !empty($data['pinyin'])) {
+            $result = WebsiteCategory::where('website_id', $data['website_id'])->where('aLIas_pinyin', $data['pinyin'])->first(['category_id']);
         }
         }
-        if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
-            $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
+        if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
+            $result = FooterCategory::where('website_id', $data['website_id'])->where('name_pinyin', $data['foot_pinyin'])->first(['id']);
         }
         }
         if (!isset($result) || empty($result)) {
         if (!isset($result) || empty($result)) {
-            return Result::error("暂无该导航",0); 
+            return Result::error("暂无该导航", 0);
         }
         }
-        return Result::success($result); 
+        return Result::success($result);
     }
     }
 
 
     //20250212  网站标识
     //20250212  网站标识

+ 1 - 2
app/Model/WebsiteCategory.php

@@ -18,7 +18,7 @@ class WebsiteCategory extends Model
     /**
     /**
      * The attributes that are mass assignable.
      * The attributes that are mass assignable.
      */
      */
-    protected array $fillable = ['website_id','name','sort','pid','seo_title', 'seo_keywords','seo_description','pid_arr','alias','category_arr_id','category_id','is_url','web_url'];
+    protected array $fillable = ['website_id', 'name', 'sort', 'pid', 'seo_title', 'seo_keywords', 'seo_description', 'pid_arr', 'alias', 'aLIas_pinyin', 'category_arr_id', 'category_id', 'is_url', 'web_url'];
 
 
     /**
     /**
      * The attributes that should be cast to native types.
      * The attributes that should be cast to native types.
@@ -28,5 +28,4 @@ class WebsiteCategory extends Model
     {
     {
         return $this->hasMany(WebsiteCategory::class, 'pid', 'category_id');
         return $this->hasMany(WebsiteCategory::class, 'pid', 'category_id');
     }
     }
-
 }
 }