Browse Source

健康档案

gorden 3 months ago
parent
commit
477c33eace
2 changed files with 41 additions and 2 deletions
  1. 40 2
      app/admin/controller/sys_manage/QuestionController.php
  2. 1 0
      route/admin.php

+ 40 - 2
app/admin/controller/sys_manage/QuestionController.php

@@ -33,7 +33,7 @@ class QuestionController extends Curd
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
         $where['content_category'] = 'WELLNESSQUESTION';
-        $order = $request->get('order', 'desc');
+        $order = $request->get('order', 'ASC');
         $field = $field ?? 'content_sort';
         $query = $this->doSelect($where, $field, $order);
         return $this->doFormat($query, $format, $limit);
@@ -76,7 +76,7 @@ class QuestionController extends Curd
             }
         }
         if ($field) {
-            $model = $model->orderBy($field, $order)->orderBy('content_addtimes','DESC');
+            $model = $model->orderBy($field, $order)->orderBy('content_addtimes', 'DESC');
         }
         return $model;
     }
@@ -108,6 +108,44 @@ class QuestionController extends Curd
         return $items;
     }
 
+    public function selectList()
+    {
+        $questions = Content::where('content_category', 'WELLNESSQUESTION')
+            ->select('content_title', 'content_config_json')
+            ->orderBy('content_sort', 'asc')
+            ->get()
+            ->toArray();
+        foreach ($questions as &$question) {
+            if (!empty($question['content_config_json'])) {
+                $contentConfigJson = json_decode($question['content_config_json'], true);
+                foreach ($contentConfigJson as $item) {
+                    $fields = SysField::whereIn('field_id', $item['field'])
+                        ->select('field_id', 'field_form_key', 'field_form_type', 'field_refer_json')
+                        ->orderByDesc('field_sort')
+                        ->get()
+                        ->toArray();
+                    $fieldData = [];
+                    foreach ($fields as $field) {
+                        if (!empty($field['field_refer_json'])) {
+                            $fieldData = [
+                                'form_type' => $field['field_form_type'],
+                                'form_key' => $field['field_form_key'],
+                                'field' => json_decode($field['field_refer_json'], true)
+                            ];
+                        }
+                    }
+                    $question['list'][] = [
+                        'question' => $item['question'],
+                        'fields' => $fieldData
+                    ];
+                }
+            }
+            unset($question['content_config_json']);
+        }
+
+        return json_success('success', $questions);
+    }
+
     /**
      * @Desc 问卷详情
      * @Author Gorden

+ 1 - 0
route/admin.php

@@ -433,6 +433,7 @@ Route::group('/admin', function () {
         ]);
         Route::group('/question', function () {
             Route::get('/list', [\app\admin\controller\sys_manage\QuestionController::class, 'select']);
+            Route::get('/selectList', [\app\admin\controller\sys_manage\QuestionController::class, 'selectList']);
             Route::get('/info', [\app\admin\controller\sys_manage\QuestionController::class, 'info']);
             Route::post('/add', [\app\admin\controller\sys_manage\QuestionController::class, 'insert']);
             Route::post('/update', [\app\admin\controller\sys_manage\QuestionController::class, 'update']);