- Require_once (App_root. "./class/class_lib.php");
- Require_once libfile (' Class/storeprocs ');
- Pc_base::load_app_class (' table_sub ', ', 0);
- /**
- * Large Turntable
- * @author Administrator
- *
- */
- Class Lib_dzp_lottery extends App_lib {
- /**
- * Prizes Table
- */
- Public $lottery = ' activity_lyq_lottery ';
- /**
- * Prize Log table
- */
- Public $lottery _log = ' activity_lyq_lottery_log ';
- /**
- * Prizes such as n
- */
- Private $level = Array ();
- /**
- * Prize Information
- */
- Private $lotteryArray = Array ();
- /***
- * Number of random digits ending digits
- */
- Private $max = 30000;
- /**
- * Category true: Default false: Palm Sue
- */
- Private $type =true;
- /**
- * Winning Specialist
- */
- 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 meaning yesterday 23:59:59
- Define (' L_day_start ', $data [' L_day_start ']); Daily start time
- Define (' L_day_end ', $data [' l_day_end ']);//End of day
- Define (' L_day_cishu ', $data [' L_day_cishu ');//Earn prizes per day
- Define (' L_cishu ', $data [' L_cishu ']);//Total number of prizes awarded
- Define (' L_min ', 20);//Minimum of FXCM
- Define (' L_LFB ', $data [' L_LFB ']);//Reduce the dollar
- Define (' L_zy ', $data [' L_zy ']); Professional outdoor movable
- Define (' L_quanshu ', $data [' L_quanshu ']);//laps, large turntable start lap number
- Define (' L_kongjiang ', intval ($data [' L_kongjiang ']);//Void award probability
- $host = ' www.****.com '; Current 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. ' /'); Domain Name last Add/
- Define (' L_url ', l_site. ' index.php ');//Access Address
- Only accessible via Flash address
- $s =l_site. ' flash/dzp/i.swf ';
- if (preg_replace ('/swf.*$/', ' swf ', $_server[' http_referer '])! = $s && $this->type) {
- Exit (' Dude you've got enough already, please draw the prize by regular way! ');
- }
- $this->load ();
- }
- /**
- * Blacklist
- */
- Private $heimingdan = Array ();
- /**
- * Read the 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 Award +20% Award
- $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 '];
- }
- }
- }
- /**
- * Detect if the user is winning 0 Thank you for participating, other return prizes 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 early, the activity has not begun!
- return-21;
- }
- if (Intval (time) >intval (l_end)) {
- The time has gone by, very sorry, thank you!
- return-22;
- }
- if ($this->get_user_lfb ($user [' uid ']) < L_min) {
- $this->credit ($user [' uid '], -11, $logid);
- return-11; Your cash balance is low
- }
- $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 items the user has won each 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);
- I'm sorry, you didn't get anything this time!
- return-12;
- }
- Check the total number of products the user has won
- if ($this->get_lottery ($user [' uid '], 0, 0, true) > L_cishu&&l_cishu>0) {
- $this->credit ($user [' uid '], -12, $logid);
- I'm sorry, you didn't get anything this time!
- return-15;
- }
- detecting blacklists, setting probabilities
- if ($this->checkhei ($user [' Tel ']) > 0) {
- $this->credit ($user [' uid '], -13, $logid);
- I'm sorry, you didn't get 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 prizes have been sent out
- -2 prizes have been played during this period
- -3 not to send prizes
- -4 Issues with prizes
- -11 Your cash balance is insufficient
- -12 Unfortunately, you didn't get anything this time!
- -13 blacklist inside, very sorry, you did not draw anything this time!
- -14 winners Forbidden high-quality prizes
- -15 has exceeded Yizhong total prize number
- -16 Palm Sue Pass the phone number error
- -21 You are early, the activity has not begun!
- -22 has gone through the activity time, very sorry, thank you!
- -23 Sorry, now is not the activity time, the activity time is daily
- }
- /**
- * Display
- * @param unknown_type $data
- */
- Public function Show ($data) {
- $ok =0;//3 win
- $zz =0;//Turntable 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 login first! ';
- }break;
- case-11:{
- $m = ' Your cash balance is insufficient! ';
- }break;
- case-12:{
- $m = ' I'm sorry, you didn't get anything this time! ';
- }break;
- case-21:{
- $m = ' You came early, the activity hasn't started yet! ';
- }break;
- case-22:{
- $m = ' already past the activity time, very sorry, thank you! ';
- }break;
- case-23:{
- $m = ' Sorry, now is not the active time, the activity time is daily '. L_day_start. ': 0 0-'. L_day_end. ': 0 0 ';
- }break;
- default:{
- $m = ' I'm sorry, you didn't get anything this time! ';
- }break;
- }
- $result = $m;
- $ok =3;//3 win
- $zz =360+l_quanshu*360;//to redouble
- }
- 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 (' return ' = $lotteryid,
- ' msg ' = $result));
- }else{
- Echo ' . ' \ n ";
- Echo ' . ' \ n ";
- Echo ' . ' \ n ";
- Echo '. ' \ n ";
- }
- Exit
- }
- /**
- * The lottery number
- */
- Private $hao = 0;
- /**
- * Start of the lottery
- */
- 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). ': 0 0: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) {
- Number of prizes in this period
- $sum = 0;
- foreach ($d as $k = = $r) {
- if (time>= $r [' Time ']&&time<= $r [' time_end ']) {
- if ($l [' time_ '. $k]>0) {//number limit
- $sum = $this->get_lottery_id (0, $r [' time '], $r [' Time_end ']+1, $lotteryid);
- if ($sum >= $l [' time_ '. $k]) {
- Prizes have been played in this period
- $lotteryid =-2;
- Break
- }
- }elseif ($l [' time_ '. $k]==0) {
- Do not send prizes
- $lotteryid =-3;
- Break
- }else{
- -1 No Limit
- }
- }
- }
- if ($this->tel_zy && $lotteryid >0&& $lotteryid <4) {
- $lotteryid =-14;
- }
- }else{
- The prize has been sent out
- $lotteryid =-1;
- }
- }else{
- There's a problem with the prize
- $lotteryid =-4;
- }
- return $lotteryid;
- }
- /**
- * Detection of blacklists and ordinary users, probability
- * @param string $tel
- * @return greater than 1 means this ban
- */
- 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{
- Number detection
- 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 to get the number of prizes false not counted
- * @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 user to FXCM
- * @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 to FXCM
- * @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, ' integral zeroing activity ');
- }
- }
- /**
- * Mobile phone 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 Links
- */
- Private $StoreProcs;
- /**
- * Bitcoin Log stored procedure
- * @param intval $uid
- * @param string $op Add to increase reduce consumption
- * @param intval $creditvalue to Fu yen
- * @param intval $credittype a blessing point
- * @param string $oreason description
- */
- Private Function Credit_log ($uid, $op, $creditvalue, $credittype, $oreason) {
- if (! $this->storeprocs) {
- $this->storeprocs = new Storeprocs ();
- }
- Call a stored procedure
- $this->storeprocs->query ("Call App_credit_log ($uid, ' $op ', ' $credittype ', 1, $creditvalue, ' $oreason ')");
- }
- }
Copy CodeThree, call:
- $dzp =new lib_dzp_lottery ();
- $u =array (' uid ' =>$_g [' uid '], ' tel ' =>$_g [' tel '], ' ip ' = = $_g [' ClientIP ']);
- $dzp->load_setting ();
- $dzp->show ($dzp->check ($u));
- ?>
Copy Code |