xialei 1 год назад
Родитель
Сommit
62bc77d41a
1 измененных файлов с 26 добавлено и 0 удалено
  1. 26 0
      app/common/repositories/store/product/ProductRepository.php

+ 26 - 0
app/common/repositories/store/product/ProductRepository.php

@@ -800,6 +800,26 @@ class ProductRepository extends BaseRepository
800 800
 
801 801
         $where = array_merge($where, $this->dao->productShow());
802 802
 
803
+        $cateList = [];
804
+        if($where['cate_id']){
805
+            $cate_name = Db::name('store_category')->where('pid', 564)->where('store_category_id', $where['cate_id'])->value('cate_name');
806
+            $url = "https://dc-api.gdjbp.com/douhuomallCategory/getCateAll";
807
+            $result = curlGet($url);
808
+            if (!isset($result['status']) || $result['status'] != 200) {
809
+                $cateList = [$where['cate_id']];
810
+            }else{
811
+                $cateIds = [];
812
+                foreach($result['data'] as $item){
813
+                    if($item['cateName'] == $cate_name){
814
+                        $cateIds = explode(",", $item['cateIds']);
815
+                        break;
816
+                    }
817
+                }
818
+                $cateList = array_merge([$where['cate_id']], $cateIds);
819
+            }
820
+            unset($where['cate_id']);
821
+        }
822
+
803 823
         //搜索记录
804 824
         if ($userInfo && isset($where['keyword']) && !empty($where['keyword'])){
805 825
             log::info("======sousuojilu====");
@@ -819,6 +839,12 @@ class ProductRepository extends BaseRepository
819 839
             });
820 840
         }
821 841
 
842
+        if(count($cateList) > 0){
843
+            $query->where(function ($query2) use ($cateList) {
844
+                $query2->whereIn('cate_id', $cateList)->whereOr("cate_id is null");
845
+            });
846
+        }
847
+
822 848
         $count = $query->count($this->dao->getPk());
823 849
 //        echo DB::getlastsql();die;
824 850
         $list = $query->page($page, $limit)->setOption('field', [])->field($this->filed)->select();