|
@@ -2,13 +2,11 @@
|
|
|
|
|
|
namespace app\admin\controller\sys_manage;
|
|
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\admin\validate\sys_manage\ContentValidate;
|
|
use app\controller\Curd;
|
|
use app\controller\Curd;
|
|
-use app\model\Adv;
|
|
|
|
-use app\model\Article;
|
|
|
|
use app\model\Content;
|
|
use app\model\Content;
|
|
|
|
+use app\model\SysField;
|
|
use support\exception\BusinessException;
|
|
use support\exception\BusinessException;
|
|
use support\Request;
|
|
use support\Request;
|
|
use support\Response;
|
|
use support\Response;
|
|
@@ -36,7 +34,7 @@ class QuestionController extends Curd
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
$where['content_category'] = 'WELLNESSQUESTION';
|
|
$where['content_category'] = 'WELLNESSQUESTION';
|
|
$order = $request->get('order', 'desc');
|
|
$order = $request->get('order', 'desc');
|
|
- $field = $field ?? 'content_addtimes';
|
|
|
|
|
|
+ $field = $field ?? 'content_sort';
|
|
$query = $this->doSelect($where, $field, $order);
|
|
$query = $this->doSelect($where, $field, $order);
|
|
return $this->doFormat($query, $format, $limit);
|
|
return $this->doFormat($query, $format, $limit);
|
|
}
|
|
}
|
|
@@ -78,7 +76,7 @@ class QuestionController extends Curd
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($field) {
|
|
if ($field) {
|
|
- $model = $model->orderBy($field, $order);
|
|
|
|
|
|
+ $model = $model->orderBy($field, $order)->orderBy('content_addtimes','DESC');
|
|
}
|
|
}
|
|
return $model;
|
|
return $model;
|
|
}
|
|
}
|
|
@@ -88,20 +86,20 @@ class QuestionController extends Curd
|
|
foreach ($items as &$item) {
|
|
foreach ($items as &$item) {
|
|
if (!empty($item->content_config_json)) {
|
|
if (!empty($item->content_config_json)) {
|
|
$contentConfigJson = json_decode($item->content_config_json, true);
|
|
$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 {
|
|
} else {
|
|
$item->content_config_json = [];
|
|
$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
|
|
* @Author Gorden
|
|
* @Date 2024/3/27 10:24
|
|
* @Date 2024/3/27 10:24
|
|
*
|
|
*
|
|
@@ -123,25 +157,20 @@ class QuestionController extends Curd
|
|
{
|
|
{
|
|
$data = $this->inputFilter($request->post());
|
|
$data = $this->inputFilter($request->post());
|
|
$data['content_category'] = 'WELLNESSQUESTION';
|
|
$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;
|
|
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
|
|
protected function updateInput(Request $request): array
|
|
{
|
|
{
|
|
$primary_key = $this->model->getKeyName();
|
|
$primary_key = $this->model->getKeyName();
|
|
@@ -151,19 +180,7 @@ class QuestionController extends Curd
|
|
if (!$model) {
|
|
if (!$model) {
|
|
throw new BusinessException('记录不存在', 2);
|
|
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]);
|
|
unset($data[$primary_key]);
|
|
return [$id, $data];
|
|
return [$id, $data];
|
|
}
|
|
}
|