sandm 1 年之前
父节点
当前提交
59fb409157
共有 1 个文件被更改,包括 16 次插入8 次删除
  1. 16 8
      server/api/modules/v1/controllers/SurveyController.php

+ 16 - 8
server/api/modules/v1/controllers/SurveyController.php

@@ -271,18 +271,26 @@ class SurveyController extends Controller {
                 }
             }
 
+            $cengci = [];
+            $level = [];
             foreach($list as $k => $v){
-                $zclist = Policy::find()->where(['type' => Policy::TYPE_SURVEY, 'estate' => $type,'title' => $v['title']])->andWhere(['like','cengci',"{$v['level']}"])->all();
-                $list[$k]['policy'] = $zclist;
-            }
 
-            $cengci = [];
-            foreach ($list as $value) {
-                if(!isset($cengci[$value['level']])){
-                    $cengci[$value['level']] = $value;
+                if(!in_array($v['level'],$level)){
+                    $cengci[] = [
+                        'id' => $v['id'],
+                        'title' => $v['level'],
+                        'content' => '',
+                        'level' => $v['level'],
+                        'policy' => []
+                    ];
+                    array_push($level,$v['level']);
+                    $index = count($level) - 1;
+                }else{
+                    $index = array_search($v['level'],$level);
                 }
+                $zclist = Policy::find()->where(['type' => Policy::TYPE_SURVEY, 'estate' => $type,'title' => $v['title']])->andWhere(['like','cengci',"{$v['level']}"])->all();
+                $cengci[$index]['policy'] = array_merge($cengci[$index]['policy'],$zclist);
             }
-            $cengci = array_values($cengci);
 
         }else{
             foreach ($survey as $key=>$value) {