Jelajahi Sumber

问卷分组

gorden 3 bulan lalu
induk
melakukan
33f9fcbeaf

+ 17 - 12
app/admin/controller/sys_manage/CategoryController.php

@@ -41,25 +41,30 @@ class CategoryController extends Curd
         $format = 'tree';
         $order = $request->get('order', 'desc');
         $field = $field ?? 'category_sort';
-        $where['category_status'] = ['in',['ACTIVED','UNSHOW']];
+        $where['category_status'] = ['in', ['ACTIVED', 'UNSHOW']];
+//        dump($where);
         $query = $this->doSelect($where, $field, $order);
         return $this->doFormat($query, $format, 1000);
     }
 
-    public function afterQuery($items){
+    public function afterQuery($items)
+    {
+        $categoryType = \request()->get('category_type', '');
         $categoryDatas = [];
-        foreach($items as &$item){
-            if (empty($item->category_super_path)){
-                $item->category_super_path = '#'.$item['category_id'].'#';
+        foreach ($items as &$item) {
+            if (empty($item->category_super_path)) {
+                $item->category_super_path = '#' . $item['category_id'] . '#';
             }
-            $categorys = SysCategory::where('category_super_path','like',$item->category_super_path.'%')
-                ->where('category_status','ACTIVED')
+            $categorys = SysCategory::where('category_super_path', 'like', $item->category_super_path . '%')
+                ->when(!empty($categoryType), function ($query) use ($categoryType) {
+                    $query->where('category_type', $categoryType);
+                })->whereIn('category_status', ['ACTIVED', 'UNSHOW'])
                 ->paginate(1000)
                 ->items();
-            $categoryDatas = array_merge($categorys,$categoryDatas);
+            $categoryDatas = array_merge($categorys, $categoryDatas);
         }
 
-        $items = array_merge($items,$categoryDatas);
+        $items = array_merge($items, $categoryDatas);
 
         return $items;
     }
@@ -101,7 +106,7 @@ class CategoryController extends Curd
         $order = $request->get('order', 'desc');
         $field = $field ?? 'category_sort';
         $where['category_status'] = 'ACTIVED';
-        $where['category_super_id'] = ['in','31,154,5,181,30,70,42'];
+        $where['category_super_id'] = ['in', '31,154,5,181,30,70,42'];
         $query = $this->doSelect($where, $field, $order);
         return $this->doFormatForGoods($query, $format, 1000);
         // $model->orWhereIn('category_id', ['31','154','5','181','30','70','42']);
@@ -128,12 +133,12 @@ class CategoryController extends Curd
         if (method_exists($this, "afterQuery")) {
             $items = call_user_func([$this, "afterQuery"], $items);
         }
-        $super = SysCategory::whereIn('category_id', ['31','154','5','181','30','70','42']);
+        $super = SysCategory::whereIn('category_id', ['31', '154', '5', '181', '30', '70', '42']);
         $superPaginator = $super->paginate($limit);
         $superTotal = $superPaginator->total();
         $superItems = $superPaginator->items();
 
-        $items = array_merge($items,$superItems);
+        $items = array_merge($items, $superItems);
         $total = $total + $superTotal;
 
         $format_function = $methods[$format] ?? 'formatNormal';

+ 66 - 49
app/admin/controller/sys_manage/QuestionController.php

@@ -2,13 +2,11 @@
 
 namespace app\admin\controller\sys_manage;
 
-use app\admin\validate\sys_manage\AdvValidate;
-use app\admin\validate\sys_manage\ArticleValidate;
+use app\admin\service\sys_manage\FieldService;
 use app\admin\validate\sys_manage\ContentValidate;
 use app\controller\Curd;
-use app\model\Adv;
-use app\model\Article;
 use app\model\Content;
+use app\model\SysField;
 use support\exception\BusinessException;
 use support\Request;
 use support\Response;
@@ -36,7 +34,7 @@ class QuestionController extends Curd
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
         $where['content_category'] = 'WELLNESSQUESTION';
         $order = $request->get('order', 'desc');
-        $field = $field ?? 'content_addtimes';
+        $field = $field ?? 'content_sort';
         $query = $this->doSelect($where, $field, $order);
         return $this->doFormat($query, $format, $limit);
     }
@@ -78,7 +76,7 @@ class QuestionController extends Curd
             }
         }
         if ($field) {
-            $model = $model->orderBy($field, $order);
+            $model = $model->orderBy($field, $order)->orderBy('content_addtimes','DESC');
         }
         return $model;
     }
@@ -88,20 +86,20 @@ class QuestionController extends Curd
         foreach ($items as &$item) {
             if (!empty($item->content_config_json)) {
                 $contentConfigJson = json_decode($item->content_config_json, true);
-                $questionArray = [];
-                foreach ($contentConfigJson as $question) {
-                    $questionArray[] = [
-                        [
-                            'label' => '选项',
-                            'value' => $question['field'],
-                        ],
-                        [
-                            'label' => '题目',
-                            'value' => $question['question'],
-                        ]
-                    ];
-                }
-                $item->content_config_json = $questionArray;
+//                $questionArray = [];
+//                foreach ($contentConfigJson as $question) {
+//                    $questionArray[] = [
+//                        [
+//                            'label' => '选项',
+//                            'value' => $question['field'],
+//                        ],
+//                        [
+//                            'label' => '题目',
+//                            'value' => $question['question'],
+//                        ]
+//                    ];
+//                }
+                $item->content_config_json = array_values($contentConfigJson);
             } else {
                 $item->content_config_json = [];
             }
@@ -111,7 +109,43 @@ class QuestionController extends Curd
     }
 
     /**
-     * @Desc
+     * @Desc 问卷详情
+     * @Author Gorden
+     * @Date 2024/12/2 10:09
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function info(Request $request): Response
+    {
+        $contentId = $request->get('content_id');
+
+        $question = Content::where('content_id', $contentId)->first();
+        $questionContent = [];
+        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_name', 'field_form_type')->get()->toArray();
+                $fieldName = '';
+                foreach ($fields as $field) {
+                    $formType = FieldService::$formType[$field['field_form_type']] ?? '';
+                    $fieldName .= $field['field_name'] . '(' . $formType . ');';
+                }
+                $questionContent[] = [
+                    'question' => $item['question'],
+                    'fieldStr' => rtrim($fieldName, ';')
+                ];
+            }
+            $question->content_question_content = $questionContent;
+        }
+
+        dump($question);
+
+        return json_success('success', $question);
+    }
+
+    /**
+     * @Desc insert 处理
      * @Author Gorden
      * @Date 2024/3/27 10:24
      *
@@ -123,25 +157,20 @@ class QuestionController extends Curd
     {
         $data = $this->inputFilter($request->post());
         $data['content_category'] = 'WELLNESSQUESTION';
-        $contentConfigJson = [];
-        if (!empty($request->post('question'))) {
-            $questions = $request->post('question');
-            foreach ($questions as $question) {
-                if (!empty($question[1]['value'])) {
-                    $contentConfigJson[] = [
-                        'field' => $question[0]['value'],
-                        'question' => $question[1]['value'],
-                    ];
-                }
-            }
-            $contentConfigJson = new \ArrayObject($contentConfigJson);
-
-            $data['content_config_json'] = json_encode($contentConfigJson);
-        }
+        $data['content_config_json'] = json_encode($request->post('question'));
 
         return $data;
     }
 
+    /**
+     * @Desc update 处理
+     * @Author Gorden
+     * @Date 2024/12/2 9:22
+     *
+     * @param Request $request
+     * @return array
+     * @throws BusinessException
+     */
     protected function updateInput(Request $request): array
     {
         $primary_key = $this->model->getKeyName();
@@ -151,19 +180,7 @@ class QuestionController extends Curd
         if (!$model) {
             throw new BusinessException('记录不存在', 2);
         }
-        $contentConfigJson = [];
-        if (!empty($request->post('question'))) {
-            $questions = $request->post('question');
-            foreach ($questions as $question) {
-                $contentConfigJson[] = [
-                    'question' => $question[1]['value'],
-                    'field' => $question[0]['value'],
-                ];
-            }
-            $contentConfigJson = new \ArrayObject($contentConfigJson);
-
-            $data['content_config_json'] = json_encode($contentConfigJson);
-        }
+        $data['content_config_json'] = json_encode($request->post('question'));
         unset($data[$primary_key]);
         return [$id, $data];
     }

+ 9 - 0
app/admin/service/sys_manage/FieldService.php

@@ -457,4 +457,13 @@ class FieldService
         'INT' => 'integer',
         'DECIMAL' => 'decimal'
     ];
+
+    public static $formType = [
+        'TEXT' => '单行文本',
+        'TEXTAREA' => '多行文本',
+        'RADIO' => '单选',
+        'CHECKBOX' => '多选',
+        'SELECT' => '下拉选择',
+        'DATE' => '日期'
+    ];
 }

+ 1 - 0
route/admin.php

@@ -432,6 +432,7 @@ Route::group('/admin', function () {
         ]);
         Route::group('/question', function () {
             Route::get('/list', [\app\admin\controller\sys_manage\QuestionController::class, 'select']);
+            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']);
             Route::delete('/delete', [\app\admin\controller\sys_manage\QuestionController::class, 'delete']);