<span><a href="<?php echo Yii::$app->urlManager->createUrl(['act/hometown/index']); ?> ">活动详情</a></span> </li> <li class="nav_list <?php if (Yii::$app->controller->action->id == 'works') { echo 'nav_active'; } ?> "> <span><a href="<?php echo Yii::$app->urlManager->createUrl(['act/hometown/works']); ?> ">参与作品(<?php echo ActHometown::find()->where(['status' => 1])->count(); ?> )</a></span> </li> <li class="nav_list <?php if (Yii::$app->controller->action->id == 'top') { echo 'nav_active'; } ?> "> <span><a href="<?php echo Yii::$app->urlManager->createUrl(['act/hometown/top']); ?> ">排行榜</a></span> </li> </ul>
public function actionVote() { if (time() > strtotime($this->end_at)) { return json_encode(['status' => '0', 'msg' => '活动已经结束']); } $this->getWxUser(); if (Yii::$app->request->post()) { $id = Yii::$app->request->post('ActHometown')['id']; $info = ActHometown::find()->where(['id' => $id, 'status' => 1])->one(); if ($id && $info) { $today_vote = ActVoteLog::find()->where(['act_id' => $this->act_id, 'uid' => $this->wx_user['uid']])->andWhere(['>=', 'created_at', strtotime(date('Y-m-d'))])->andWhere(['<', 'created_at', strtotime(date('Y-m-d')) + 86400])->asArray()->all(); if ($today_vote) { if (count($today_vote) > 4) { return json_encode(['status' => '0', 'msg' => '每天最多有5票']); } $today_is_vote = false; foreach ($today_vote as $row) { if ($id == $row['act_info_id']) { $today_is_vote = true; break; } } if ($today_is_vote) { return json_encode(['status' => '0', 'msg' => '每人每天为同一作品最多投一票']); } } $info->scenario = 'vote'; $info->vote = $info->vote + 1; if ($info->save()) { $model = new ActVoteLog(['scenario' => 'create']); $model->act_id = $this->act_id; $model->act_info_id = $id; $model->uid = $this->wx_user['uid']; $model->ip = ip2long(Yii::$app->request->userIP); $model->user_agent = Yii::$app->request->headers['User-Agent']; $model->save(); return json_encode(['status' => '1', 'msg' => '投票成功']); } else { return json_encode(['status' => '0', 'msg' => '投票失败']); } } } }