public static function toupiaoAjax($author_openid, $vote_openid) { $qingshi_vote = self::findOne(['vote_openid' => $vote_openid]); if (empty($qingshi_vote)) { $qingshi_vote = new \app\models\MQingshiVote(); } else { //已经投过一次票了,提示用户已投过票,只能每人只能投一次票哟 return \yii\helpers\Json::encode(['code' => 11]); } $qingshi_vote->author_openid = $author_openid; $qingshi_vote->vote_openid = $vote_openid; $qingshi_vote->save(false); //写入到投票表中; $qingshi_score = \app\models\MQingshiScore::findOne(['author_openid' => $author_openid]); U::W($qingshi_score); if (empty($qingshi_score)) { $qingshi_score = new \app\models\MQingshiScore(); } $qa = \app\models\MQingshiAuthor::findOne(['author_openid' => $author_openid]); $qingshi_score->author_openid = $author_openid; $qingshi_score->score = $qingshi_score->score + 1; $qingshi_score->status = 0; $qingshi_score->create_time = $qa->create_time; $qingshi_score->save(false); return \yii\helpers\Json::encode(['code' => 0]); }
/** * Finds the MQingshiAuthor model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MQingshiAuthor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MQingshiAuthor::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionQingshiVote() { $this->layout = false; $id = $_GET["id"]; //$gh_id = U::getSessionParam('gh_id'); $gh_id = 'gh_03a74ac96138'; $openid = U::getSessionParam('openid'); $wx_user = \app\models\MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if (empty($wx_user) || $wx_user->subscribe === 0) { return $this->render('need_subscribe'); } $qingshi_author = \app\models\MQingshiAuthor::findOne(['id' => $id]); return $this->render('qingshi-vote', ['observer' => $wx_user, 'qingshi_author' => $qingshi_author]); }
<ul class="table-view"> <li class="table-view-cell media"> <div class="media-body"> 名次 </div> <span class="badge" style="font-size: 12pt"> 所得票数 </span> </li> <?php foreach ($votes as $vote) { $top++; $author = \app\models\MQingshiAuthor::findOne(['author_openid' => $vote->author_openid]); ?> <li class="table-view-cell media"> <a data-ignore="push" class="navigate-right" href="<?php echo \yii\helpers\Url::to(['qingshi-vote', 'id' => $author->id]); ?> "> <sapn class="pull-left" style="font-size: 18pt; font-weight: bolder;color:green;"> <?php echo $top; ?> . </sapn>