-
- require_once (APP_ROOT . "./class/class_lib.php");
- require_once libfile ( 'class/StoreProcs' );
- pc_base::load_app_class('table_sub','',0 );
- /**
- * Big carousel
- * @author Administrator
- *
- */
- class lib_dzp_lottery extends app_lib {
- /**
- * Prize List
- */
- public $lottery = 'activity_lyq_lottery';
- /**
- * Prize Log Sheet
- */
- public $lottery_log = ' activity_lyq_lottery_log';
- /**
- * n prizes
- */
- private $level = array();
- /**
- * Prize information
- */
- private $lotteryArray = array();
- /***
- * Random number ending digits
- */
- private $max = 30000;
- /**
- * Category true: Default false: Palm Su
- */
- private $type=true;
- /**
- * Winning professional account
- */
- private $tel_zy=false;
- /**
- * Read configuration
- */
- public function load_setting () {
- $data=getcache('lyqdzp_setting');
- define('TIME', time()); //Current time
- define('L_START', strtotime($data['l_start'])); / /Registration start time
- define('L_END', strtotime($data['l_end'])); //Registration end time, -1 means yesterday 23:59:59
- define('L_DAY_START',$data['l_day_start ']); //Start time of each day
- define('L_DAY_END', $data['l_day_end']); //End time of each day
- define('L_DAY_CISHU', $data['l_day_cishu']); //Get every day Number of prizes
- define('L_CISHU', $data['l_cishu']);//Total number of prizes obtained
- define('L_MIN', 20);//Minimum LIFB coins
- define('L_LFB', $data[ 'l_lfb']);//Reduce Lifb coins
- define('L_ZY', $data['l_zy']); //Professional accounts
- define('L_QUANSHU', $data['l_quanshu']);//Circle Count, the number of rounds the big wheel starts to roll
- define('L_KONGJIANG', intval($data['l_kongjiang'])); //Probability of empty prize
- $host='www.****.com'; //Existing network
- if($_SERVER['HTTP_HOST']=='221.****0'){
- $host='221.*****'; //Test machine
- }elseif($_SERVER['HTTP_HOST ']=='125.com'){
- $host='125life.com';//Local
- }elseif(strpos($_SERVER['HTTP_HOST'],'192.168.')==0){
- $ host=$_SERVER['HTTP_HOST'].'/125e.com';//Local
- }
- define('L_SITE', 'http://'.$host.'/'); //Add / at the end of the domain name
- define('L_URL', L_SITE.'index.php');//Access address
-
- //Can only be accessed through flash address
- $s=L_SITE.'flash/dzp/i.swf';
- if(preg_replace ('/swf.*$/','swf',$_SERVER['HTTP_REFERER'])!=$s&&$this->type){
- exit('Dude, you have got enough, please pass the formal Way to win!');
- }
- $this->load();
- }
- /**
- * Blacklist
- */
- private $heimingdan = array();
- /**
- * Read prize configuration
- */
- public function load() {
- $this->setlottery ();
- $this->heimingdan = getcache ( 'tel', 'blanklist' );
- }
- private function setlottery() {
- $time=strtotime(date ('Y-m-d',TIME));
- $sql = "select u.*";
- $sql .= ", (select COUNT(l.lotteryid) from " . DB::table ( $this-> lottery_log ) . " AS l where u.lotteryid=l.lotteryid and l.iswinning='1')as num ";
- $sql .= " from " . DB::table ( $this->lottery ) . " AS u ";
- $sql .= " where 1 ";
- $sql .= " and u.isdisable='0' ";
- $sql .= " and u.time_start<='$time' ";
- $ sql .= " and u.time_end>='$time' ";
- $sql .= " ORDER BY u.listorder ";
- $d = DB::fetch_all ( $sql );
- $sum = 0;
- foreach ( $d as $r ) {
- $r ['sum_over'] = intval ( $r ['sum'] ) - intval ( $r ['num'] );
- if ($r ['sum'] > ; 0) {
- $sum += $r ['sum'];
- }
- $r['msg']=str_replace('{name}', $r['name'],$r['msg' ]);
- $this->lotteryArray [$r ['lotteryid']] = $r;
- }
- if($sum<100) $sum=1000;
- $m = 1;
- $probability = 0;
- $newsum=0;
- //80% empty prize + 20% prize
- $this->max = $sum + $sum * (L_KONGJIANG/100) / ((100-L_KONGJIANG)/100);
- foreach ( $this->lotteryArray as $r ) {
- if ($r ['sum'] > 0) {
- $newsum=$r ['sum'];
- if($r['probability']> 0){
- $probability=0;
- $probability=ceil($r ['sum']*100/$r['probability']);
- if($probability>0){
- $newsum=$probability;
- }
- }
- $this->level [$r ['lotteryid']] ['start'] = $m;
- $this->level [$r ['lotteryid']] ['end'] = $m + $newsum;
- $m = $m + $r ['sum'];
- }
- }
- }
- /**
- * Check whether the user has won the prize 0 Thank you for participating, others return prize data
- * @param array $user array(uid,tel,ip)
- */
- public function check($user) {
- if (intval ( $user ['uid'] ) < 1) {
- //Not logged in
- return 0;
- }
- if(intval(TIME)//You are here early, the event is still going on No start!
- return -21;
- }
- if(intval(TIME)>intval(L_END)){
- //The event time has passed, I am very sorry, thank you!
- return -22;
- }
- if ($this->get_user_lfb ( $user ['uid'] ) < L_MIN) {
- //$this->credit ( $user ['uid'], -11 , $logid );
- return -11; //Your LIF balance is insufficient
- }
-
- $data = array(
- 'uid' => $user ['uid'],
- 'tel' => $user ['tel'],
- 'ip' => $user ['ip'],
- 'addtime' => time ()
- );
- $logid = DB::insert ( $this-> lottery_log, $data, true );
-
-
- //Check the number of prizes the user has won every day
- if ($this->get_lottery ( $user ['uid'], strtotime ( date ( 'Y-m-d', TIME ) ), strtotime ( "+1day", strtotime ( date ( 'Y-m-d', TIME ) ) ), true ) >= L_DAY_CISHU) {
- $this->credit ( $user ['uid'], -12 , $logid );
- //Unfortunately, you didn’t draw anything this time!
- return -12;
- }
- //Check the number of prizes won by the user
- if ($this->get_lottery ( $user ['uid'], 0, 0, true ) > L_CISHU&&L_CISHU>0) {
- $ this->credit ( $user ['uid'], -12, $logid );
- //Unfortunately, you didn’t draw anything this time!
- return -15;
- }
- //Detect blacklist, set probability
- if ($this->checkhei ( $user ['tel'] ) > 0) {
- $this->credit ( $user [ 'uid'], -13, $logid );
- //Unfortunately, you didn't draw anything this time!
- return -13;
- }
- $lotteryid = $this->choujiang();
- $this->credit ( $user ['uid'], $lotteryid<1?$lotteryid:0, $logid, $ lotteryid ,$this->hao);
- if ($lotteryid > 0) {
- return $this->lotteryArray [$lotteryid];
- } else {
- return -4;
- }
- //-1 prize Already distributed
- //-2 Prizes for this period have been played
- //-3 Prizes not distributed
- //-4 There is a problem with the prizes
- //-11 Your Laifu coin balance is insufficient
- //-12 Unfortunately, you Nothing was drawn this time!
- //-In the blacklist of 13, unfortunately, you didn’t draw anything this time!
- //-14 Winning professional accounts are prohibited from talking about high prizes.
- //-15 has exceeded the total number of prizes in yizhong.
- //-16 The mobile number sent by Zhangsu is wrong.
- //-21 You are early and the event has not started yet!
- //-22 has passed the event time, I am very sorry, thank you!
- //-23Sorry, it is not the event time now, the event time is every day
- }
- /**
- * Show
- * @param unknown_type $data
- */
- public function show($data){
- $ok=0;//3 Winning
- $zz= 0;//Roulette degree
- $result='';//Prize name
- $lotteryid=0;//Prize ID
- if(is_array($data)){
- $ok=3;
- $result=$data[ 'msg'];
- $zz=$data['angle']+L_QUANSHU*360;
- $lotteryid=$data['lotteryid'];
- }else{
- $m='';
- switch($data) {
- case 0:{
- $m= 'Please log in first! ';
- }break;
- case -11:{
- $m= 'Your Raffles balance is insufficient! ';
- }break;
- case -12:{
- $m= 'Unfortunately, you didn't draw anything this time! ';
- }break;
- case -21:{
- $m= 'You are early and the event has not started yet! ';
- }break;
- case -22:{
- $m= 'The event time has passed, I am very sorry, thank you! ';
- }break;
- case -23:{
- $m= 'Sorry, it is not the event time now, the event time is every day'.L_DAY_START.':00-'.L_DAY_END.':00';
- }break;
- default:{
- $m= 'Unfortunately, you didn't draw anything this time!';
- }break;
- }
- $result=$m;
- $ok=3;//3中奖
- $zz=360+L_QUANSHU*360;//再接再厉
- }
- header("Expires:Mon,26Jul199705:00:00GMT");
- header("Cache-Control:no-cache,must-revalidate");
- header("Pragma:no-cache");
- header("Content-type:text/html;charset=utf-8");
- if(!$this->type){
- echo json_encode(array('return'=>$lotteryid,
- 'msg'=>$result));
- }else{
- echo ''."n";
- echo ''."n";
- echo ''."n";
- echo ''."n";
- }
- exit;
- }
- /**
- * Lucky draw number
- */
- private $hao=0;
- /**
- *The draw begins
- */
- private function choujiang() {
- $j = 0;
- $lotteryid = 0;
- $j = mt_rand ( 1, $this->max );
- $this->hao=$j;
- foreach ( $this->level as $k => $r ) {
- if ($r ['start'] <= $j && $r ['end'] > $j) {
- $lotteryid = $k;
- break;
- }
- }
- $d = array(
- 1 => array(
- 'time' => strtotime ( date ( 'Y-m-d 00:00:00', TIME ) ),
- 'time_end' => strtotime ( date ( 'Y-m-d 07:59:59', TIME ) )
- )
- );
- for ($i=2;$i<=17;$i++){
- $d[$i]=array(
- 'time' => strtotime ( date ( 'Y-m-d '.($i+6).':00:00', TIME ) ),
- 'time_end' => strtotime ( date ( 'Y-m-d '.($i+6).':59:59', TIME ) )
- );
- }
- if($lotteryid>0){
- $l=$this->lotteryArray [$lotteryid];
- $sql = "select count(*) m from " . DB::table ( $this->lottery_log );
- $sql .= " where lotteryid='$lotteryid' ";
- $s= intval ( DB::result_first ( $sql ) );
- $sum_over=$l['sum']-$s;
- if($sum_over>0){
- //本时段 奖品数
- $sum=0;
- foreach ($d as $k=>$r){
- if(TIME>=$r['time']&&TIME<=$r['time_end']){
- if($l['time_'.$k]>0){//个数限制
- $sum=$this->get_lottery_id(0,$r['time'],$r['time_end']+1,$lotteryid);
- if($sum>=$l['time_'.$k]){
- //本时段奖品已玩
- $lotteryid=-2;
- break;
- }
- }elseif ($l['time_'.$k]==0){
- //不发奖品
- $lotteryid=-3;
- break;
- }else{
- //-1 不限制
- }
-
- }
- }
- if($this->tel_zy && $lotteryid>0&&$lotteryid<4){
- $lotteryid=-14;
- }
- }else{
- //奖品已发完
- $lotteryid=-1;
- }
- }else{
- //奖品有问题
- $lotteryid=-4;
- }
- return $lotteryid;
-
- }
- /**
- * Detect blacklist and ordinary users, probability
- * @param string $tel
- * @return greater than 1 means that drawing is prohibited this time
- */
- private function checkhei($tel) {
- $n = mt_rand ( 1, 100 );
- if (in_array ( $tel, $this->heimingdan ['tel'] ) && L_ZY > 0) {
- $this->tel_zy=true;
- if ($n > L_ZY) {
- return 1;
- }
- }else{
- //号码检测
- if (!self::check_tel($tel)) {
- return 1;
- }
- }
- return 0;
- }
- /**
- * Total number of prizes
- * @param intval $uid
- * @param intval $start
- * @param intval $end
- * @param bool $bool true Number of prizes obtained false No statistics
- * @return number
- */
- private function get_lottery($uid = 0, $start = 0, $end = 0, $bool = false) {
- $sql = "select count(*) m from " . DB::table ( $this->lottery_log );
- $sql .= " where 1 ";
- if (intval ( $start ) > 0) {
- $sql .= " and addtime>='$start' ";
- }
- if (intval ( $end ) > 0) {
- $sql .= " and addtime<'$end' ";
- }
- if ($bool) {
- $sql .= " and lotteryid>0 ";
- }
- if (intval ( $uid ) > 0) {
- $sql .= " and uid='$uid' ";
- }
- return intval ( DB::result_first ( $sql ) );
- }
- /**
- * Total number of prizes
- * @param intval $uid
- * @param intval $start
- * @param intval $end
- * @param intval $bool prize id
- * @return number
- */
- private function get_lottery_id($uid = 0, $start = 0, $end = 0, $lotteryid = 0) {
-
- $sql = "select count(*) m from " . DB::table ( $this->lottery_log );
- $sql .= " where 1 ";
- if (intval ( $start ) > 0) {
- $sql .= " and addtime>='$start' ";
- }
- if (intval ( $end ) > 0) {
- $sql .= " and addtime<'$end' ";
- }
- if ($lotteryid>=0) {
- $sql .= " and lotteryid='$lotteryid' ";
- }
- if (intval ( $uid ) > 0) {
- $sql .= " and uid='$uid' ";
- }
- return intval ( DB::result_first ( $sql ) );
- }
- /**
- * Get the user’s Rafflecoins
- * @param intval $uid
- * @return number
- */
- public function get_user_lfb($uid) {
- $sql = "select extcredits2 from sz_common_member_count ";
- $sql .= " where 1 ";
- $sql .= " and uid='$uid' ";
- return intval ( DB::result_first ( $sql ) );
- }
- /**
- * Record logs and update user LIF coins
- * @param intval $uid
- * @param intval $r return value
- * @param intval $logid
- * @param intval $lotteryid
- */
- private function credit($uid, $result, $logid = 0, $lotteryid = 0,$hao=0) {
- $data = array();
- if ($lotteryid > 0) {
- $data ['lotteryid'] = $lotteryid;
- $data ['iswinning'] = 1;
- }
- $data ['result'] = $result;
- $data ['hao'] = $hao;
- $data ['HTTP_REFERER'] = $_SERVER['HTTP_REFERER'];
- DB::Update ( $this->lottery_log, $data, " logid='$logid' " );
- if (L_LFB > 0) {
- $sql = 'UPDATE sz_common_member_count SET extcredits2=extcredits2-' . L_LFB . ' WHERE uid=' . $uid;
- DB::query ( $sql );
- $this->credit_log ( $uid, 'reduce', L_LFB, 1, '积分清零活动' );
- }
- }
- /**
- *Mobile number check
- */
- private function check_tel($tel){
- $different_network=table_sub::get_different_network();
- if (!preg_match("/$different_network/",$tel)) {
- return false;
- }
- return true;
- }
- /**
- * Stored procedure link
- */
- private $StoreProcs;
- /**
- * Laifu Coin log stored procedure
- * @param intval $uid
- * @param string $op add to increase reduce consumption
- * @param intval $creditvalue Laifu Coin
- * @param intval $credittype 1 Laifu Coin 2 Laifu Coin Click
- * @param string $oreason description
- */
- private function credit_log($uid, $op, $creditvalue, $credittype, $oreason) {
- if (! $this->StoreProcs) {
- $this->StoreProcs = new StoreProcs ();
- }
- //调用存储过程
- $this->StoreProcs->query ( "call app_credit_log($uid,'$op','$credittype',1,$creditvalue,'$oreason')" );
- }
-
- }
复制代码
三,调用:
-
- $dzp=new lib_dzp_lottery();
- $u=array('uid'=>$_G ['uid'],'tel'=>$_G ['tel'],'ip'=> $_G ['clientip']);
- $dzp->load_setting();
- $dzp->show($dzp->check($u));
- ?>
复制代码
|