/** * 设置测试次数 * @param integer $uid */ public function setTestCount($uid) { $condition['uid'] = $uid; $count = Survey::find()->where($condition)->count(); $testing_count = Survey::find()->where($condition)->sum('answer_count'); $model_UserProfile = UserProfile::findOne($uid); $model_UserProfile ? null : ($model_UserProfile = new UserProfile()); $model_UserProfile->uid = $uid; $model_UserProfile->test_count = $count; $model_UserProfile->testing_count = $testing_count; return $model_UserProfile->save(); }
public function query($params) { $query = Survey::find(); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $query; } // ZCommonFun::print_r_debug($this->attributes); $query->andFilterWhere(['id' => $this->id, 'tax' => $this->tax, 'uid' => $this->uid, 'theme' => $this->theme, 'theme_mobile' => $this->theme_mobile, 'is_publish' => $this->is_publish, 'created' => $this->created, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'answer_count' => $this->answer_count, 'visit_count' => $this->visit_count, 'is_public' => $this->is_public, 'is_statistics_public' => $this->is_statistics_public, 'max_answer_count' => $this->max_answer_count, 'is_share_template' => $this->is_share_template, 'answer_total_time' => $this->answer_total_time, 'answer_average_time' => $this->answer_average_time, 'answer_limit_time' => $this->answer_limit_time, 'reward_total' => $this->reward_total, 'reward_average' => $this->reward_average, 'reward_count' => $this->reward_count]); $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'pass', $this->pass]); return $query; }
case 1: $row_url = Yii::$app->urlManager->createUrl(['answer/step1', 'id' => $row->id]); break; case 2: case 3: $row_url = Yii::$app->urlManager->createUrl(['answer/step2-answer2', 'id' => $row->id]); break; default: $row_url = ''; break; } $row_ur_done = Yii::$app->urlManager->createUrl(['survey/done', 'id' => $row->id]); //发布 $row_ur_done_publish = Yii::$app->urlManager->createUrl(['survey/done', 'is_ajax' => 1, 'id' => $row->id]); $row_ur_change = Yii::$app->urlManager->createUrl(['survey/step2', 'id' => $row->id]); $image = common\models\Survey::getImageUrl($row); ?> <dl> <a href="<?php echo $row_url; ?> "> <dt> <img src="<?php echo $image; ?> " alt="<?php echo $row->title; ?> ">
/** * 推荐 * * @return \yii\web\Response */ public function actionRecommend($id, $op) { $this->layout = false; $model = Survey::findOne($id); if (ZCommonSessionFun::get_user_id() < 1) { ZCommonFun::output_json(null, -1, '请登录'); } if (ZCommonSessionFun::get_role() != 1) { ZCommonFun::output_json(null, 2, '管理员才能操作'); } // 没有找到 if (!$model) { ZCommonFun::output_json(null, 1, '测试不存在'); $model = new Survey(); } // 推荐 $model->is_top = $op == 1 ? $_SERVER['REQUEST_TIME'] : 0; if ($model->save()) { ZCommonFun::output_json(null, 0, '操作成功'); } ZCommonFun::output_json(null, -2, '操作失败'); }
/** * 分数型问题回答2 */ public function actionStep2Answer2($id) { $this->layout = false; $model = Survey::findOne($id); if (!$model) { //没找到 $model = new Survey(); } if ($model->is_publish < 1) { $this->popupMessage($model->title . '未发布,不能测试'); exit; } $data = $model->FindAllQuestionsOptions($id); // ZCommonFun::print_r_debug($_POST); // exit; $posts = Yii::$app->request->post(); $error = ''; if (isset($posts['name'])) { is_array($posts['options']) ?: ($posts['options'] = array()); $op = count($posts['options']) > 0 ? true : false; $res = isset($posts['res']) ? intval($posts['res']) : 0; $res_model_SurveyResulte = $res > 0 ? SurveyResulte::findOne($res) : null; if ($res_model_SurveyResulte && $res_model_SurveyResulte->s_id == $id) { } else { $res_model_SurveyResulte = null; } $total_score = 0; $save = 0; $result = null; //保存结果 $transaction = Yii::$app->db->beginTransaction(); try { $name = isset($posts['name']) ? $posts['name'] : ''; $year = isset($posts['birth']['year']) ? $posts['birth']['year'] : 2015; $month = isset($posts['birth']['month']) ? $posts['birth']['month'] : '01'; $day = isset($posts['birth']['day']) ? $posts['birth']['day'] : '01'; $constellation = isset($posts['constellation']) ? intval($posts['constellation']) : 0; $constellation = $constellation > 0 && $constellation < 13 ? $constellation : 0; $birth = $year . '-' . $month . '-' . $day; $birth = date('Y-m-d', strtotime($birth)); $model_AnswerUser = new AnswerUser(); $model_AnswerUser->sid = $id; $model_AnswerUser->table = 'survey_resulte'; $res_model_SurveyResulte ? $model_AnswerUser->table_id = $res_model_SurveyResulte->sr_id : null; $model_AnswerUser->answer_name = $name; $model_AnswerUser->answer_age = $birth; $model_AnswerUser->constellation = $constellation; $model_AnswerUser->ip = self::getUserIP(); if (!$model_AnswerUser->save()) { $error = '用户操作失败'; $transaction->rollBack(); } else { foreach ($data['options'] as $key => $value) { foreach ($value as $option) { foreach ($posts['options'] as $question_id => $row) { //找到选项 if ($option->qo_id = $row[0]) { $model_Answer = new Answer(); $model_Answer->table_id = $id; $model_Answer->question_id = $option->question_id; $model_Answer->qo_id = $row[0]; $model_Answer->answer_score += $option->option_score; $model_Answer->au_id = $model_AnswerUser->au_id; $total_score += $model_Answer->answer_score; $model_Answer->save() ? $save++ : null; } } } } if ($save > 0) { $model_SurveyResulte = new SurveyResulte(); //如果直接选择了答案 if ($model_AnswerUser->table == 'survey_resulte' && $model_AnswerUser->table_id > 0) { $result = $res_model_SurveyResulte; // } else { $result = $model_SurveyResulte->getStep2Result($id, $model_AnswerUser->answer_score); } if ($result && !$res_model_SurveyResulte) { //保存回答者结果,防止用户更改数据导致结果丢失 $mode_AnswerSurveyResulte = new AnswerSurveyResulte(); $mode_AnswerSurveyResulte->attributes = $result->attributes; $mode_AnswerSurveyResulte->save(); $model_AnswerUser->table == 'answer_survey_resulte'; $model_AnswerUser->table_id = $mode_AnswerSurveyResulte->answer_sr_id; } $model_AnswerUser->save(); $transaction->commit(); //设置测试数量 $model->setAnswerCount($id); $model_UserProfile = new UserProfile(); $model_UserProfile->setTestCount($model_AnswerUser->uid); return $this->redirect(['resulte', 'au_id' => $model_AnswerUser->au_id]); } else { $error = '没有选项'; $transaction->rollBack(); } } } catch (\Exception $e) { $error = '事物异常'; ZCommonFun::print_r_debug($e); $transaction->rollBack(); } } $model_Users = null; $model_UsersProfile = null; if ($model->uid) { $zhao_condition['uid'] = $model->uid; $model_Users = User::findOne($zhao_condition); $model_UsersProfile = UserProfile::findOne($zhao_condition); } !$model_Users ? $model_Users = new User() : ''; !$model_UsersProfile ? $model_UsersProfile = new UserProfile() : ''; $model_UsersProfile->uid = $model->uid; // echo $error; // exit; // ZCommonFun::print_r_debug($result); $model_SurveyOperation = new SurveyOperation(); $models_SurveyOperation = $model_SurveyOperation->getIsTop(); return $this->render('step2answer3', ['models_SurveyOperation' => $models_SurveyOperation, 'data' => $data, 'model' => $model, 'error' => $error, 'posts' => $posts, 'image' => Survey::getImageUrl($model), 'model_Users' => $model_Users, 'model_UsersProfile' => $model_UsersProfile, 'randSurvey' => $this->getRandSurvey()]); // return $this->render('step2answer',[ // 'data'=>$data, // 'model'=>$model, // 'error'=>$error, // 'posts'=>$posts, // 'image'=>Survey::getImageUrl($model), // 'model_Users'=>$model_Users, // 'model_UsersProfile'=>$model_UsersProfile, // ]); }
<a class="btn_bg" href="<?php echo Yii::$app->urlManager->createUrl(['survey/step2','id'=>$model->id]);?>" id="prev-step">上一步</a> <br /> <a class="btn_bg" href="<?php echo Yii::$app->urlManager->createUrl(['survey/done','id'=>$model->id]);?>"> <input type="button" value="预览"> </a> <br /> */ ?> <div id="image-wrap"> <?php if (isset($model->images->image) && !empty($model->images->image)) { echo '<img src="', Survey::getImageUrl($model), '"/>'; } ?> </div> <?php ActiveForm::end(); ?> <p class="text-hint"><?php echo $text_hint; ?> </p> </section>