dever il y a 6 ans
Parent
commit
d8baf2ebca
2 fichiers modifiés avec 68 ajouts et 16 suppressions
  1. 18 0
      database/exam.php
  2. 50 16
      src/Api.php

+ 18 - 0
database/exam.php

@@ -33,6 +33,12 @@ $continue_num_type = array
 	3 => '按照天间隔',
 );
 
+$continue_index = array
+(
+	1 => '复活完成后继续当前题目',
+	2 => '复活完成后完成当前题目,进入下一道题目',
+);
+
 
 $continue_num_user = array
 (
@@ -203,6 +209,18 @@ return array
 			'show'		=> array('continue=2', 'continue=3'),
 		),
 
+		'continue_index'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '答题复活是否完成当前题目',
+			'default' 	=> '1',
+			'desc' 		=> '答题复活是否完成当前题目',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $continue_index,
+			'show'		=> array('continue=2', 'continue=3'),
+		),
+
 		'continue_num'		=> array
 		(
 			'type' 		=> 'int-11',

+ 50 - 16
src/Api.php

@@ -53,6 +53,22 @@ class Api
 		return $result;
 	}
 
+	/**
+	 * 获取用户信息接口 api.getUserInfo?uid=1
+	 *
+	 * @return mixed
+	 */
+	public function getUserInfo()
+	{
+		$this->getUser();
+		$this->result();
+
+		$result['exam'] = $this->exam;
+		$result['user'] = $this->user;
+		
+		return $result;
+	}
+
 	/**
 	 * 从某个活动中抽取题目并保存下来
 	 * $category 分类id
@@ -223,6 +239,12 @@ class Api
 			$id = $this->user['id'];
 		}
 
+		# 获取规则
+		$this->result();
+	}
+
+	private function result()
+	{
 		if ($this->user['status'] >= 3) {
 			$this->exam['content'] = Dever::array_decode($this->exam['content']);
 			$this->exam['result'] = array();
@@ -409,6 +431,7 @@ class Api
 				$data['content'][$option]['score'] = 0;
 				$data['content'][$option]['title'] = '超时';
 			}
+
 			if (!isset($data['content'][$option])) {
 				Dever::alert('错误的选项信息');
 			}
@@ -423,33 +446,44 @@ class Api
 			}
 
 			$update['score'] = $data['score'] + $data['content'][$option]['score'];
-			$update['index'] = $data['index'] + 1;
 			$update['where_id'] = $data['user_data_id'];
 
 			$update['status'] = 2;
 
-			if ($update['index'] >= $data['num']) {
-				# 答题完成
-				$update['status'] = 4;
+			if ($this->exam['continue'] >= 2 && $data['content'][$option]['score'] == 0) {
+				# 答题错误 进度不变
+				$update['status'] = 3;
 				# 将当前分数同步到排行榜中去
 				$this->setRanking($update['score']);
+
+				# 答题完成后,进度变化
+				if ($this->exam['continue_index'] == 2) {
+					$update['index'] = $data['index'] + 1;
+				} else {
+					$update['index'] = $data['index'];
+				}
+			} else {
+				$update['index'] = $data['index'] + 1;
 			}
-			if ($this->exam['continue'] >= 2 && $data['content'][$option]['score'] == 0) {
-				#答题错误
-				$update['status'] = 3;
+
+			if ($update['index'] >= $data['num'] && $update['status'] == 2) {
+				# 答题完成
+				$update['status'] = 4;
 				# 将当前分数同步到排行榜中去
 				$this->setRanking($update['score']);
 			}
 			
 			Dever::db('question/user')->update($update);
 
-			$insert['user_id'] = $data['user_data_id'];
-			$insert['info_id'] = $data['id'];
-			$insert['score'] = $data['content'][$option]['score'];
-			$insert['option'] = $option;
-			$insert['uid'] = $this->user['uid'];
-			$insert['option_name'] = $data['content'][$option]['title'];
-			Dever::db('question/user_answer')->insert($insert);
+			if ($update['index'] > $data['index']) {
+				$insert['user_id'] = $data['user_data_id'];
+				$insert['info_id'] = $data['id'];
+				$insert['score'] = $data['content'][$option]['score'];
+				$insert['option'] = $option;
+				$insert['uid'] = $this->user['uid'];
+				$insert['option_name'] = $data['content'][$option]['title'];
+				Dever::db('question/user_answer')->insert($insert);
+			}
 		}
 
 		$result = array();
@@ -506,7 +540,7 @@ class Api
 
 			$update['where_id'] = $this->user['id'];
 			if ($this->user['index'] >= $this->user['num']) {
-				$update['status'] = 2;
+				$update['status'] = 4;
 			} else {
 				$update['status'] = 2;
 			}
@@ -529,7 +563,7 @@ class Api
 			$update['where_id'] = $this->user['id'];
 
 			if ($this->user['index'] >= $this->user['num']) {
-				$update['status'] = 2;
+				$update['status'] = 4;
 			} else {
 				$update['status'] = 2;
 			}