PHP lucky big turntable source code, supports ThinkPHP, big turntable thinkphp
HTML code
The Code is based on thinkphp. If not, you can modify the url path.
- Charset = "UTF-8">
- Name = "keywords" content = "lucky big turntable, cnsecer.com"/>
- Name = "description" content = "lucky big turntable"/>
- Lucky big Turntable
- Type = "text/css">
- . Demo {width: pixel PX; height: pixel PX; position: relative; margin: 50 pxauto}
- # Disk {width: pixel PX; height: pixel PX; background: url (_ STATIC _/images/disk.jpg) no-repeat}
- # Start {width: 163px; height: 320px; position: absolute; top: 46px; left: 130px ;}
- # Start img {cursor: pointer}
- Src = "http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js">
- Type = "text/javascript" src = "_ STATIC _/js/jQueryRotate.2.2.js">
- Type = "text/javascript" src = "_ STATIC _/js/jquery. easing. min. js">
- Type = "text/javascript">
- $ (Function (){
- $ ("# Startbtn"). click (function (){
- Lottery ();
- });
- });
- Function lottery (){
- $. Ajax ({
- Type: 'post ',
- Url: '{: U (\ 'game/run \')} ', // change the submitted address to your own
- DataType: 'json ',
- Cache: false,
- Error: function (){
- Alert ('error! ');
- Returnfalse;
- },
- Success: function (json ){
- $ ("# Startbtn" 2.16.unbind('click'mirror.css ("cursor", "default ");
- Var a = json. angle; // angle
- Var p = json. prize; // Award
- $ ("# Startbtn"). rotate ({
- Duration: 3000, // rotation time
- Angle: 0,
- AnimateTo: 1800 + a, // Rotation Angle
- Easing: $. easing. easeOutSine,
- Callback: function (){
- Var con = confirm ('Congratulations, do you have to come back again in '+ p +' \ n? ');
- If (con ){
- Lottery ();
- } Else {
- Returnfalse;
- }
- }
- });
- }
- });
- }
- Id = "main">
- Class = "msg">
- Class = "demo">
- Id = "disk">
- Id = "start"> src = "_ STATIC _/images/start.png" id = "startbtn">
- Id = "footer">
Background processing code
- Php
- NamespaceHome \ Controller;
- UseThink \ Controller;
- ClassGameControllerextendsBaseController {
- Publicfunction index (){
- $ This-> display ("index ");
- }
- Publicfunction run (){
- $ ProArr = array ();
- // V is the sum of the winning probability, preferably an integer multiple of 100. id is the prize number min max, which is the largest and the smallest angle respectively.
- $ Prize_arr = array (
- '0' => array ('id' => 1, 'Min' => 1, 'max '=> 29, 'prize' => 'first prize ', 'V' => 0 ),
- '1' => array ('id' => 2, 'Min' => 302, 'max '=> 328, 'prize' => 'second prize ', 'V' => 0 ),
- '2' => array ('id' => 3, 'Min' => 242, 'max '=> 268, 'prize' => 'third prize ', 'V' => 0 ),
- '3' => array ('id' => 4, 'Min' => 182, 'max '=> 208, 'prize' => '4 ', 'V' => 0 ),
- '4' => array ('id' => 5, 'Min' => 122, 'max '=> 148, 'prize' => 'fifth runner ', 'V' => 0 ),
- '5' => array ('id' => 6, 'Min' => 62, 'max '=> 88, 'prize' => '6 ', 'V' => 0 ),
- '6' => array ('id' => 7, 'Min' => array (152,212,272,332, 58,118,178,238,298,358), 'Max' => array ), 'prize' => '7', 'V' => 100)
- );
- // Obtain a random Prize
- Foreach ($ prize_arr as $ v ){
- $ ProArr [$ v ['id'] = $ v ['V'];
- }
- $ Rid = $ this-> getRand ($ proArr); // obtain the award id based on the probability.
- $ Res = $ prize_arr [$ rid-1]; // medium Award
- // Dd ($ res); die;
- $ Min = $ res ['Min'];
- $ Max = $ res ['Max'];
- If ($ res ['id'] = 7) {// 7.
- $ I = mt_rand (0, 5 );
- $ Result ['angle '] = mt_rand ($ min [$ I], $ max [$ I]);
- } Else {
- $ Result ['angle '] = mt_rand ($ min, $ max); // randomly generate an angle
- }
- $ Result ['prize'] = $ res ['prize'];
- Echo json_encode ($ result );
- }
- Protectedfunction getRand ($ proArr ){
- $ Result = '';
- // The total probability precision of the probability Array
- $ ProSum = array_sum ($ proArr );
- // Probability array Loop
- Foreach ($ proArr as $ key => $ proCur ){
- $ RandNum = mt_rand (1, $ proSum );
- If ($ randNum <= $ proCur ){
- $ Result = $ key;
- Break;
- } Else {
- $ ProSum-= $ proCur;
- }
- }
- Unset ($ proArr );
- Return $ result;
- }
- }
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.