PHP Lottery program code for a split-time period

Source: Internet
Author: User
  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. * Large Turntable
  6. * @author Administrator
  7. *
  8. */
  9. Class Lib_dzp_lottery extends App_lib {
  10. /**
  11. * Prizes Table
  12. */
  13. Public $lottery = ' activity_lyq_lottery ';
  14. /**
  15. * Prize Log table
  16. */
  17. Public $lottery _log = ' activity_lyq_lottery_log ';
  18. /**
  19. * Prizes such as n
  20. */
  21. Private $level = Array ();
  22. /**
  23. * Prize Information
  24. */
  25. Private $lotteryArray = Array ();
  26. /***
  27. * Number of random digits ending digits
  28. */
  29. Private $max = 30000;
  30. /**
  31. * Category true: Default false: Palm Sue
  32. */
  33. Private $type =true;
  34. /**
  35. * Winning Specialist
  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 meaning yesterday 23:59:59
  46. Define (' L_day_start ', $data [' L_day_start ']); Daily start time
  47. Define (' L_day_end ', $data [' l_day_end ']);//End of day
  48. Define (' L_day_cishu ', $data [' L_day_cishu ');//Earn prizes per day
  49. Define (' L_cishu ', $data [' L_cishu ']);//Total number of prizes awarded
  50. Define (' L_min ', 20);//Minimum of FXCM
  51. Define (' L_LFB ', $data [' L_LFB ']);//Reduce the dollar
  52. Define (' L_zy ', $data [' L_zy ']); Professional outdoor movable
  53. Define (' L_quanshu ', $data [' L_quanshu ']);//laps, large turntable start lap number
  54. Define (' L_kongjiang ', intval ($data [' L_kongjiang ']);//Void award probability
  55. $host = ' www.****.com '; Current Network
  56. if ($_server[' http_host ']== ' 221.****0 ') {
  57. $host = ' 221.***** '; Test machine
  58. }elseif ($_server[' http_host ']== ' 125.com ') {
  59. $host = ' 125life.com ';//Local
  60. }elseif (Strpos ($_server[' http_host '), ' 192.168. ') ==0) {
  61. $host =$_server[' http_host ']. ' /125e.com ';//Local
  62. }
  63. Define (' l_site ', ' http://'. $host. ' /'); Domain Name last Add/
  64. Define (' L_url ', l_site. ' index.php ');//Access Address
  65. Only accessible via 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've got enough already, please draw the prize by regular way! ');
  69. }
  70. $this->load ();
  71. }
  72. /**
  73. * Blacklist
  74. */
  75. Private $heimingdan = Array ();
  76. /**
  77. * Read the prize configuration
  78. */
  79. Public function load () {
  80. $this->setlottery ();
  81. $this->heimingdan = GetCache (' tel ', ' blanklist ');
  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% Empty Award +20% Award
  108. $this->max = $sum + $sum * (l_kongjiang/100)/((100-l_kongjiang)/100);
  109. foreach ($this->lotteryarray as $r) {
  110. if ($r [' Sum '] > 0) {
  111. $newsum = $r [' Sum '];
  112. if ($r [' probability ']>0) {
  113. $probability = 0;
  114. $probability =ceil ($r [' Sum ']*100/$r [' probability ']);
  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. * Detect if the user is winning 0 Thank you for participating, other return prizes data
  127. * @param array $user Array (UID,TEL,IP)
  128. */
  129. Public function Check ($user) {
  130. if (Intval ($user [' uid ']) < 1) {
  131. Not logged in
  132. return 0;
  133. }
  134. if (Intval (time)
  135. You are early, the activity has not begun!
  136. return-21;
  137. }
  138. if (Intval (time) >intval (l_end)) {
  139. The time has gone by, very sorry, 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 cash balance is low
  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 items the user has won each 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. I'm sorry, you didn't get anything this time!
  157. return-12;
  158. }
  159. Check the total number of products the user has won
  160. if ($this->get_lottery ($user [' uid '], 0, 0, true) > L_cishu&&l_cishu>0) {
  161. $this->credit ($user [' uid '], -12, $logid);
  162. I'm sorry, you didn't get anything this time!
  163. return-15;
  164. }
  165. detecting blacklists, setting probabilities
  166. if ($this->checkhei ($user [' Tel ']) > 0) {
  167. $this->credit ($user [' uid '], -13, $logid);
  168. I'm sorry, you didn't 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 prizes have been sent out
  179. -2 prizes have been played during this period
  180. -3 not to send prizes
  181. -4 Issues with prizes
  182. -11 Your cash balance is insufficient
  183. -12 Unfortunately, you didn't get anything this time!
  184. -13 blacklist inside, very sorry, you did not draw anything this time!
  185. -14 winners Forbidden high-quality prizes
  186. -15 has exceeded Yizhong total prize number
  187. -16 Palm Sue Pass the phone number error
  188. -21 You are early, the activity has not begun!
  189. -22 has gone through the activity time, very sorry, thank you!
  190. -23 Sorry, now is not the activity time, the activity time is daily
  191. }
  192. /**
  193. * Display
  194. * @param unknown_type $data
  195. */
  196. Public function Show ($data) {
  197. $ok =0;//3 win
  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 = ' Please login first! ';
  211. }break;
  212. case-11:{
  213. $m = ' Your cash balance is insufficient! ';
  214. }break;
  215. case-12:{
  216. $m = ' I'm sorry, you didn't get anything this time! ';
  217. }break;
  218. case-21:{
  219. $m = ' You came early, the activity hasn't started yet! ';
  220. }break;
  221. case-22:{
  222. $m = ' already past the activity time, very sorry, thank you! ';
  223. }break;
  224. case-23:{
  225. $m = ' Sorry, now is not the active time, the activity time is daily '. L_day_start. ': 0 0-'. L_day_end. ': 0 0 ';
  226. }break;
  227. default:{
  228. $m = ' I'm sorry, you didn't get anything this time! ';
  229. }break;
  230. }
  231. $result = $m;
  232. $ok =3;//3 win
  233. $zz =360+l_quanshu*360;//to redouble
  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 (' 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. * The lottery number
  252. */
  253. Private $hao = 0;
  254. /**
  255. * Start of the lottery
  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). ': 0 0: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) {//number limit
  292. $sum = $this->get_lottery_id (0, $r [' time '], $r [' Time_end ']+1, $lotteryid);
  293. if ($sum >= $l [' time_ '. $k]) {
  294. Prizes have been played in this period
  295. $lotteryid =-2;
  296. Break
  297. }
  298. }elseif ($l [' time_ '. $k]==0) {
  299. Do not send prizes
  300. $lotteryid =-3;
  301. Break
  302. }else{
  303. -1 No Limit
  304. }
  305. }
  306. }
  307. if ($this->tel_zy && $lotteryid >0&& $lotteryid <4) {
  308. $lotteryid =-14;
  309. }
  310. }else{
  311. The prize has been sent out
  312. $lotteryid =-1;
  313. }
  314. }else{
  315. There's a problem with the prize
  316. $lotteryid =-4;
  317. }
  318. return $lotteryid;
  319. }
  320. /**
  321. * Detection of blacklists and ordinary users, probability
  322. * @param string $tel
  323. * @return greater than 1 means this ban
  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 number of prizes
  342. * @param intval $uid
  343. * @param intval $start
  344. * @param intval $end
  345. * @param bool $bool True to get the number of prizes false not counted
  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 number of 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 user to FXCM
  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 user to FXCM
  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, ' integral zeroing 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 Links
  436. */
  437. Private $StoreProcs;
  438. /**
  439. * Bitcoin Log stored procedure
  440. * @param intval $uid
  441. * @param string $op Add to increase reduce consumption
  442. * @param intval $creditvalue to Fu yen
  443. * @param intval $credittype a blessing point
  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 a stored procedure
  451. $this->storeprocs->query ("Call App_credit_log ($uid, ' $op ', ' $credittype ', 1, $creditvalue, ' $oreason ')");
  452. }
  453. }
Copy Code

Three, 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. ?>
Copy Code
  • Related Article

    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.