Просмотр исходного кода

前端接口 分类和地址查询供应信息

moonsflyer 5 месяцев назад
Родитель
Сommit
57b1d35da0
1 измененных файлов с 24 добавлено и 5 удалено
  1. 24 5
      app/api/lists/supply_demand/SupplyDemandLists.php

+ 24 - 5
app/api/lists/supply_demand/SupplyDemandLists.php

@@ -18,6 +18,7 @@ use app\api\lists\BaseApiDataLists;
 use app\common\enum\YesNoEnum;
 use app\common\lists\ListsSearchInterface;
 use app\common\model\agricultural_machinery\UserService;
+use app\common\model\supply_demand\SupplyDemandCate;
 use app\common\model\supply_demand\SupplyDemandInfo;
 
 
@@ -59,11 +60,29 @@ class SupplyDemandLists extends BaseApiDataLists implements ListsSearchInterface
         }else{
             $where[] = ['status', '=', 2];
         }
-//
-//        if (!empty($this->params['area_id'])) {
-//
-//            $where[] = ['area_id', 'like', '%' . ',' .$this->params['area_id'].',' . '%'];
-//        }
+
+        if (isset($this->params['cate_id']) && $this->params['cate_id']) {
+            $cate_id_arr = [];
+            $cate_id =  $this->params['cate_id'];
+            $cate_info = SupplyDemandCate::find($cate_id);
+            if($cate_info){
+                array_push($cate_id_arr,$cate_id);
+                if($cate_info['level'] == 1){
+                    $children_cate_info = SupplyDemandCate::where(['pid'=>$cate_id])->field('id,pid')->select()->toArray();
+                    if($children_cate_info){
+                        $children_cate = array_column($children_cate_info,'id');
+                        $cate_id_arr = array_merge($cate_id_arr,$children_cate);
+                    }
+                }
+                $where[] = ['cate_id', 'in',$cate_id_arr];
+            }
+
+        }
+
+        if (isset($this->params['area_id']) && $this->params['area_id']) {
+            $area_id =  $this->params['area_id'];
+            $where[] = ['area_id', '=',$area_id];
+        }
 
         return $where;
     }