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)
  135. // You have arrived early and the activity has not started!
  136. Return-21;
  137. }
  138. If (intval (TIME)> intval (L_END )){
  139. // It is a pity that the event time has passed. thank you!
  140. Return-22;
  141. }
  142. If ($ this-> get_user_lfb ($ user ['uid']) <L_MIN ){
  143. // $ This-> credit ($ user ['uid'],-11, $ logid );
  144. Return-11; // your lucky money balance is insufficient
  145. }
  146. $ Data = array (
  147. 'Uid' => $ user ['uid'],
  148. 'Tel' => $ user ['tel'],
  149. 'IP' => $ user ['IP'],
  150. 'Addtime' => time ()
  151. );
  152. $ Logid = DB: insert ($ this-> lottery_log, $ data, true );
  153. // Check the number of prizes that the user has received every day
  154. If ($ this-> get_lottery ($ user ['uid'], strtotime (date ('Y-m-D', TIME), strtotime ("+ 1day ", strtotime (date ('Y-m-D', TIME), true)> = L_DAY_CISHU ){
  155. $ This-> credit ($ user ['uid'],-12, $ logid );
  156. // Sorry, you did not get anything this time!
  157. Return-12;
  158. }
  159. // Check the number of all the winning prizes of the user
  160. If ($ this-> get_lottery ($ user ['uid'], 0, 0, true)> L_CISHU & L_CISHU> 0 ){
  161. $ This-> credit ($ user ['uid'],-12, $ logid );
  162. // Sorry, you did not get anything this time!
  163. Return-15;
  164. }
  165. // Check the blacklist and set the probability
  166. If ($ this-> checkhei ($ user ['Tel '])> 0 ){
  167. $ This-> credit ($ user ['uid'],-13, $ logid );
  168. // Sorry, you did not get anything this time!
  169. Return-13;
  170. }
  171. $ Lotteryid = $ this-> choujiang ();
  172. $ This-> credit ($ user ['uid'], $ lotteryid <1? $ Lotteryid: 0, $ logid, $ lotteryid, $ this-> hao );
  173. If ($ lotteryid> 0 ){
  174. Return $ this-> lotteryArray [$ lotteryid];
  175. } Else {
  176. Return-4;
  177. }
  178. //-1 the prize has been sent
  179. //-2 the prize has been played during this period
  180. //-3 No Prize
  181. //-4. The prize is incorrect.
  182. //-11 your credit card balance is insufficient
  183. //-12 sorry, you did not get anything this time!
  184. //-13 it's a pity that you did not get anything in this blacklist!
  185. //-14 the winning professional is prohibited from high-end lecture and high prizes
  186. //-15 has exceeded the total yizhong prize count
  187. //-The mobile phone number passed by Ops Su is incorrect.
  188. //-21 you have arrived early and the activity has not started!
  189. //-22 the event has passed. sorry, thank you!
  190. //-23 sorry, it is not the activity time, and the activity time is daily
  191. }
  192. /**
  193. * Display
  194. * @ Param unknown_type $ data
  195. */
  196. Public function show ($ data ){
  197. $ OK = 0; // 3
  198. $ Zz = 0; // turntable degree
  199. $ Result = ''; // prize name
  200. $ Lotteryid = 0; // prize ID
  201. If (is_array ($ data )){
  202. $ OK = 3;
  203. $ Result = $ data ['MSG '];
  204. $ Zz = $ data ['angle '] + L_QUANSHU * 360;
  205. $ Lotteryid = $ data ['lotteryid'];
  206. } Else {
  207. $ M = '';
  208. Switch ($ data ){
  209. Case 0 :{
  210. $ M = 'log on first! ';
  211. } Break;
  212. Case-11 :{
  213. $ M = 'Your lucky money balance is insufficient! ';
  214. } Break;
  215. Case-12 :{
  216. $ M = 'Sorry, you did not get anything this time! ';
  217. } Break;
  218. Case-21 :{
  219. $ M = 'you're late, and the activity hasn't started yet! ';
  220. } Break;
  221. Case-22 :{
  222. $ M = 'the event time has passed. sorry, thank you! ';
  223. } Break;
  224. Case-23 :{
  225. $ M = 'Sorry, this is not the activity time. the activity time is Daily '. L_DAY_START.': 00-'. L_DAY_END.': 00 ';
  226. } Break;
  227. Default :{
  228. $ M = 'Sorry, you did not get anything this time! ';
  229. } Break;
  230. }
  231. $ Result = $ m;
  232. $ OK = 3; // 3
  233. $ Zz = 360 + L_QUANSHU * 360; // make persistent efforts
  234. }
  235. Header ("Expires: Mon, 26Jul199705: 00: 00GMT ");
  236. Header ("Cache-Control: no-cache, must-revalidate ");
  237. Header ("Pragma: no-cache ");
  238. Header ("Content-type: text/html; charset = utf-8 ");
  239. If (! $ This-> type ){
  240. Echo json_encode (array ('Return '=> $ lotteryid,
  241. 'MSG '=> $ result ));
  242. } Else {
  243. Echo' '. "\ N ";
  244. Echo' '. "\ N ";
  245. Echo' '. "\ N ";
  246. Echo''. "\ N ";
  247. }
  248. Exit;
  249. }
  250. /**
  251. * Lottery number
  252. */
  253. Private $ hao = 0;
  254. /**
  255. * Lottery starts
  256. */
  257. Private function choujiang (){
  258. $ J = 0;
  259. $ Lotteryid = 0;
  260. $ J = mt_rand (1, $ this-> max );
  261. $ This-> hao = $ j;
  262. Foreach ($ this-> level as $ k => $ r ){
  263. If ($ r ['start'] <= $ j & $ r ['end']> $ j ){
  264. $ Lotteryid = $ k;
  265. Break;
  266. }
  267. }
  268. $ D = array (
  269. 1 => array (
  270. 'Time' => strtotime (date ('Y-m-d 00:00:00 ', time )),
  271. 'Time _ end' => strtotime (date ('Y-m-d 07:59:59 ', time ))
  272. )
  273. );
  274. For ($ I = 2; $ I <= 17; $ I ++ ){
  275. $ D [$ I] = array (
  276. 'Time' => strtotime (date ('Y-m-D'. ($ I + 6). ': 00: 00', time )),
  277. 'Time _ end' => strtotime (date ('Y-m-D'. ($ I + 6). ': 59: 59', time ))
  278. );
  279. }
  280. If ($ lotteryid> 0 ){
  281. $ L = $ this-> lotteryArray [$ lotteryid];
  282. $ SQL = "select count (*) m from". DB: table ($ this-> lottery_log );
  283. $ SQL. = "where lotteryid = '$ lotteryid '";
  284. $ S = intval (DB: result_first ($ SQL ));
  285. $ Sum_over = $ l ['sum']-$ s;
  286. If ($ sum_over> 0 ){
  287. // Number of prizes in this period
  288. $ Sum = 0;
  289. Foreach ($ d as $ k => $ r ){
  290. If (TIME >=$ r ['Time'] & time <= $ r ['time _ end']) {
  291. If ($ l ['time _ '. $ k]> 0) {// quantity limit
  292. $ Sum = $ this-> get_lottery_id (0, $ r ['Time'], $ r ['time _ end'] + 1, $ lotteryid );
  293. If ($ sum> = $ l ['time _ '. $ k]) {
  294. // The Prize has been played during this period
  295. $ Lotteryid =-2;
  296. Break;
  297. }
  298. } Elseif ($ l ['time _ '. $ k] = 0 ){
  299. // No Prize is given
  300. $ Lotteryid =-3;
  301. Break;
  302. } Else {
  303. //-1 Unlimited
  304. }
  305. }
  306. }
  307. If ($ this-> tel_zy & $ lotteryid> 0 & $ lotteryid <4 ){
  308. $ Lotteryid =-14;
  309. }
  310. } Else {
  311. // The Prize has been delivered
  312. $ Lotteryid =-1;
  313. }
  314. } Else {
  315. // The prize is incorrect.
  316. $ Lotteryid =-4;
  317. }
  318. Return $ lotteryid;
  319. }
  320. /**
  321. * Checks the blacklist and common users.
  322. * @ Param string $ tel
  323. * @ Return greater than 1 indicates smoking is prohibited this time
  324. */
  325. Private function checkhei ($ tel ){
  326. $ N = mt_rand (1,100 );
  327. If (in_array ($ tel, $ this-> heimingdan ['tel']) & L_ZY> 0 ){
  328. $ This-> tel_zy = true;
  329. If ($ n> L_ZY ){
  330. Return 1;
  331. }
  332. } Else {
  333. // Number detection
  334. If (! Self: check_tel ($ tel )){
  335. Return 1;
  336. }
  337. }
  338. Return 0;
  339. }
  340. /**
  341. * Total Prizes
  342. * @ Param intval $ uid
  343. * @ Param intval $ start
  344. * @ Param intval $ end
  345. * @ Param bool $ bool true: the number of prizes received is false. no statistics are collected.
  346. * @ Return number
  347. */
  348. Private function get_lottery ($ uid = 0, $ start = 0, $ end = 0, $ bool = false ){
  349. $ SQL = "select count (*) m from". DB: table ($ this-> lottery_log );
  350. $ SQL. = "where 1 ";
  351. If (intval ($ start)> 0 ){
  352. $ SQL. = "and addtime> = '$ start '";
  353. }
  354. If (intval ($ end)> 0 ){
  355. $ SQL. = "and addtime <'$ end '";
  356. }
  357. If ($ bool ){
  358. $ SQL. = "and lotteryid> 0 ";
  359. }
  360. If (intval ($ uid)> 0 ){
  361. $ SQL. = "and uid = '$ uid '";
  362. }
  363. Return intval (DB: result_first ($ SQL ));
  364. }
  365. /**
  366. * Total Prizes
  367. * @ Param intval $ uid
  368. * @ Param intval $ start
  369. * @ Param intval $ end
  370. * @ Param intval $ bool prize id
  371. * @ Return number
  372. */
  373. Private function get_lottery_id ($ uid = 0, $ start = 0, $ end = 0, $ lotteryid = 0 ){
  374. $ SQL = "select count (*) m from". DB: table ($ this-> lottery_log );
  375. $ SQL. = "where 1 ";
  376. If (intval ($ start)> 0 ){
  377. $ SQL. = "and addtime> = '$ start '";
  378. }
  379. If (intval ($ end)> 0 ){
  380. $ SQL. = "and addtime <'$ end '";
  381. }
  382. If ($ lotteryid> = 0 ){
  383. $ SQL. = "and lotteryid = '$ lotteryid '";
  384. }
  385. If (intval ($ uid)> 0 ){
  386. $ SQL. = "and uid = '$ uid '";
  387. }
  388. Return intval (DB: result_first ($ SQL ));
  389. }
  390. /**
  391. * Get the user's lucky money
  392. * @ Param intval $ uid
  393. * @ Return number
  394. */
  395. Public function get_user_lfb ($ uid ){
  396. $ SQL = "select extcredits2 from sz_common_member_count ";
  397. $ SQL. = "where 1 ";
  398. $ SQL. = "and uid = '$ uid '";
  399. Return intval (DB: result_first ($ SQL ));
  400. }
  401. /**
  402. * Record logs and update users' lucky coins
  403. * @ Param intval $ uid
  404. * @ Param intval $ r return value
  405. * @ Param intval $ logid
  406. * @ Param intval $ lotteryid
  407. */
  408. Private function credit ($ uid, $ result, $ logid = 0, $ lotteryid = 0, $ hao = 0 ){
  409. $ Data = array ();
  410. If ($ lotteryid> 0 ){
  411. $ Data ['lotteryid'] = $ lotteryid;
  412. $ Data ['iswinning'] = 1;
  413. }
  414. $ Data ['result'] = $ result;
  415. $ Data ['hao'] = $ hao;
  416. $ Data ['http _ referer'] = $ _ SERVER ['http _ referer'];
  417. DB: Update ($ this-> lottery_log, $ data, "logid = '$ logid '");
  418. If (L_LFB> 0 ){
  419. $ SQL = 'update sz_common_member_count SET extcredits2 = extcredits2-'. L_LFB. 'where uid ='. $ uid;
  420. DB: query ($ SQL );
  421. $ This-> credit_log ($ uid, 'reduce', L_LFB, 1, 'point clearing activity ');
  422. }
  423. }
  424. /**
  425. * Mobile phone number check
  426. */
  427. Private function check_tel ($ tel ){
  428. $ Different_network = table_sub: get_different_network ();
  429. If (! Preg_match ("/$ different_network/", $ tel )){
  430. Return false;
  431. }
  432. Return true;
  433. }
  434. /**
  435. * Stored procedure link
  436. */
  437. Private $ StoreProcs;
  438. /**
  439. * Laifencoin log storage process
  440. * @ Param intval $ uid
  441. * @ Param string $ op add increases reduce consumption
  442. * @ Param intval $ creditvalue lucky currency
  443. * @ Param intval $ credittype 1 laifucoin 2 laifudian
  444. * @ Param string $ oreason description
  445. */
  446. Private function credit_log ($ uid, $ op, $ creditvalue, $ credittype, $ oreason ){
  447. If (! $ This-> StoreProcs ){
  448. $ This-> StoreProcs = new StoreProcs ();
  449. }
  450. // Call the stored procedure
  451. $ This-> StoreProcs-> query ("call app_credit_log ($ uid, '$ op', '$ credittype', 1, $ creditvalue, '$ oreason ')");
  452. }
  453. }

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.