Эх сурвалжийг харах

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

LiuJ 2 долоо хоног өмнө
parent
commit
050c875d2b

+ 15 - 1
app/JsonRpc/FooterService.php

@@ -10,6 +10,7 @@ use Hyperf\RpcServer\Annotation\RpcService;
 use App\Tools\Result;
 use Hyperf\DbConnection\Db;
 use PhpParser\Node\Expr\Clone_;
+use Overtrue\Pinyin\Pinyin;
 
 #[RpcService(name: "FooterService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class FooterService implements FooterServiceInterface
@@ -58,9 +59,17 @@ class FooterService implements FooterServiceInterface
      */
     public function addFooterCategory(array $data): array
     {
+        
+        //从WebsiteCategory取出alis ,并转成拼音存放到alias_pinyin
+        // $result = WebsiteCategory::where($where)->first();
+        // $result = $result->toArray();
         if(empty($data)){
             $result = Website::select('website_name','id')->get();
         }else{
+            // $alias = $data['name'];
+            // 引入 Pinyin 类
+            
+            // $alias_pinyin = $pinyin->permalink($alias, '');
             // 底部导航类型  0:内容型;1:列表型;
             $webid = Website::select('website_name','id')->where('id',$data['website_id'])->first();
             if(empty($webid)){
@@ -71,12 +80,15 @@ class FooterService implements FooterServiceInterface
             if(!empty($name)){
                 return Result::error("该底部导航名称已存在!");
             }
+            $pinyin = new Pinyin();
             $result = FooterCategory::insertGetId($data); 
+            $name_pinyin['name_pinyin'] = $pinyin->permalink($data['name'], '') . $result;
+            $result = FooterCategory::where('id', $result)->update($name_pinyin);
         }
         if(empty($result)){
             return Result::error("添加失败!");
         }else{
-            return Result::success($result);
+            return Result::success($data);
         }
     }
      /**
@@ -113,6 +125,8 @@ class FooterService implements FooterServiceInterface
             if(empty($webid)){
                 return Result::error("该网站不存在!");
             }
+            $pinyin = new Pinyin();
+            $data['name_pinyin'] = $pinyin->permalink($data['name'], ''). $data['id'];
             $result = FooterCategory::where('id', $data['id'])->update($data);
         }
         if (empty($result)) {

+ 68 - 41
app/JsonRpc/WebsiteService.php

@@ -518,14 +518,22 @@ class WebsiteService implements WebsiteServiceInterface
             $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
             $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
             // return Result::success($where);
-            $result = AdPlace::where($where)
+            $result =  AdPlace::where($where)
                 ->leftJoin("ad", function ($join) use ($now) {
                     $join->on("ad.pid", "=", "ad_place.id")
                         ->where('ad.status', 1)
                         ->where('ad.fromtime', '<=', $now)
                         ->where('ad.totime', '>=', $now);
                 })
-                ->select("ad_place.*", 'ad.*', "ad_place.id as ad_place_id", "ad.name as ad_name")
+                ->select(
+                    'ad_place.name as place_name',
+                    'ad_place.thumb',
+                    'ad_place.ad_tag',
+                    'ad.name as ad_name',
+                    'ad.image_src',
+                    'ad.image_url',
+                    'ad.image_alt'
+                )
                 ->get()->all();
             if (empty($result)) {
                 return Result::error("此广告位不存在!", 0);
@@ -2081,59 +2089,59 @@ class WebsiteService implements WebsiteServiceInterface
     }
 
     /*
-     * 获取父级/子级栏目
+     * 获取父级/子级栏目------路由
      * @param array $data
      * @return array
      * */
     public function getWebsiteParentCategory(array $data): array
     {
+        // return Result::success($data);
         if (isset($data['website_id']) && !empty($data['website_id'])) {
             $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
         }
         if (empty($website)) {
             return Result::error("暂无该网站", 0);
         }
-        if ($data['id'] == 0) {
-            // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法
-            // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
-            $category = WebsiteCategory::where('website_id', $data['website_id'])
-                ->where('pid', 0)
-                ->select('alias_pinyin', 'category_id', 'alias')
-                ->get() // 添加 get() 方法获取结果集合
-                ->map(function ($item) {
-                    return [
-                        'path' => "/{$item->alias_pinyin}/",
-                        'name' => $item->alias,
-                        'cid' => $item->category_id,
-                    ];
-                })
-                ->values()
-                ->all();
-        } else {
-            // 不使用 with 方法,直接查询父级栏目需要的字段
-            $category = WebsiteCategory::where('website_id', $data['website_id'])
-                ->where('pid', '!=', 0)
-                ->get();
-            $category = $category->map(function ($item) {
-                $alias = $item->alias;
-                $category_id = $item->category_id;
-                $alias_pinyin = $item->aLIas_pinyin;
-                // 根据 pid 查找父级栏目
-                $parent = WebsiteCategory::where('website_id', $item->website_id)
-                    ->where('category_id', $item->pid)
-                    ->first();
-                $parentAlias = $parent ? $parent->aLIas_pinyin : '';
-                return [
-                    'path' => "/{$parentAlias}/{$alias_pinyin}/",
-                    'name' => $alias ? "{$alias}" : null,
-                    'cid' => $category_id ? "{$category_id}" : null,
-                ];
-            })->values()->all();
-        }
+        // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
+        // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理
+        $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
+            ->where('pid', 0)
+            ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
+            ->get() // 添加 get() 方法获取结果集合
+            ->all();
+        // 提前查询所有父级栏目,避免在 map 中多次查询
+        // 提前查询所有父级栏目信息并以 category_id 作为键存储
+        $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
+            ->where('pid', 0)
+            ->select('category_id', 'aLIas_pinyin')
+            ->get()
+            ->keyBy('category_id');
+
+        // 直接查询子栏目信息
+        $child = WebsiteCategory::where('website_id', $data['website_id'])
+            ->where('pid', '!=', 0)
+            ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
+            ->get();
+
+        // 使用集合的 map 方法处理子栏目信息
+        $category['child'] = $child->map(function ($item) use ($parentCategories) {
+            $alias = $item->alias;
+            $category_id = $item->category_id;
+            $alias_pinyin = $item->aLIas_pinyin;
+            $parent = $parentCategories->get($item->pid);
+            $parentAlias = $parent ? $parent->aLIas_pinyin : '';
+            $result = [
+                'name' => $alias,
+                'cid' => $category_id
+            ];
+            if (!empty($alias_pinyin) && !empty($parentAlias)) {
+                $result['path'] = "/{$parentAlias}/{$alias_pinyin}/";
+            }
+            return $result;
+        })->values()->all();
         if (empty($category)) {
             return Result::error("暂无此导航", 0);
         }
-        // $result = [];
         return Result::success($category);
     }
     /**
@@ -2170,6 +2178,25 @@ class WebsiteService implements WebsiteServiceInterface
         return Result::success($result);
     }
 
+
+    /**
+     * 路由匹配
+     * @param array $data
+     */
+    public function getWebsiteRoute(array $data): array
+    {
+        $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
+        if (empty($website)) {
+            return Result::error("暂无该网站", 0);
+        }
+        // return Result::success($data);
+        $result = WebsiteCategory::where('website_id', $data['website_id'])->where('aLIas_pinyin', $data['pinyin'])->first(['category_id']);
+        if (empty($result)) {
+            return Result::error("暂无此导航", 0);
+        }
+        return Result::success($result['category_id']);
+    }
+
     //20250212  网站标识
     public function addWebsiteGroup(array $data): array
     {

+ 2 - 0
app/JsonRpc/WebsiteServiceInterface.php

@@ -136,4 +136,6 @@ interface WebsiteServiceInterface
     public function getWebsiteParentCategory(array $data): array;
     public function getWebsiteFootAll(array $data): array;
     public function getWebsiteHead(array $data): array;
+    
+    public function getWebsiteRoute(array $data): array;
 }