objDLotteryEvents = new LotteryEvents(); $this->objDLotteryPrize = new LotteryPrize(); $this->thisTime = time(); $this->objMemcached = new Memcached(); } /** * 记录用户 活动参与次数(天) */ public function setUserEventNum($uid,$event_id){ $key = "lottery_{$uid}_{$event_id}_participation_user_num"; $time = strtotime(date('Y-m-d',strtotime('+1 day'))); $num = $this->objMemcached -> get($key); if(is_null($num)){ $this->objMemcached -> set($key,1,$time); return true; } $this->objMemcached -> increment($key, 1); return true; } /** * 记录IP 活动参与次数(天) */ public function setIpEventNum($ip,$event_id){ $key = "lottery_{$ip}_{$event_id}_participation_ip_num"; $time = strtotime(date('Y-m-d',strtotime('+1 day'))); $num = $this->objMemcached -> get($key); if(is_null($num)){ $this->objMemcached -> set($key,1,$time); return true; } $this->objMemcached -> increment($key, 1); return true; } /** * 记录 用户获奖次数 */ public function setUserWinningNum($uid,$event_id){ $key = "lottery_{$uid}_{$event_id}_winning_user_num"; $evetData = $this->objDLotteryEvents -> get($event_id); $num = $this->objMemcached -> get($key); if(is_null($num)){ $this->objMemcached -> set($key,1,$evetData['end_time']); } $this->objMemcached -> increment($key, 1); return true; } /** * 记录 用户参与次数 */ public function setUserParticipationNum($uid,$event_id){ $key = "lottery_{$uid}_{$event_id}_participation_user_all_num"; $evetData = $this->objDLotteryEvents -> get($event_id); $num = $this->objMemcached -> get($key); if(is_null($num)){ $this->objMemcached -> set($key,1,$evetData['end_time']); } $this->objMemcached -> increment($key, 1); return true; } /** * 判断 活动是否能参与 * 1.验证IP 活动参与次数(天) * 2.验证用户 活动参与次数(天) * 3.验证用户获奖次数 * 4.验证用户参与次数 */ public function ckEventRestrictions($uid,$ip,$event_id){ $participation_user_num_key = "lottery_{$uid}_{$event_id}_participation_user_num"; $participation_ip_num_key = "lottery_{$ip}_{$event_id}_participation_ip_num"; $winning_user_num_Key = "lottery_{$uid}_{$event_id}_winning_user_num"; $participation_user_all_num_Key = "lottery_{$uid}_{$event_id}_participation_user_all_num"; $evetData = $this->objDLotteryEvents -> get($event_id); # 验证IP 活动参与次数(天) if($evetData['participation_user_num'] != 0){ $num = $this->objMemcached -> get($participation_user_num_key); if(!is_null($num) && $num >= $evetData['participation_user_num']){ //exit('UID活动参与次数'); return false; } } # 验证用户 活动参与次数(天) if($evetData['participation_ip_num'] != 0){ $num = $this->objMemcached -> get($participation_ip_num_key); if(!is_null($num) && $num >= $evetData['participation_ip_num']){ //exit('IP参与限制'); return false; } } # 验证用户获奖次数 if($evetData['winning_user_num'] != 0){ $num = $this->objMemcached -> get($winning_user_num_Key); if(!is_null($num) && $num > $evetData['winning_user_num']){ //exit('UID获奖次数限制'); return false; } } # 验证用户参与次数 if($evetData['participation_user_all_num'] != 0){ $num = $this->objMemcached -> get($participation_user_all_num_Key); if(!is_null($num) && $num > $evetData['participation_user_all_num']){ //exit('验证用户参与次数'); return false; } } return true; } }