| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 | <?phpnamespace Cas\Module;use KIF\Verify;use Cas\Dao\LotteryEvents;use KIF\Core\Config;use Cas\Dao\LotteryPrize;use KIF\Cache\Memcached;use KIF\Dao\SqlHelper;use Cas\Dao\LotteryPrizeVirtualData;use Cas\Dao\LotteryData;use Cas\Module\LotteryLog;use Cas\Dao\LotteryEventsLog as DLog;use Cas\Module\Lottery;use Cas\Dao\LotteryEventsLetters;use Cas\Dao\LotteryEventsUserLetters;use Cas\Dao\LotteryEventsUserPrizeData;use KIF\Data\ResultWrapper;use KIF\Core\Request;use Cas\Dao\LotteryEventsVote;use Cas\Dao\LotteryEventsVoteUserLog;/** *	 *  投票 [模型] * * @author lihuanchun */class LotteryEventsTypeVote  {		private $uid;	private $events_id;	private $objMlottery;	private $objMLotteryLog;	private $thisTime;	private $objMLotteryEventsLimitations;	private $objDLotteryEventsVote;	private $objDLotteryEventsVoteUserLog;		public function __construct($uid=null , $events_id=null ) {		$this->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("取消成功");	}}
 |