Prechádzať zdrojové kódy

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

LiuJ 4 dní pred
rodič
commit
1dffaa7a3e
1 zmenil súbory, kde vykonal 60 pridanie a 28 odobranie
  1. 60 28
      app/JsonRpc/NewsService.php

+ 60 - 28
app/JsonRpc/NewsService.php

@@ -1919,9 +1919,9 @@ class NewsService implements NewsServiceInterface
     {
         $input['id'] = $data['id'];
         $input['website_id'] = $data['website_id'];
-        // return Result::success($input);
+        $catid = $data['catid'];
         $data = json_decode($input['id'] ?? '', true) ?? [];
-        $result = array_map(function ($item) use ($input) {
+        $result['goods'] = array_map(function ($item) use ($input) {
             // 检查parent元素是否存在且不是undefined
             if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
                 list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
@@ -1967,10 +1967,23 @@ class NewsService implements NewsServiceInterface
                     ->offset($goodStart)
                     ->limit($goodNum)
                     ->get();
-                $all_goods = $this->processGoods($all_goods, $input);
+                $all_goods = $this->processGoods($all_goods, $website);
+                    
             }
             return  $all_goods;
         }, $data);
+        $website = $input['website_id'];
+        $result['article'] = Article::where(function ($query) use ($website) {
+                $query->where(function ($subQuery) use ($website) {
+                    $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
+                })->orWhereNull("ignore_ids");
+            })
+            ->where('catid', $catid)
+            ->where('article.status', 1)
+            ->leftJoin('article_data', 'article_data.article_id', 'article.catid')
+            ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl','article_data.content')
+            ->orderBy('article.updated_at', 'desc')
+            ->first();
         return Result::success($result);
     }
     /**
@@ -1980,43 +1993,61 @@ class NewsService implements NewsServiceInterface
      *  */
     public function getWebsiteshopCat(array $data): array
     {
-        $category = WebsiteCategory::where('website_id', $data['website_id'])
-            ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
-            ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
-            ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id')
+        $website = $data['website_id'];
+        $category = WebsiteCategory::where('website_id', $website)
+            ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
+            ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
+            ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id')
             ->orderBy('sort')
-            ->get()
-            ->map(function ($item) use ($data) {
-                $pinyin = [];
-                $level = json_decode($item->category_arr_id);
-                // 递归获取所有父级栏目的拼音
-                if ($item->pid != 0) {
-                    $pinyin = WebsiteCategory::whereIn('category_id', $level)
-                        ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
+            ->get();
+        
+        $cat =  $category->map(function ($item) use ($website) {
+                $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
+                $pid = $item->pid?? 0;
+                if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
+                    $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
+                        ->where('website_id', $website)
+                        ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
                         ->get(['aLIas_pinyin'])
                         ->pluck('aLIas_pinyin')
                         ->implode('/');
-                } else {
-                    $pinyin = $item->aLIas_pinyin;
+                }else{
+                    $pinyin = $item->aLIas_pinyin ?? '';
                 }
-                $item->aLIas_pinyin = $pinyin;
-                return $item;
-            });
-        $goods = Good::where('website_id', $data['website_id'])
+                $item->pinyin = $pinyin;
+            })
+            ;
+        if(empty($category)){
+            return Result::error("栏目查询失败", 0);
+        }
+        // $cat_tree = $this->processGoods($cat, $website);
+        $goods = Good::where('website_id', $website)
             ->where('status', 2)
             ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
             ->latest('updated_at')
             ->offset(($data['page'] - 1) * $data['pageSize'])
             ->limit($data['pageSize'])
             ->get();
-        $goods = $this->processGoods($goods, $data);
-        if (empty($category)) {
-            return Result::error("栏目查询失败", 0);
-        }
-        if (empty($goods)) {
+        if($goods->isEmpty()){
             return Result::error("商品查询失败", 0);
         }
-        // 调用Tool中的buildMenuTree方法构建菜单树
+        if(count($goods) > 1){
+            $goods = $this->processGoods($goods, $website);
+        }else{
+            $catid = $goods[0]['catid'] ?? 0;
+            $good_category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
+            if (!empty($good_category->pid) && $good_category->pid != 0) {
+                $level = json_decode($good_category->category_arr_id);
+                $pinyin = WebsiteCategory::whereIn('category_id', $level)
+                    ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
+                    ->get(['aLIas_pinyin'])
+                    ->pluck('aLIas_pinyin')
+                    ->implode('/');
+            } else {
+                $pinyin = $good_category->aLIas_pinyin ?? '';
+            }
+            $goods[0]['pinyin'] = $pinyin;
+        }
         $cat_tree = Result::buildMenuTree($category);
         $result = [
             'category' => $cat_tree,
@@ -2114,7 +2145,8 @@ class NewsService implements NewsServiceInterface
         $where = [
             'good.status' => 2,
             'good.website_id' => $data['website_id'],
-        ];
+            'good.id' => $data['id'],
+        ]; 
         $goods = Good::where($where)
             ->where('good.id', $data['id'])
             ->leftJoin('website_category', 'website_category.category_id', 'good.catid')