LotteryEventsLimitations.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace Cas\Module;
  3. use KIF\Core\Request;
  4. use KIF\Page\Page;
  5. use KIF\Verify;
  6. use Cas\Dao\LotteryEvents;
  7. use KIF\Core\Config;
  8. use KIF\Image;
  9. use Cas\Dao\LotteryPrize;
  10. use KIF\Cache\Memcached;
  11. use KIF\Dao\SqlHelper;
  12. /**
  13. * 活动限制
  14. *
  15. * @author lihuanchun
  16. */
  17. class LotteryEventsLimitations {
  18. private $objMemcached;
  19. private $objDLotteryEvents;
  20. private $objDLotteryPrize;
  21. private $thisTime;
  22. public function __construct() {
  23. $this->objDLotteryEvents = new LotteryEvents();
  24. $this->objDLotteryPrize = new LotteryPrize();
  25. $this->thisTime = time();
  26. $this->objMemcached = new Memcached();
  27. }
  28. /**
  29. * 记录用户 活动参与次数(天)
  30. */
  31. public function setUserEventNum($uid,$event_id){
  32. $key = "lottery_{$uid}_{$event_id}_participation_user_num";
  33. $time = strtotime(date('Y-m-d',strtotime('+1 day')));
  34. $num = $this->objMemcached -> get($key);
  35. if(is_null($num)){
  36. $this->objMemcached -> set($key,1,$time);
  37. return true;
  38. }
  39. $this->objMemcached -> increment($key, 1);
  40. return true;
  41. }
  42. /**
  43. * 记录IP 活动参与次数(天)
  44. */
  45. public function setIpEventNum($ip,$event_id){
  46. $key = "lottery_{$ip}_{$event_id}_participation_ip_num";
  47. $time = strtotime(date('Y-m-d',strtotime('+1 day')));
  48. $num = $this->objMemcached -> get($key);
  49. if(is_null($num)){
  50. $this->objMemcached -> set($key,1,$time);
  51. return true;
  52. }
  53. $this->objMemcached -> increment($key, 1);
  54. return true;
  55. }
  56. /**
  57. * 记录 用户获奖次数
  58. */
  59. public function setUserWinningNum($uid,$event_id){
  60. $key = "lottery_{$uid}_{$event_id}_winning_user_num";
  61. $evetData = $this->objDLotteryEvents -> get($event_id);
  62. $num = $this->objMemcached -> get($key);
  63. if(is_null($num)){
  64. $this->objMemcached -> set($key,1,$evetData['end_time']);
  65. }
  66. $this->objMemcached -> increment($key, 1);
  67. return true;
  68. }
  69. /**
  70. * 记录 用户参与次数
  71. */
  72. public function setUserParticipationNum($uid,$event_id){
  73. $key = "lottery_{$uid}_{$event_id}_participation_user_all_num";
  74. $evetData = $this->objDLotteryEvents -> get($event_id);
  75. $num = $this->objMemcached -> get($key);
  76. if(is_null($num)){
  77. $this->objMemcached -> set($key,1,$evetData['end_time']);
  78. }
  79. $this->objMemcached -> increment($key, 1);
  80. return true;
  81. }
  82. /**
  83. * 判断 活动是否能参与
  84. * 1.验证IP 活动参与次数(天)
  85. * 2.验证用户 活动参与次数(天)
  86. * 3.验证用户获奖次数
  87. * 4.验证用户参与次数
  88. */
  89. public function ckEventRestrictions($uid,$ip,$event_id){
  90. $participation_user_num_key = "lottery_{$uid}_{$event_id}_participation_user_num";
  91. $participation_ip_num_key = "lottery_{$ip}_{$event_id}_participation_ip_num";
  92. $winning_user_num_Key = "lottery_{$uid}_{$event_id}_winning_user_num";
  93. $participation_user_all_num_Key = "lottery_{$uid}_{$event_id}_participation_user_all_num";
  94. $evetData = $this->objDLotteryEvents -> get($event_id);
  95. # 验证IP 活动参与次数(天)
  96. if($evetData['participation_user_num'] != 0){
  97. $num = $this->objMemcached -> get($participation_user_num_key);
  98. if(!is_null($num) && $num >= $evetData['participation_user_num']){
  99. //exit('UID活动参与次数');
  100. return false;
  101. }
  102. }
  103. # 验证用户 活动参与次数(天)
  104. if($evetData['participation_ip_num'] != 0){
  105. $num = $this->objMemcached -> get($participation_ip_num_key);
  106. if(!is_null($num) && $num >= $evetData['participation_ip_num']){
  107. //exit('IP参与限制');
  108. return false;
  109. }
  110. }
  111. # 验证用户获奖次数
  112. if($evetData['winning_user_num'] != 0){
  113. $num = $this->objMemcached -> get($winning_user_num_Key);
  114. if(!is_null($num) && $num > $evetData['winning_user_num']){
  115. //exit('UID获奖次数限制');
  116. return false;
  117. }
  118. }
  119. # 验证用户参与次数
  120. if($evetData['participation_user_all_num'] != 0){
  121. $num = $this->objMemcached -> get($participation_user_all_num_Key);
  122. if(!is_null($num) && $num > $evetData['participation_user_all_num']){
  123. //exit('验证用户参与次数');
  124. return false;
  125. }
  126. }
  127. return true;
  128. }
  129. }