Browse Source

专题管理

gorden 9 months ago
parent
commit
8a7dcdaef9
1 changed files with 31 additions and 17 deletions
  1. 31 17
      app/admin/service/goods/GoodsService.php

+ 31 - 17
app/admin/service/goods/GoodsService.php

@@ -56,11 +56,18 @@ class GoodsService
             })->when($categoryId != null, function ($query) use ($categoryId) {
                 $query->where('join_goods_category_id', $categoryId);
             })
-            ->where('goods_classify', $classify)
+            ->when($classify != '', function ($query) use ($classify) {
+                if ($classify == 'GOODS') {
+                    $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
+                } else {
+                    $query->where('goods_classify', $classify);
+                }
+            })
             ->orderBy('goods_addtimes', 'DESC')
             ->forPage($page, $pageSize)
             ->get()
             ->toArray();
+
         $total = Goods::when($goodsName != '', function ($query) use ($goodsName) {
             $query->where(function ($q) use ($goodsName) {
                 $q->where('goods_name', 'like', '%' . $goodsName . '%')
@@ -68,7 +75,14 @@ class GoodsService
             });
         })->when($categoryId != null, function ($query) use ($categoryId) {
             $query->where('join_goods_category_id', $categoryId);
-        })->where('goods_classify', $classify)->count();
+        })->when($classify != '', function ($query) use ($classify) {
+            if ($classify == 'GOODS') {
+                $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
+            } else {
+                $query->where('goods_classify', $classify);
+            }
+        })
+            ->count();
 
         foreach ($rows as &$row) {
             $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];
@@ -106,7 +120,7 @@ class GoodsService
             })->when($categoryId != null, function ($query) use ($categoryId) {
                 $query->where('join_goods_category_id', $categoryId);
             })
-            ->whereIn('join_goods_category_id', [65,43])
+            ->whereIn('join_goods_category_id', [65, 43])
             ->orderBy('goods_addtimes', 'DESC')
             ->forPage($page, $pageSize)
             ->get()
@@ -118,7 +132,7 @@ class GoodsService
             });
         })->when($categoryId != null, function ($query) use ($categoryId) {
             $query->where('join_goods_category_id', $categoryId);
-        })->whereIn('join_goods_category_id', [65,43])->count();
+        })->whereIn('join_goods_category_id', [65, 43])->count();
 
         foreach ($rows as &$row) {
             $row['goods_cover'] = getenv('STORAGE_DOMAIN') . $row['goods_cover'];
@@ -311,8 +325,8 @@ class GoodsService
                     $skuNameValue = [];
                     $i = 1;
                     foreach ($skuSpecsJson as $k => $item) {
-                        if (is_array($item)){
-                            $item = implode(',',$item);
+                        if (is_array($item)) {
+                            $item = implode(',', $item);
                         }
                         $skuSpecs = $skuSpecs . $item . ',';
                         $skuNameKey = 'skuName' . $i;
@@ -384,11 +398,11 @@ class GoodsService
                 foreach ($data['goods_json'] as $key => $datum) {
                     $data['goods_json'][$key]['color'] = rgbToHex($datum['color']);
                 }
-            }elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43){
+            } elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43) {
 //                dump($data['goods_json']);
-                foreach ($data['goods_json'] as $key1 => $item1){
+                foreach ($data['goods_json'] as $key1 => $item1) {
                     $data['goods_json'][$key1]['title'] = $key1;
-                    foreach ($item1['items'] as $key2 => $item2){
+                    foreach ($item1['items'] as $key2 => $item2) {
                         $data['goods_json'][$key1]['items'][$key2]['key'] = $key2;
                         $data['goods_json'][$key1]['items'][$key2]['params'] = $item2;
                     }
@@ -800,19 +814,19 @@ class GoodsService
                 }
 
                 $model->goods_json = json_encode($goodsJson);
-            }elseif (!empty($params['goods_json']) && $params['join_goods_category_id'] == 43){
+            } elseif (!empty($params['goods_json']) && $params['join_goods_category_id'] == 43) {
                 $goodsJson = json_decode($params['goods_json'], true);
                 $newGoodsJson = [];
-                foreach ($goodsJson as $item1){
+                foreach ($goodsJson as $item1) {
                     $newItem1 = [];
-                    foreach ($item1['items'] as $item2){
+                    foreach ($item1['items'] as $item2) {
                         $newItem1['items'][$item2['key']] = $item2['params'];
                     }
                     $newItem1['service'] = $item1['service'];
                     $newGoodsJson[$item1['title']] = $newItem1;
                 }
                 $model->goods_json = json_encode($newGoodsJson);
-            }else{
+            } else {
                 $model->goods_json = '[]';
             }
 
@@ -1043,19 +1057,19 @@ class GoodsService
                 }
 
                 $data['goods_json'] = json_encode($goodsJson);
-            }elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43){
+            } elseif (!empty($data['goods_json']) && $data['join_goods_category_id'] == 43) {
                 $goodsJson = json_decode($data['goods_json'], true);
                 $newGoodsJson = [];
-                foreach ($goodsJson as $item1){
+                foreach ($goodsJson as $item1) {
                     $newItem1 = [];
-                    foreach ($item1['items'] as $item2){
+                    foreach ($item1['items'] as $item2) {
                         $newItem1['items'][$item2['key']] = $item2['params'];
                     }
                     $newItem1['service'] = $item1['service'];
                     $newGoodsJson[$item1['title']] = $newItem1;
                 }
                 $data['goods_json'] = json_encode($newGoodsJson);
-            }else{
+            } else {
                 $data['goods_json'] = '[]';
             }