123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace Cas\Module;
- use KIF\Core\Request;
- use KIF\Page\Page;
- use KIF\Verify;
- use Cas\Dao\LotteryEvents;
- use KIF\Core\Config;
- use KIF\Image;
- use Cas\Dao\LotteryPrize;
- use KIF\Cache\Memcached;
- use KIF\Dao\SqlHelper;
- /**
- * 活动限制
- *
- * @author lihuanchun
- */
- class LotteryEventsLimitations {
-
- private $objMemcached;
-
- private $objDLotteryEvents;
-
- private $objDLotteryPrize;
-
- private $thisTime;
-
- public function __construct() {
- $this->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;
- }
-
-
-
- }
|