|
|
@@ -28,7 +28,7 @@ use think\facade\Db;
|
|
|
class TrainingQuestionsLogic extends BaseLogic
|
|
|
{
|
|
|
|
|
|
-
|
|
|
+ public static $select_value = [];
|
|
|
/**
|
|
|
* @notes 添加
|
|
|
* @param array $params
|
|
|
@@ -44,8 +44,9 @@ class TrainingQuestionsLogic extends BaseLogic
|
|
|
'training_course_id' => $params['training_course_id'],
|
|
|
'title' => $params['title'],
|
|
|
'question_type' => $params['question_type'],
|
|
|
- 'question_selects' => $params['question_selects'],
|
|
|
- 'question_answer' => $params['question_answer'],
|
|
|
+ //'question_selects' => $params['question_selects'],
|
|
|
+ 'question_selects' => self::configureReservedField($params['question_selects']??[]),
|
|
|
+ 'question_answer' => self::$select_value?implode(',',self::$select_value):'',
|
|
|
'question_analysis' => $params['question_analysis'],
|
|
|
]);
|
|
|
|
|
|
@@ -68,14 +69,15 @@ class TrainingQuestionsLogic extends BaseLogic
|
|
|
*/
|
|
|
public static function edit(array $params): bool
|
|
|
{
|
|
|
+
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
TrainingQuestions::where('id', $params['id'])->update([
|
|
|
'training_course_id' => $params['training_course_id'],
|
|
|
'title' => $params['title'],
|
|
|
'question_type' => $params['question_type'],
|
|
|
- 'question_selects' => $params['question_selects'],
|
|
|
- 'question_answer' => $params['question_answer'],
|
|
|
+ 'question_selects' => json_encode(self::configureReservedField($params['question_selects']??[])),
|
|
|
+ 'question_answer' => self::$select_value?implode(',',self::$select_value):'',
|
|
|
'question_analysis' => $params['question_analysis'],
|
|
|
]);
|
|
|
|
|
|
@@ -113,4 +115,22 @@ class TrainingQuestionsLogic extends BaseLogic
|
|
|
{
|
|
|
return TrainingQuestions::findOrEmpty($params['id'])->toArray();
|
|
|
}
|
|
|
+
|
|
|
+ public static function configureReservedField($data): array
|
|
|
+ {
|
|
|
+ $select_value = [];
|
|
|
+ foreach ($data as $key => &$item) {
|
|
|
+ $data[$key]['block_key'] = $key+1;
|
|
|
+ if($item['select_value']){
|
|
|
+ $select_value[] = $data[$key]['block_key'];
|
|
|
+ $item['select_value'] = \true;
|
|
|
+ }else{
|
|
|
+ $item['select_value'] = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self::$select_value = $select_value;
|
|
|
+ return $data??[];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|