|
@@ -72,31 +72,7 @@ class Api
|
|
|
}
|
|
|
|
|
|
if ($level_ids) {
|
|
|
-
|
|
|
- $level = explode(',', $level_ids);
|
|
|
- $level_data = Dever::db('question/level')->getAll();
|
|
|
- $index = $index + 1;
|
|
|
- $level_info = array();
|
|
|
- $i = 1;
|
|
|
- foreach ($level as $k => $v) {
|
|
|
- $start = $i;
|
|
|
- $end = $v;
|
|
|
- $i = $end + $i;
|
|
|
- $end = $start + $end - 1;
|
|
|
- if ($index >= $start && $index <= $end) {
|
|
|
- if (isset($level_data[$k])) {
|
|
|
- $level_info = $level_data[$k];
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isset($level_info)) {
|
|
|
- $where['level_id'] = $level_info['id'];
|
|
|
- } else {
|
|
|
- Dever::alert('难度获取失败');
|
|
|
- }
|
|
|
+ $where['level_id'] = $this->getLevel($level_ids, $index);
|
|
|
}
|
|
|
|
|
|
$data = Dever::db('question/info')->getAll($where);
|
|
@@ -131,6 +107,61 @@ class Api
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 获取等级id
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function getLevel($level_ids, $index)
|
|
|
+ {
|
|
|
+
|
|
|
+ $level = explode("\r\n", $level_ids);
|
|
|
+ $level_data = Dever::db('question/level')->all();
|
|
|
+ $index = $index + 1;
|
|
|
+ $level_info = array();
|
|
|
+ $i = 1;
|
|
|
+ foreach ($level as $v) {
|
|
|
+ $v = explode(',', $v);
|
|
|
+ $start = $i;
|
|
|
+ $end = $v[1];
|
|
|
+ $i = $end + $i;
|
|
|
+ $end = $start + $end - 1;
|
|
|
+ if ($index >= $start && $index <= $end) {
|
|
|
+ if (isset($level_data[$v[0]])) {
|
|
|
+ $level_info = $level_data[$v[0]];
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 3,3,4形式,已废弃
|
|
|
+ $level = explode(',', $level_ids);
|
|
|
+ $level_data = Dever::db('question/level')->getAll();
|
|
|
+ $index = $index + 1;
|
|
|
+ $level_info = array();
|
|
|
+ $i = 1;
|
|
|
+ foreach ($level as $k => $v) {
|
|
|
+ $start = $i;
|
|
|
+ $end = $v;
|
|
|
+ $i = $end + $i;
|
|
|
+ $end = $start + $end - 1;
|
|
|
+ if ($index >= $start && $index <= $end) {
|
|
|
+ if (isset($level_data[$k])) {
|
|
|
+ $level_info = $level_data[$k];
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+ if (isset($level_info)) {
|
|
|
+ return $level_info['id'];
|
|
|
+ } else {
|
|
|
+ Dever::alert('难度获取失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
* 初始化用户信息
|
|
@@ -148,7 +179,7 @@ class Api
|
|
|
if ($this->exam['continue'] == 1) {
|
|
|
|
|
|
$where['where_status'] = 4;
|
|
|
- } elseif ($this->exam['continue'] == 2) {
|
|
|
+ } elseif ($this->exam['continue'] >= 2) {
|
|
|
|
|
|
$where['where_status'] = 3;
|
|
|
}
|
|
@@ -157,7 +188,7 @@ class Api
|
|
|
|
|
|
$finish = Dever::db('question/user')->getFinish($where);
|
|
|
|
|
|
- if ($this->exam['continue'] == 2 && $finish && $finish['status'] == 3) {
|
|
|
+ if ($this->exam['continue'] == 3 && $finish && $finish['status'] == 3) {
|
|
|
|
|
|
$this->user = $finish;
|
|
|
return;
|
|
@@ -249,26 +280,25 @@ class Api
|
|
|
{
|
|
|
$this->getUser();
|
|
|
|
|
|
- $this->exam = Dever::db('question/exam')->one($this->user['exam_id']);
|
|
|
-
|
|
|
return $this->getQuestionInfo();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 获取最新一条用户参与信息
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function getUser()
|
|
|
{
|
|
|
$uid = $this->getUid();
|
|
|
-
|
|
|
- $id = Dever::input('user_data_id');
|
|
|
-
|
|
|
- $this->user = Dever::db('question/user')->one($id);
|
|
|
+
|
|
|
+ $this->user = Dever::db('question/user')->get(array('where_uid' => $uid));
|
|
|
|
|
|
if (!$this->user) {
|
|
|
Dever::alert('错误的用户信息');
|
|
|
}
|
|
|
|
|
|
- if ($this->user && $uid != $this->user['uid']) {
|
|
|
- Dever::alert('错误的用户信息');
|
|
|
- }
|
|
|
+ $this->exam = Dever::db('question/exam')->one($this->user['exam_id']);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -285,7 +315,7 @@ class Api
|
|
|
Dever::alert('已经答完所有题目');
|
|
|
}
|
|
|
|
|
|
- if ($this->exam['continue'] == 2 && $this->user['status'] == 3) {
|
|
|
+ if ($this->exam['continue'] >= 2 && $this->user['status'] == 3) {
|
|
|
Dever::alert('不能继续答题');
|
|
|
}
|
|
|
|
|
@@ -337,17 +367,14 @@ class Api
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 开始答题接口: api.submit?question_id=1&option=0&user_data_id=1&uid=1&next=1 获取下一题的信息
|
|
|
+ * 开始答题接口: api.submit?question_id=1&option=0&uid=1
|
|
|
* 返回参数:status 2为进行中 3答题错误 4答题正确
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function submit()
|
|
|
{
|
|
|
- $id = Dever::input('user_data_id');
|
|
|
- if (!$id) {
|
|
|
- Dever::alert('错误的用户信息');
|
|
|
- }
|
|
|
+ $this->getUser();
|
|
|
|
|
|
$question_id = Dever::input('question_id');
|
|
|
if (!$question_id) {
|
|
@@ -355,18 +382,33 @@ class Api
|
|
|
}
|
|
|
$option = Dever::input('option', 0);
|
|
|
|
|
|
- $one['user_id'] = $id;
|
|
|
+ $one['user_id'] = $this->user['id'];
|
|
|
$one['uid'] = Dever::input('uid');
|
|
|
$one['info_id'] = Dever::input('question_id');
|
|
|
$one = Dever::db('question/user_answer')->one($one);
|
|
|
if ($one) {
|
|
|
- $this->user = Dever::db('question/user')->one($id);
|
|
|
$update['status'] = $this->user['status'];
|
|
|
} else {
|
|
|
+ if ($this->exam['continue'] >= 2 && $this->exam['continue_times'] > 0) {
|
|
|
+ $cur = time();
|
|
|
+
|
|
|
+ $times = $this->exam['continue_times'];
|
|
|
+
|
|
|
+ if ($cur - $this->user['cdate'] > $times) {
|
|
|
+
|
|
|
+ $option = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$this->hidden = false;
|
|
|
- $data = $this->getInfo();
|
|
|
+ $data = $this->getQuestionInfo();
|
|
|
|
|
|
+ if ($option == -1) {
|
|
|
+
|
|
|
+ $data['content'][$option] = array();
|
|
|
+ $data['content'][$option]['score'] = 0;
|
|
|
+ $data['content'][$option]['title'] = '超时';
|
|
|
+ }
|
|
|
if (!isset($data['content'][$option])) {
|
|
|
Dever::alert('错误的选项信息');
|
|
|
}
|
|
@@ -392,7 +434,7 @@ class Api
|
|
|
|
|
|
$this->setRanking($update['score']);
|
|
|
}
|
|
|
- if ($this->exam['continue'] == 2 && $data['content'][$option]['score'] == 0) {
|
|
|
+ if ($this->exam['continue'] >= 2 && $data['content'][$option]['score'] == 0) {
|
|
|
|
|
|
$update['status'] = 3;
|
|
|
|
|
@@ -414,11 +456,14 @@ class Api
|
|
|
$result['status'] = $update['status'];
|
|
|
$result['question_id'] = $question_id;
|
|
|
$result['option'] = $option;
|
|
|
- $result['user_data_id'] = $id;
|
|
|
-
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 积分榜单
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
private function setRanking($score)
|
|
|
{
|
|
|
$ranking = Dever::db('question/ranking')->one(array
|
|
@@ -454,13 +499,109 @@ class Api
|
|
|
public function continue()
|
|
|
{
|
|
|
$this->getUser();
|
|
|
- $update['where_id'] = $this->user['id'];
|
|
|
- $update['status'] = 2;
|
|
|
- Dever::db('question/user')->update($update);
|
|
|
+
|
|
|
+ if ($this->user['status'] == 3) {
|
|
|
+
|
|
|
+ $this->checkContinue();
|
|
|
+
|
|
|
+ $update['where_id'] = $this->user['id'];
|
|
|
+ if ($this->user['index'] >= $this->user['num']) {
|
|
|
+ $update['status'] = 2;
|
|
|
+ } else {
|
|
|
+ $update['status'] = 2;
|
|
|
+ }
|
|
|
+ Dever::db('question/user')->update($update);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 无限复活接口 慎用
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function go_continue()
|
|
|
+ {
|
|
|
+ $this->getUser();
|
|
|
+
|
|
|
+ if ($this->user['status'] == 3) {
|
|
|
+ $update['where_id'] = $this->user['id'];
|
|
|
+
|
|
|
+ if ($this->user['index'] >= $this->user['num']) {
|
|
|
+ $update['status'] = 2;
|
|
|
+ } else {
|
|
|
+ $update['status'] = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ Dever::db('question/user')->update($update);
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 验证当前的复活次数够不够
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function checkContinue()
|
|
|
+ {
|
|
|
+ $continue_num = $this->exam['continue_num'];
|
|
|
+ if ($continue_num > 0) {
|
|
|
+ $continue_num_user = $this->exam['continue_num_user'];
|
|
|
+ $continue_num_type = $this->exam['continue_num_type'];
|
|
|
+ $continue_num_type_times = $this->exam['continue_num_type_times'];
|
|
|
+
|
|
|
+ $where['exam_id'] = $this->user['exam_id'];
|
|
|
+ if ($continue_num_user == 1) {
|
|
|
+ $where['uid'] = $this->user['uid'];
|
|
|
+ } elseif ($continue_num_user == 2) {
|
|
|
+ $where['user_id'] = $this->user['id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $continue = Dever::db('question/continue')->one($where);
|
|
|
+
|
|
|
+ if ($continue) {
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ if ($continue_num_type == 1) {
|
|
|
+
|
|
|
+ $continue_num_type_times = 0;
|
|
|
+ $date = Dever::maketime(date('Y-m-d 00:00:00', strtotime("+1 day", $continue['cdate'])));
|
|
|
+ if ($time >= $date) {
|
|
|
+ $continue['num'] = 0;
|
|
|
+ }
|
|
|
+ } elseif ($continue_num_type == 2) {
|
|
|
+
|
|
|
+ $continue_num_type_times = $continue_num_type_times * 3600;
|
|
|
+ } elseif ($continue_num_type == 3) {
|
|
|
+
|
|
|
+ $continue_num_type_times = $continue_num_type_times * 86400;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($continue_num_type_times > 0 && $time - $continue['cdate'] >= $continue_num_type_times) {
|
|
|
+ $continue['num'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($continue['num'] < $continue_num) {
|
|
|
+
|
|
|
+ $update['where_id'] = $continue['id'];
|
|
|
+ $update['num'] = $continue['num'] + 1;
|
|
|
+ Dever::db('question/continue')->update($update);
|
|
|
+ } else {
|
|
|
+ Dever::alert('无法复活');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $insert['exam_id'] = $this->user['exam_id'];
|
|
|
+ $insert['uid'] = $this->user['uid'];
|
|
|
+ $insert['user_id'] = $this->user['id'];
|
|
|
+ $insert['num'] = 1;
|
|
|
+ Dever::db('question/continue')->insert($insert);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 重新挑战接口,重新开始,当前结束
|
|
|
*
|