uid = $uid; $this->events_id = $events_id; $this->objMlottery = new Lottery(); $this->objDLotteryEventsVote = new LotteryEventsVote(); $this->objDLotteryEventsVoteUserLog = new LotteryEventsVoteUserLog(); $this->objMLotteryLog = new LotteryLog($uid,$events_id); $this->thisTime = time(); $this->objMLotteryEventsLimitations = new LotteryEventsLimitations(); } /** * 获取当前“投票”信息 */ public function getEventsData(){ $data = $this->objMlottery->getOneLotteryEvents($this->events_id); $data['vote'] = $this->objDLotteryEventsVote-> getThisEventData($this->events_id); return $data; } /** * 参与投票 */ public function vote($vote_id){ $eventsData = $this->objMlottery->getOneLotteryEvents($this->events_id); # 活动是否开始 if($this->thisTime < $eventsData['begin_time'] || $this->thisTime > $eventsData['end_time']){ return ResultWrapper::fail('当前活动未开始'); } # 活动限制 if(!$this->objMLotteryEventsLimitations->ckEventRestrictions($this->uid,Request::ip(), $this->events_id)){ return ResultWrapper::fail('您不可以重复参与哦!'); } # 记录参与日志 $other = array( 'vote_id' => $vote_id, ); $this->objMLotteryLog ->addLog(DLog::LOG_TYPE_PARTICIPATION, $other); # 记录用户 $this->objMLotteryEventsLimitations->setUserEventNum($this->uid, $this->events_id); // 记录用户参与UID(天) $this->objMLotteryEventsLimitations->setIpEventNum(Request::ip(), $this->events_id);// 记录用户参与IP(天) $this->objMLotteryEventsLimitations->setUserParticipationNum($this->uid, $this->events_id); // 记录用户参与次数 # 修改数量 $this->objDLotteryEventsVote ->upNum($vote_id); # 记录用户的投票日志中 $info = array( 'events_id' => $this->events_id, 'vote_id' => $vote_id, 'uid' => $this->uid ); $this->objDLotteryEventsVoteUserLog ->add($info); #######用户行为记录######## #用户抽中奖品 $allVoteData = $this->objDLotteryEventsVote ->getThisEventData($this->events_id); $other = array( '投票:' => $allVoteData[$vote_id]['title'], ); $this->objMLotteryLog ->addUserParticipateLog($other); ######################### return ResultWrapper::success('投票成功'); } /** * 取消投票 * @param unknown $vote_id */ public function cancelVote($vote_id) { $this->objDLotteryEventsVote->decrNum($vote_id); $condition = array( 'events_id' => $this->events_id, 'vote_id' => $vote_id, 'uid' => $this->uid, ); $result = $this->objDLotteryEventsVoteUserLog->delete($condition); if (!$result) { return ResultWrapper::fail("取消失败"); } return ResultWrapper::success("取消成功"); } }