- Require_once (APP_ROOT. "./class/class_lib.php ");
- Require_once libfile ('class/StoreProcs ');
- Pc_base: load_app_class ('Table _ sub', '', 0 );
- /**
- * Big turntable
- * @ Author Administrator
- *
- */
- Class lib_dzp_lottery extends app_lib {
- /**
- * Prize table
- */
- Public $ lottery = 'activity _ lyq_lottery ';
- /**
- * Prize log table
- */
- Public $ lottery_log = 'activity _ lyq_lottery_log ';
- /**
- * N and other prizes
- */
- Private $ level = array ();
- /**
- * Prize information
- */
- Private $ lotteryArray = array ();
- /***
- * Number of random ending digits
- */
- Private $ max = 30000;
- /**
- * Category true: default value: false: zhangsu
- */
- Private $ type = true;
- /**
- * Winners
- */
- 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 23:59:59 yesterday
- Define ('l _ DAY_START ', $ data ['l _ day_start']); // Daily start time
- Define ('l _ DAY_END ', $ data ['l _ day_end']); // end time of each day
- Define ('l _ DAY_CISHU ', $ data ['l _ day_cishu']); // The number of times the prize is received per day
- Define ('l _ CISHU ', $ data ['l _ cishu']); // The total number of prizes received
- Define ('l _ min', 20); // The minimum Laifu coin
- Define ('l _ lfb', $ data ['l _ lfb']); // reduce Laifu coins
- Define ('l _ ZY ', $ data ['l _ zy']); // professional
- Define ('l _ QUANSHU ', $ data ['l _ quanshu']); // number of circles, starting circle of the big turntable
- Define ('l _ KONGJIANG ', intval ($ data ['l _ kongjiang']); // empty prize probability
- $ Host = 'www. ****. com '; // The current network
- If ($ _ SERVER ['http _ host'] = '2017. ***** 0 '){
- $ Host = '1970. ***** '; // test machine
- } Elseif ($ _ SERVER ['http _ host'] = '2017. com '){
- $ Host = '125life. com'; // Local
- } Elseif (strpos ($ _ SERVER ['http _ host'], '2017. 192. ') = 0 ){
- $ Host = $ _ SERVER ['http _ host']. '/125e.com'; // Local
- }
- Define ('l _ site', 'http: // '. $ host.'/'); // add the domain name to the end/
- Define ('l _ url', L_SITE. 'index. php'); // access address
-
- // Only access through the 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 shake the prize through a regular channel! ');
- }
- $ This-> load ();
- }
- /**
- * Blacklist
- */
- Private $ heimingdan = array ();
- /**
- * Read prize configurations
- */
- Public function load (){
- $ This-> setlottery ();
- $ This-> heimingdan = getcache ('Tel ', 'blance ');
- }
- 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% blank prize + 20% prize
- $ This-> max = $ sum + $ sum * (Rochelle Kongjiang/100)/(100-L_KONGJIANG)/100 );
- Foreach ($ this-> lotteryArray as $ r ){
- If ($ r ['sum']> 0 ){
- $ Newsum = $ r ['sum'];
- If ($ r ['bability ']> 0 ){
- $ Probability = 0;
- $ Probability = ceil ($ r ['sum'] * 100/$ r ['bability ']);
- If ($ probability> 0 ){
- $ Newsum = $ probability;
- }
- }
- $ This-> level [$ r ['lotteryid'] ['start'] = $ m;
- $ This-> level [$ r ['lotteryid'] ['end'] = $ m + $ newsum;
- $ M = $ m + $ r ['sum'];
- }
- }
- }
- /**
- * Checks whether the user wins the prize. 0. thank you for your participation. other prize data is returned.
- * @ Param array $ user array (uid, tel, ip)
- */
- Public function check ($ user ){
- If (intval ($ user ['uid']) <1 ){
- // No logon
- Return 0;
- }
- If (intval (TIME) // You have arrived early and the activity has not started!
- Return-21;
- }
- If (intval (TIME)> intval (L_END )){
- // It is a pity that the event time has passed. thank you!
- Return-22;
- }
- If ($ this-> get_user_lfb ($ user ['uid']) <L_MIN ){
- // $ This-> credit ($ user ['uid'],-11, $ logid );
- Return-11; // your lucky money 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 that the user has received 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 );
- // Sorry, you did not get anything this time!
- Return-12;
- }
- // Check the number of all the winning prizes of the user
- If ($ this-> get_lottery ($ user ['uid'], 0, 0, true)> L_CISHU & L_CISHU> 0 ){
- $ This-> credit ($ user ['uid'],-12, $ logid );
- // Sorry, you did not get anything this time!
- Return-15;
- }
- // Check the blacklist and set the probability
- If ($ this-> checkhei ($ user ['Tel '])> 0 ){
- $ This-> credit ($ user ['uid'],-13, $ logid );
- // Sorry, you did not 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 the prize has been sent
- //-2 the prize has been played during this period
- //-3 No Prize
- //-4. The prize is incorrect.
- //-11 your credit card balance is insufficient
- //-12 sorry, you did not get anything this time!
- //-13 it's a pity that you did not get anything in this blacklist!
- //-14 the winning professional is prohibited from high-end lecture and high prizes
- //-15 has exceeded the total yizhong prize count
- //-The mobile phone number passed by Ops Su is incorrect.
- //-21 you have arrived early and the activity has not started!
- //-22 the event has passed. sorry, thank you!
- //-23 sorry, it is not the activity time, and the activity time is daily
- }
- /**
- * Display
- * @ Param unknown_type $ data
- */
- Public function show ($ data ){
- $ OK = 0; // 3
- $ 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 = 'log on first! ';
- } Break;
- Case-11 :{
- $ M = 'Your lucky money balance is insufficient! ';
- } Break;
- Case-12 :{
- $ M = 'Sorry, you did not get anything this time! ';
- } Break;
- Case-21 :{
- $ M = 'you're late, and the activity hasn't started yet! ';
- } Break;
- Case-22 :{
- $ M = 'the event time has passed. sorry, thank you! ';
- } Break;
- Case-23 :{
- $ M = 'Sorry, this is not the activity time. the activity time is Daily '. L_DAY_START.': 00-'. L_DAY_END.': 00 ';
- } Break;
- Default :{
- $ M = 'Sorry, you did not get anything this time! ';
- } Break;
- }
- $ Result = $ m;
- $ OK = 3; // 3
- $ Zz = 360 + L_QUANSHU * 360; // make persistent efforts
- }
- 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;
- }
- /**
- * Lottery number
- */
- Private $ hao = 0;
- /**
- * Lottery starts
- */
- 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 ){
- // 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) {// quantity limit
- $ Sum = $ this-> get_lottery_id (0, $ r ['Time'], $ r ['time _ end'] + 1, $ lotteryid );
- If ($ sum> = $ l ['time _ '. $ k]) {
- // The Prize has been played during this period
- $ Lotteryid =-2;
- Break;
- }
- } Elseif ($ l ['time _ '. $ k] = 0 ){
- // No Prize is given
- $ Lotteryid =-3;
- Break;
- } Else {
- //-1 Unlimited
- }
-
- }
- }
- If ($ this-> tel_zy & $ lotteryid> 0 & $ lotteryid <4 ){
- $ Lotteryid =-14;
- }
- } Else {
- // The Prize has been delivered
- $ Lotteryid =-1;
- }
- } Else {
- // The prize is incorrect.
- $ Lotteryid =-4;
- }
- Return $ lotteryid;
-
- }
- /**
- * Checks the blacklist and common users.
- * @ Param string $ tel
- * @ Return greater than 1 indicates smoking 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 {
- // Number detection
- If (! Self: check_tel ($ tel )){
- Return 1;
- }
- }
- Return 0;
- }
- /**
- * Total Prizes
- * @ Param intval $ uid
- * @ Param intval $ start
- * @ Param intval $ end
- * @ Param bool $ bool true: the number of prizes received is false. no statistics are collected.
- * @ 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 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 lucky money
- * @ 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 users' lucky 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, 'point clearing 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 link
- */
- Private $ StoreProcs;
- /**
- * Laifencoin log storage process
- * @ Param intval $ uid
- * @ Param string $ op add increases reduce consumption
- * @ Param intval $ creditvalue lucky currency
- * @ Param intval $ credittype 1 laifucoin 2 laifudian
- * @ Param string $ oreason description
- */
- Private function credit_log ($ uid, $ op, $ creditvalue, $ credittype, $ oreason ){
- If (! $ This-> StoreProcs ){
- $ This-> StoreProcs = new StoreProcs ();
- }
- // Call the stored procedure
- $ This-> StoreProcs-> query ("call app_credit_log ($ uid, '$ op', '$ credittype', 1, $ creditvalue, '$ oreason ')");
- }
-
- }
3. 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 ));
- ?>
|