Php lottery program code in different time periods

Source: Internet
Author: User
Php lottery program code in different time periods

  1. Require_once (APP_ROOT. "./class/class_lib.php ");
  2. Require_once libfile ('class/StoreProcs ');
  3. Pc_base: load_app_class ('Table _ sub', '', 0 );
  4. /**
  5. * Big turntable
  6. * @ Author Administrator
  7. *
  8. */
  9. Class lib_dzp_lottery extends app_lib {
  10. /**
  11. * Prize table
  12. */
  13. Public $ lottery = 'activity _ lyq_lottery ';
  14. /**
  15. * Prize log table
  16. */
  17. Public $ lottery_log = 'activity _ lyq_lottery_log ';
  18. /**
  19. * N and other prizes
  20. */
  21. Private $ level = array ();
  22. /**
  23. * Prize information
  24. */
  25. Private $ lotteryArray = array ();
  26. /***
  27. * Number of random ending digits
  28. */
  29. Private $ max = 30000;
  30. /**
  31. * Category true: default value: false: zhangsu
  32. */
  33. Private $ type = true;
  34. /**
  35. * Winners
  36. */
  37. Private $ tel_zy = false;
  38. /**
  39. * Read configuration
  40. */
  41. Public function load_setting (){
  42. $ Data = getcache ('lyqdzp _ setting ');
  43. Define ('time', TIME (); // current time
  44. Define ('l _ start', strtotime ($ data ['l _ start']); // registration START time
  45. Define ('l _ end', strtotime ($ data ['l _ end']); // registration END time,-1 means 23:59:59 yesterday
  46. Define ('l _ DAY_START ', $ data ['l _ day_start']); // Daily start time
  47. Define ('l _ DAY_END ', $ data ['l _ day_end']); // end time of each day
  48. Define ('l _ DAY_CISHU ', $ data ['l _ day_cishu']); // The number of times the prize is received per day
  49. Define ('l _ CISHU ', $ data ['l _ cishu']); // The total number of prizes received
  50. Define ('l _ min', 20); // The minimum Laifu coin
  51. Define ('l _ lfb', $ data ['l _ lfb']); // reduce Laifu coins
  52. Define ('l _ ZY ', $ data ['l _ zy']); // professional
  53. Define ('l _ QUANSHU ', $ data ['l _ quanshu']); // number of circles, starting circle of the big turntable
  54. Define ('l _ KONGJIANG ', intval ($ data ['l _ kongjiang']); // empty prize probability
  55. $ Host = 'www. ****. com '; // The current network
  56. If ($ _ SERVER ['http _ host'] = '2017. ***** 0 '){
  57. $ Host = '1970. ***** '; // test machine
  58. } Elseif ($ _ SERVER ['http _ host'] = '2017. com '){
  59. $ Host = '125life. com'; // Local
  60. } Elseif (strpos ($ _ SERVER ['http _ host'], '2017. 192. ') = 0 ){
  61. $ Host = $ _ SERVER ['http _ host']. '/125e.com'; // Local
  62. }
  63. Define ('l _ site', 'http: // '. $ host.'/'); // add the domain name to the end/
  64. Define ('l _ url', L_SITE. 'index. php'); // access address
  65. // Only access through the flash address
  66. $ S = L_SITE. 'Flash/dzp/I .swf ';
  67. If (preg_replace ('/swf. * $/', 'swf ', $ _ SERVER ['http _ referer'])! = $ S & $ this-> type ){
  68. Exit ('Dude, you have got enough. please shake the prize through a regular channel! ');
  69. }
  70. $ This-> load ();
  71. }
  72. /**
  73. * Blacklist
  74. */
  75. Private $ heimingdan = array ();
  76. /**
  77. * Read prize configurations
  78. */
  79. Public function load (){
  80. $ This-> setlottery ();
  81. $ This-> heimingdan = getcache ('Tel ', 'blance ');
  82. }
  83. Private function setlottery (){
  84. $ Time = strtotime (date ('Y-m-D', TIME ));
  85. $ SQL = "select u .*";
  86. $ SQL. = ", (select COUNT (l. lotteryid) from ". DB: table ($ this-> lottery_log ). "AS l where u. lotteryid = l. lotteryid and l. iswinning = '1') as num ";
  87. $ SQL. = "from". DB: table ($ this-> lottery). "AS u ";
  88. $ SQL. = "where 1 ";
  89. $ SQL. = "and u. isdisable = '0 '";
  90. $ SQL. = "and u. time_start <= '$ time '";
  91. $ SQL. = "and u. time_end> = '$ time '";
  92. $ SQL. = "ORDER BY u. listorder ";
  93. $ D = DB: fetch_all ($ SQL );
  94. $ Sum = 0;
  95. Foreach ($ d as $ r ){
  96. $ R ['sum _ over'] = intval ($ r ['sum'])-intval ($ r ['num']);
  97. If ($ r ['sum']> 0 ){
  98. $ Sum + = $ r ['sum'];
  99. }
  100. $ R ['MSG '] = str_replace (' {name} ', $ r ['name'], $ r ['MSG']);
  101. $ This-> lotteryArray [$ r ['lotteryid'] = $ r;
  102. }
  103. If ($ sum <100) $ sum = 1000;
  104. $ M = 1;
  105. $ Probability = 0;
  106. $ Newsum = 0;
  107. // 80% blank prize + 20% prize
  108. $ This-> max = $ sum + $ sum * (Rochelle Kongjiang/100)/(100-L_KONGJIANG)/100 );
  109. Foreach ($ this-> lotteryArray as $ r ){
  110. If ($ r ['sum']> 0 ){
  111. $ Newsum = $ r ['sum'];
  112. If ($ r ['bability ']> 0 ){
  113. $ Probability = 0;
  114. $ Probability = ceil ($ r ['sum'] * 100/$ r ['bability ']);
  115. If ($ probability> 0 ){
  116. $ Newsum = $ probability;
  117. }
  118. }
  119. $ This-> level [$ r ['lotteryid'] ['start'] = $ m;
  120. $ This-> level [$ r ['lotteryid'] ['end'] = $ m + $ newsum;
  121. $ M = $ m + $ r ['sum'];
  122. }
  123. }
  124. }
  125. /**
  126. * Checks whether the user wins the prize. 0. thank you for your participation. other prize data is returned.
  127. * @ Param array $ user array (uid, tel, ip)
  128. */
  129. Public function check ($ user ){
  130. If (intval ($ user ['uid']) <1 ){
  131. // No logon
  132. Return 0;
  133. }
  134. If (intval (TIME) // You have arrived early and the activity has not started!
  135. Return-21;
  136. }
  137. If (intval (TIME)> intval (L_END )){
  138. // It is a pity that the event time has passed. thank you!
  139. Return-22;
  140. }
  141. If ($ this-> get_user_lfb ($ user ['uid']) <L_MIN ){
  142. // $ This-> credit ($ user ['uid'],-11, $ logid );
  143. Return-11; // your lucky money balance is insufficient
  144. }
  145. $ Data = array (
  146. 'Uid' => $ user ['uid'],
  147. 'Tel' => $ user ['tel'],
  148. 'IP' => $ user ['IP'],
  149. 'Addtime' => time ()
  150. );
  151. $ Logid = DB: insert ($ this-> lottery_log, $ data, true );
  152. // Check the number of prizes that the user has received every day
  153. If ($ this-> get_lottery ($ user ['uid'], strtotime (date ('Y-m-D', TIME), strtotime ("+ 1day ", strtotime (date ('Y-m-D', TIME), true)> = L_DAY_CISHU ){
  154. $ This-> credit ($ user ['uid'],-12, $ logid );
  155. // Sorry, you did not get anything this time!
  156. Return-12;
  157. }
  158. // Check the number of all the winning prizes of the user
  159. If ($ this-> get_lottery ($ user ['uid'], 0, 0, true)> L_CISHU & L_CISHU> 0 ){
  160. $ This-> credit ($ user ['uid'],-12, $ logid );
  161. // Sorry, you did not get anything this time!
  162. Return-15;
  163. }
  164. // Check the blacklist and set the probability
  165. If ($ this-> checkhei ($ user ['Tel '])> 0 ){
  166. $ This-> credit ($ user ['uid'],-13, $ logid );
  167. // Sorry, you did not get anything this time!
  168. Return-13;
  169. }
  170. $ Lotteryid = $ this-> choujiang ();
  171. $ This-> credit ($ user ['uid'], $ lotteryid <1? $ Lotteryid: 0, $ logid, $ lotteryid, $ this-> hao );
  172. If ($ lotteryid> 0 ){
  173. Return $ this-> lotteryArray [$ lotteryid];
  174. } Else {
  175. Return-4;
  176. }
  177. //-1 the prize has been sent
  178. //-2 the prize has been played during this period
  179. //-3 No Prize
  180. //-4. The prize is incorrect.
  181. //-11 your credit card balance is insufficient
  182. //-12 sorry, you did not get anything this time!
  183. //-13 it's a pity that you did not get anything in this blacklist!
  184. //-14 the winning professional is prohibited from high-end lecture and high prizes
  185. //-15 has exceeded the total yizhong prize count
  186. //-The mobile phone number passed by Ops Su is incorrect.
  187. //-21 you have arrived early and the activity has not started!
  188. //-22 the event has passed. sorry, thank you!
  189. //-23 sorry, it is not the activity time, and the activity time is daily
  190. }
  191. /**
  192. * Display
  193. * @ Param unknown_type $ data
  194. */
  195. Public function show ($ data ){
  196. $ OK = 0; // 3
  197. $ Zz = 0; // turntable degree
  198. $ Result = ''; // prize name
  199. $ Lotteryid = 0; // prize ID
  200. If (is_array ($ data )){
  201. $ OK = 3;
  202. $ Result = $ data ['MSG '];
  203. $ Zz = $ data ['angle '] + L_QUANSHU * 360;
  204. $ Lotteryid = $ data ['lotteryid'];
  205. } Else {
  206. $ M = '';
  207. Switch ($ data ){
  208. Case 0 :{
  209. $ M = 'log on first! ';
  210. } Break;
  211. Case-11 :{
  212. $ M = 'Your lucky money balance is insufficient! ';
  213. } Break;
  214. Case-12 :{
  215. $ M = 'Sorry, you did not get anything this time! ';
  216. } Break;
  217. Case-21 :{
  218. $ M = 'you're late, and the activity hasn't started yet! ';
  219. } Break;
  220. Case-22 :{
  221. $ M = 'the event time has passed. sorry, thank you! ';
  222. } Break;
  223. Case-23 :{
  224. $ M = 'Sorry, this is not the activity time. the activity time is Daily '. L_DAY_START.': 00-'. L_DAY_END.': 00 ';
  225. } Break;
  226. Default :{
  227. $ M = 'Sorry, you did not get anything this time! ';
  228. } Break;
  229. }
  230. $ Result = $ m;
  231. $ OK = 3; // 3
  232. $ Zz = 360 + L_QUANSHU * 360; // make persistent efforts
  233. }
  234. Header ("Expires: Mon, 26Jul199705: 00: 00GMT ");
  235. Header ("Cache-Control: no-cache, must-revalidate ");
  236. Header ("Pragma: no-cache ");
  237. Header ("Content-type: text/html; charset = utf-8 ");
  238. If (! $ This-> type ){
  239. Echo json_encode (array ('Return '=> $ lotteryid,
  240. 'MSG '=> $ result ));
  241. } Else {
  242. Echo' '. "\ N ";
  243. Echo' '. "\ N ";
  244. Echo' '. "\ N ";
  245. Echo''. "\ N ";
  246. }
  247. Exit;
  248. }
  249. /**
  250. * Lottery number
  251. */
  252. Private $ hao = 0;
  253. /**
  254. * Lottery starts
  255. */
  256. Private function choujiang (){
  257. $ J = 0;
  258. $ Lotteryid = 0;
  259. $ J = mt_rand (1, $ this-> max );
  260. $ This-> hao = $ j;
  261. Foreach ($ this-> level as $ k => $ r ){
  262. If ($ r ['start'] <= $ j & $ r ['end']> $ j ){
  263. $ Lotteryid = $ k;
  264. Break;
  265. }
  266. }
  267. $ D = array (
  268. 1 => array (
  269. 'Time' => strtotime (date ('Y-m-d 00:00:00 ', time )),
  270. 'Time _ end' => strtotime (date ('Y-m-d 07:59:59 ', time ))
  271. )
  272. );
  273. For ($ I = 2; $ I <= 17; $ I ++ ){
  274. $ D [$ I] = array (
  275. 'Time' => strtotime (date ('Y-m-D'. ($ I + 6). ': 00: 00', time )),
  276. 'Time _ end' => strtotime (date ('Y-m-D'. ($ I + 6). ': 59: 59', time ))
  277. );
  278. }
  279. If ($ lotteryid> 0 ){
  280. $ L = $ this-> lotteryArray [$ lotteryid];
  281. $ SQL = "select count (*) m from". DB: table ($ this-> lottery_log );
  282. $ SQL. = "where lotteryid = '$ lotteryid '";
  283. $ S = intval (DB: result_first ($ SQL ));
  284. $ Sum_over = $ l ['sum']-$ s;
  285. If ($ sum_over> 0 ){
  286. // Number of prizes in this period
  287. $ Sum = 0;
  288. Foreach ($ d as $ k => $ r ){
  289. If (TIME >=$ r ['Time'] & time <= $ r ['time _ end']) {
  290. If ($ l ['time _ '. $ k]> 0) {// quantity limit
  291. $ Sum = $ this-> get_lottery_id (0, $ r ['Time'], $ r ['time _ end'] + 1, $ lotteryid );
  292. If ($ sum> = $ l ['time _ '. $ k]) {
  293. // The Prize has been played during this period
  294. $ Lotteryid =-2;
  295. Break;
  296. }
  297. } Elseif ($ l ['time _ '. $ k] = 0 ){
  298. // No Prize is given
  299. $ Lotteryid =-3;
  300. Break;
  301. } Else {
  302. //-1 Unlimited
  303. }
  304. }
  305. }
  306. If ($ this-> tel_zy & $ lotteryid> 0 & $ lotteryid <4 ){
  307. $ Lotteryid =-14;
  308. }
  309. } Else {
  310. // The Prize has been delivered
  311. $ Lotteryid =-1;
  312. }
  313. } Else {
  314. // The prize is incorrect.
  315. $ Lotteryid =-4;
  316. }
  317. Return $ lotteryid;
  318. }
  319. /**
  320. * Checks the blacklist and common users.
  321. * @ Param string $ tel
  322. * @ Return greater than 1 indicates smoking is prohibited this time
  323. */
  324. Private function checkhei ($ tel ){
  325. $ N = mt_rand (1,100 );
  326. If (in_array ($ tel, $ this-> heimingdan ['tel']) & L_ZY> 0 ){
  327. $ This-> tel_zy = true;
  328. If ($ n> L_ZY ){
  329. Return 1;
  330. }
  331. } Else {
  332. // Number detection
  333. If (! Self: check_tel ($ tel )){
  334. Return 1;
  335. }
  336. }
  337. Return 0;
  338. }
  339. /**
  340. * Total Prizes
  341. * @ Param intval $ uid
  342. * @ Param intval $ start
  343. * @ Param intval $ end
  344. * @ Param bool $ bool true: the number of prizes received is false. no statistics are collected.
  345. * @ Return number
  346. */
  347. Private function get_lottery ($ uid = 0, $ start = 0, $ end = 0, $ bool = false ){
  348. $ SQL = "select count (*) m from". DB: table ($ this-> lottery_log );
  349. $ SQL. = "where 1 ";
  350. If (intval ($ start)> 0 ){
  351. $ SQL. = "and addtime> = '$ start '";
  352. }
  353. If (intval ($ end)> 0 ){
  354. $ SQL. = "and addtime <'$ end '";
  355. }
  356. If ($ bool ){
  357. $ SQL. = "and lotteryid> 0 ";
  358. }
  359. If (intval ($ uid)> 0 ){
  360. $ SQL. = "and uid = '$ uid '";
  361. }
  362. Return intval (DB: result_first ($ SQL ));
  363. }
  364. /**
  365. * Total Prizes
  366. * @ Param intval $ uid
  367. * @ Param intval $ start
  368. * @ Param intval $ end
  369. * @ Param intval $ bool prize id
  370. * @ Return number
  371. */
  372. Private function get_lottery_id ($ uid = 0, $ start = 0, $ end = 0, $ lotteryid = 0 ){
  373. $ SQL = "select count (*) m from". DB: table ($ this-> lottery_log );
  374. $ SQL. = "where 1 ";
  375. If (intval ($ start)> 0 ){
  376. $ SQL. = "and addtime> = '$ start '";
  377. }
  378. If (intval ($ end)> 0 ){
  379. $ SQL. = "and addtime <'$ end '";
  380. }
  381. If ($ lotteryid> = 0 ){
  382. $ SQL. = "and lotteryid = '$ lotteryid '";
  383. }
  384. If (intval ($ uid)> 0 ){
  385. $ SQL. = "and uid = '$ uid '";
  386. }
  387. Return intval (DB: result_first ($ SQL ));
  388. }
  389. /**
  390. * Get the user's lucky money
  391. * @ Param intval $ uid
  392. * @ Return number
  393. */
  394. Public function get_user_lfb ($ uid ){
  395. $ SQL = "select extcredits2 from sz_common_member_count ";
  396. $ SQL. = "where 1 ";
  397. $ SQL. = "and uid = '$ uid '";
  398. Return intval (DB: result_first ($ SQL ));
  399. }
  400. /**
  401. * Record logs and update users' lucky coins
  402. * @ Param intval $ uid
  403. * @ Param intval $ r return value
  404. * @ Param intval $ logid
  405. * @ Param intval $ lotteryid
  406. */
  407. Private function credit ($ uid, $ result, $ logid = 0, $ lotteryid = 0, $ hao = 0 ){
  408. $ Data = array ();
  409. If ($ lotteryid> 0 ){
  410. $ Data ['lotteryid'] = $ lotteryid;
  411. $ Data ['iswinning'] = 1;
  412. }
  413. $ Data ['result'] = $ result;
  414. $ Data ['hao'] = $ hao;
  415. $ Data ['http _ referer'] = $ _ SERVER ['http _ referer'];
  416. DB: Update ($ this-> lottery_log, $ data, "logid = '$ logid '");
  417. If (L_LFB> 0 ){
  418. $ SQL = 'update sz_common_member_count SET extcredits2 = extcredits2-'. L_LFB. 'where uid ='. $ uid;
  419. DB: query ($ SQL );
  420. $ This-> credit_log ($ uid, 'reduce', L_LFB, 1, 'point clearing activity ');
  421. }
  422. }
  423. /**
  424. * Mobile phone number check
  425. */
  426. Private function check_tel ($ tel ){
  427. $ Different_network = table_sub: get_different_network ();
  428. If (! Preg_match ("/$ different_network/", $ tel )){
  429. Return false;
  430. }
  431. Return true;
  432. }
  433. /**
  434. * Stored procedure link
  435. */
  436. Private $ StoreProcs;
  437. /**
  438. * Laifencoin log storage process
  439. * @ Param intval $ uid
  440. * @ Param string $ op add increases reduce consumption
  441. * @ Param intval $ creditvalue lucky currency
  442. * @ Param intval $ credittype 1 laifucoin 2 laifudian
  443. * @ Param string $ oreason description
  444. */
  445. Private function credit_log ($ uid, $ op, $ creditvalue, $ credittype, $ oreason ){
  446. If (! $ This-> StoreProcs ){
  447. $ This-> StoreProcs = new StoreProcs ();
  448. }
  449. // Call the stored procedure
  450. $ This-> StoreProcs-> query ("call app_credit_log ($ uid, '$ op', '$ credittype', 1, $ creditvalue, '$ oreason ')");
  451. }
  452. }

3. call:

  1. $ Dzp = new lib_dzp_lottery ();
  2. $ U = array ('uid' =>$ _ G ['uid'], 'tel' =>$ _ G ['tel'], 'IP' => $ _ G ['clientip']);
  3. $ Dzp-> load_setting ();
  4. $ Dzp-> show ($ dzp-> check ($ u ));
  5. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.