|
@@ -40,11 +40,7 @@ class Api
|
|
|
} else {
|
|
|
$result['info'][$k]['answer'] = '';
|
|
|
}
|
|
|
- if ($v['type'] >= 11) {
|
|
|
- $result['info'][$k]['content'] = Dever::array_decode($result['info'][$k]['content']);
|
|
|
- } else {
|
|
|
- unset($result['info'][$k]['content']);
|
|
|
- }
|
|
|
+ $result['info'][$k]['content'] = $this->getContent($v['type'], $v['content']);
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -62,22 +58,40 @@ class Api
|
|
|
if ($survey_id && $survey_answer) {
|
|
|
$survey_id = explode('||', $survey_id);
|
|
|
$survey_answer = explode('||', $survey_answer);
|
|
|
+ $num = 1;
|
|
|
+ $total = count($survey_id);
|
|
|
+
|
|
|
foreach ($survey_id as $k => $v) {
|
|
|
- $answer = Dever::db('survey/user_answer')->one(array('info_id' => $v, 'uid' => $uid));
|
|
|
+ $info = Dever::db('survey/info')->one($v);
|
|
|
|
|
|
- if ($answer) {
|
|
|
- Dever::db('survey/user_answer')->update(array('where_id' => $answer['id'], 'value' => $survey_answer[$k]));
|
|
|
- } else {
|
|
|
- Dever::db('survey/user_answer')->insert(array('info_id' => $v, 'uid' => $uid, 'value' => $survey_answer[$k]));
|
|
|
+ if ($info) {
|
|
|
+ if ($info['must'] == 1 && !isset($survey_answer[$k]) && !$survey_answer[$k]) {
|
|
|
+ $page = false;
|
|
|
+ Dever::alert($info['name'] . '未填写答案');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if ($page_number > 0) {
|
|
|
- $info = Dever::db('survey/user')->one(array('uid' => $uid));
|
|
|
- if ($info) {
|
|
|
- Dever::db('survey/user')->update(array('where_id' => $info['id'], 'index' => $page_number + 1));
|
|
|
- }
|
|
|
+ foreach ($survey_id as $k => $v) {
|
|
|
+ $info = Dever::db('survey/info')->one($v);
|
|
|
+ if ($info) {
|
|
|
+ $answer = Dever::db('survey/user_answer')->one(array('info_id' => $v, 'uid' => $uid));
|
|
|
+
|
|
|
+ if ($answer) {
|
|
|
+ Dever::db('survey/user_answer')->update(array('where_id' => $answer['id'], 'value' => $survey_answer[$k], 'product_id' => $product_id));
|
|
|
+ } else {
|
|
|
+ Dever::db('survey/user_answer')->insert(array('info_id' => $v, 'uid' => $uid, 'value' => $survey_answer[$k], 'product_id' => $product_id));
|
|
|
+ $num++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if ($num == $total) {
|
|
|
+ $user = Dever::db('survey/user')->one(array('uid' => $uid));
|
|
|
+ if ($user) {
|
|
|
+ Dever::db('survey/user')->update(array('where_id' => $user['id'], 'index' => $user['index'] + 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|
|
@@ -88,8 +102,92 @@ class Api
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function view($uid, $product_id, $page_number, $survey_id, $survey_answer)
|
|
|
+ public function view($uid, $product_id)
|
|
|
+ {
|
|
|
+ $product = Dever::config('base', 'project')->product;
|
|
|
+
|
|
|
+ $user = Dever::db('survey/user')->one(array('uid' => $uid));
|
|
|
+
|
|
|
+ $data['userinfo'] = Dever::db('passport/user')->one($uid);
|
|
|
+ $data['product'] = Dever::db($product)->one($product_id);
|
|
|
+
|
|
|
+ $data['info'] = Dever::db('survey/info')->state(array('uid' => $uid, 'product_id' => $product_id));
|
|
|
+
|
|
|
+ $data['question'] = array();
|
|
|
+
|
|
|
+ $data['page_number'] = 1;
|
|
|
+ $i = 1;
|
|
|
+ foreach ($data['info'] as $k => $v) {
|
|
|
+ if ($v['page_number'] > $data['page_number']) {
|
|
|
+ $data['page_number'] = $v['page_number'];
|
|
|
+ }
|
|
|
+ $v['content'] = $this->getContent($v['type'], $v['content']);
|
|
|
+
|
|
|
+ $answer = Dever::db('survey/user_answer')->one(array('uid' => $uid, 'info_id' => $v['id']));
|
|
|
+ if ($answer) {
|
|
|
+ if (($v['type'] == 3 || $v['type'] == 4) && strstr($answer['value'], 'http')) {
|
|
|
+ $answer['value'] = $this->getImg($answer['id'], $answer['value']);
|
|
|
+ } elseif ($v['type'] == 12 || $v['type'] == 13) {
|
|
|
+ $v['content'] = $this->getOption($answer['id'], $answer['value'], $v['content']);
|
|
|
+ }
|
|
|
+ $v['answer'] = $answer['value'];
|
|
|
+ } else {
|
|
|
+ $v['answer'] = '未作答';
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['question'][$v['page_number']][$i] = $v;
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($user['index'] >= $data['page_number']) {
|
|
|
+
|
|
|
+ $data['page'] = '100%';
|
|
|
+ } else {
|
|
|
+ $num = ceil(($user['index'] / $data['page_number']) * 100);
|
|
|
+ $data['page'] = $num . '%';
|
|
|
+ }
|
|
|
+
|
|
|
+ return Dever::render('home', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getOption($id, $answer, $option)
|
|
|
{
|
|
|
+ $array = explode(',', $answer);
|
|
|
+ $total = count($option) - 1;
|
|
|
+ foreach ($array as $k => $v) {
|
|
|
+ if (is_numeric($v)) {
|
|
|
+ $v = $v - 1;
|
|
|
+ if (isset($option[$v])) {
|
|
|
+ $option[$v]['checked'] = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $option[$total]['checked'] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $option;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getImg($id, $answer)
|
|
|
+ {
|
|
|
+ $result = '<a class="dever-img" id="answer_'.$id.'">';
|
|
|
+ $array = explode(',', $answer);
|
|
|
+ foreach ($array as $k => $v) {
|
|
|
+ $result .= '<img layer-src="'.$v.'" src="' . $v . '" style="width:200px;"/> ';
|
|
|
+ }
|
|
|
+
|
|
|
+ $result .= '</a>';
|
|
|
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getContent($type, $content)
|
|
|
+ {
|
|
|
+ if ($type >= 11) {
|
|
|
+ $content = Dever::array_decode($content);
|
|
|
+ } else {
|
|
|
+ $content = array();
|
|
|
+ }
|
|
|
+ return $content;
|
|
|
}
|
|
|
}
|