摘要:抽獎地址主要代碼其他引用可以在上面地址頁面根據引用地址下載頁面點我注冊立即簽到抽獎次數前名九宮格抽獎
抽獎地址:https://www.huijindaicn.com/i...
主要代碼:(其他引用可以在上面地址頁面根據引用地址下載)
1、html頁面
2、js 主要代碼
lottery.js: var lottery = { index: 0, //當前轉動到哪個位置,起點位置 count: 16, //總共有多少個位置 timer: 0, //setTimeout的ID,用clearTimeout清除 speed: 20, //初始轉動速度 times: 0, //轉動次數 cycle: 50, //轉動基本次數:即至少需要轉動多少次再進入抽獎環節 prize: -1, //中獎位置 init: function(id) { if ($("#" + id).find(".lottery-unit").length > 0) { $lottery = $("#" + id); $units = $lottery.find(".lottery-unit"); this.obj = $lottery; this.count = $units.length; $lottery.find(".lottery-unit-" + this.index).addClass("active"); } }, roll: function() { var index = this.index; var count = this.count; var lottery = this.obj; $(lottery).find(".lottery-unit-" + index).removeClass("active"); index += 1; if (index > count - 1) { index = 0; } $(lottery).find(".lottery-unit-" + index).addClass("active"); this.index = index; return false; }, stop: function(index) { this.prize = index; return false; } }; function roll() { lottery.times += 1; lottery.roll(); var prize_site = $("#lottery").attr("prize_site"); if (lottery.times > lottery.cycle + 10 && lottery.index == prize_site) { // var prize_id = $("#lottery").attr("prize_id"); var prize_name = $("#lottery").attr("prize_name"); // alert("中獎名稱:"+prize_name+" 中獎id:"+prize_id); $.showSuccess("恭喜你中得 "+ prize_name,function(){ get_win_num(); get_win_list(); get_tot_num(); }); clearTimeout(lottery.timer); lottery.prize = -1; lottery.times = 0; click = false; } else { if (lottery.times < lottery.cycle) { lottery.speed -= 10; } else if (lottery.times == lottery.cycle) { var index = Math.random() * (lottery.count) | 0; lottery.prize = index; } else { if (lottery.times > lottery.cycle + 10 && ((lottery.prize == 0 && lottery.index == 7) || lottery.prize == lottery.index + 1)) { lottery.speed += 110; } else { lottery.speed += 20; } } if (lottery.speed < 40) { lottery.speed = 40; } lottery.timer = setTimeout(roll, lottery.speed); } return false; } /* 獲取中獎列表 */ function get_win_list(){ $.get("/index.php?ctl=lottery&pc_ct=get_new_win&num=100", function(a){ // console.log(a); if(typeof a != "object"){ return; } for(k in a){ html = "
3、php代碼(獎品獲取代碼)
// 搖獎操作 獲取中獎結果 并返回 信息 private function get_win() { $user_id = intval($GLOBALS["user_info"]["id"]); $type = isset($_REQUEST["type"]) && preg_match("/^w+$/", $_REQUEST["type"]) ? $_REQUEST["type"] : "t_box"; $json = array("code" => 0, "msg" => "", "uid" => $user_id); if(!$user_id){ $json["msg"] = "請登錄后再試!"; $json["status"] = 2; es_session::set("gopreview", "/index.php?ctl=user&act=login"); return $json; } $base_score = 300; $user_num = $GLOBALS["db"]->getOne("SELECT num from ".DB_PREFIX."turntable_user_num where user_id = {$user_id} AND type = "t_box""); $user_num = $user_num ? $user_num : 0; $user_score = $GLOBALS["db"]->getOne("SELECT score from ".DB_PREFIX."user where id = {$user_id}"); $tot_num = intval($user_score/$base_score) + intval($user_num); // return $user_num; if(!$tot_num){ // 積分不足且沒有贈送的抽獎次數 $json["msg"] = "您的積分不足,通過投資或簽到可獲取相應積分!"; $json["status"] = 3; $json["data"] = $_data; return $json; } // 可抽中獎品列表 $arr = array( "0" => array("id"=>0,"good_id"=>50,"name"=>"平臺10積分","v"=>15), "1" => array("id"=>1,"good_id"=>70,"name"=>"智能折疊代步車","v"=>1), "2" => array("id"=>2,"good_id"=>54,"name"=>"理財紅包5元","v"=>30), "3" => array("id"=>3,"good_id"=>66,"name"=>"藍牙運動耳機","v"=>0), "4" => array("id"=>4,"good_id"=>51,"name"=>"平臺50積分","v"=>15), "5" => array("id"=>5,"good_id"=>68,"name"=>"遙控四軸飛行器","v"=>1), "6" => array("id"=>6,"good_id"=>53,"name"=>"理財紅包18元","v"=>20), "7" => array("id"=>7,"good_id"=>60,"name"=>"LED充電臺燈","v"=>5), "8" => array("id"=>8,"good_id"=>52,"name"=>"平臺300積分","v"=>10), "9" => array("id"=>9,"good_id"=>59,"name"=>"20元話費","v"=>5), "10" => array("id"=>10,"good_id"=>67,"name"=>"太陽能充電器","v"=>3), "11" => array("id"=>11,"good_id"=>58,"name"=>"10元話費","v"=>10), "12" => array("id"=>12,"good_id"=>56,"name"=>"理財紅包58元","v"=>10), "13" => array("id"=>13,"good_id"=>61,"name"=>"24小時保溫杯","v"=>10), "14" => array("id"=>14,"good_id"=>57,"name"=>"理財紅包88元","v"=>1), "15" => array("id"=>15,"good_id"=>69,"name"=>"智能運動手環","v"=>5), ); $user_ids = array( "13" => array(20861,3661,20631,7433,2447,7239,12471,3338,13031,12070), // 24小時保溫杯 "15" => array(2086,8824,6699,747,2291,1127,2955,2408,5127,12070), // 智能運動手環 ); /* 正常抽獎 */ $key = $this->get_rand($arr); $win = $arr[$key]; /* 特殊客戶 抽實物 */ $g_count = $GLOBALS["db"]->getOne("SELECT count(*) FROM ".DB_PREFIX."turntable_user_goods WHERE user_id = ".$GLOBALS["user_info"]["id"]." AND type="t_box" AND goods_id IN(61,66,67,68,69,70)"); foreach ($user_ids as $k => $v) { if(in_array($user_id, $v) && !$g_count) { $win = $arr[$k]; break; } } $good = $GLOBALS["db"]->getRow("SELECT * FROM ".DB_PREFIX."turntable_goods WHERE id = ".$win["good_id"]); // 抽獎成功 if(!empty($good)) { // 扣除抽獎積分,或贈送機會 $this->upadte_user_num_score($user_num,$user_score); // 添加獎品給用戶 $this->update_user_goods($good); return array( "code" => 1, "status" => 1, "win" => array( "id" => $win["id"], "name" => $good["name"], ), ); }else{ return array("code" => 0, "status" => 4, "msg" => "該活動 處于關閉狀態,詳情咨詢客服!"); } } // 抽獎概率算法 private function get_rand($proArr) { $result = ""; foreach ($proArr as $key => $val) { $arr[$key] = $val["v"]; } // 概率數組的總概率 $proSum = array_sum($arr); // 概率數組循環 foreach ($arr as $k => $v) { $randNum = mt_rand(1, $proSum); if ($randNum <= $v) { $result = $k; break; } else { $proSum -= $v; } } return $result; } // 獲取最新中獎列表 private function get_new_win() { $num = isset($_REQUEST["num"]) ? intval($_REQUEST["num"]) : 10; $type = isset($_REQUEST["type"]) ? $_REQUEST["type"] : "t_box"; $list = array(); $sql = "SELECT g.id, g.user_id, u.user_name, g.goods_id, g.goods_name, g.time FROM ".DB_PREFIX."turntable_user_goods g LEFT JOIN ".DB_PREFIX."user u ON u.id = g.user_id WHERE g.is_effect = 1 AND g.type = "{$type}" ORDER BY g.id DESC limit {$num}"; $list = $GLOBALS["db"]->getAll($sql); if(is_array($list)){ foreach ($list as $key => $v) { $list[$key]["user_name"] = utf_substr($v["user_name"]); } } return array("list" => $list); } /* 獲取中獎前五名 */ private function get_tot_num() { $sql = "SELECT count(*) as num,u.user_name FROM fanwe_turntable_user_goods t LEFT JOIN fanwe_user u ON t.user_id = u.id WHERE t.type = "t_box" GROUP BY t.user_id ORDER BY num desc LIMIT 5"; $list = $GLOBALS["db"]->getAll($sql); if(is_array($list)){ foreach ($list as $key => $v) { $list[$key]["user_name"] = utf_substr($v["user_name"]); } } return $list; } // 獲取自己所剩抽獎次數 和 積分 private function get_win_num() { $types = isset($_REQUEST["types"]) ? $_REQUEST["types"] : "t_box"; $arr = array(); $user_num = $GLOBALS["db"]->getOne("SELECT num from ".DB_PREFIX."turntable_user_num where user_id = {$GLOBALS["user_info"]["id"]} AND type = "t_box""); $user_score = $GLOBALS["db"]->getOne("SELECT score from ".DB_PREFIX."user where id = {$GLOBALS["user_info"]["id"]}"); $user_num = $user_num ? $user_num : 0; $arr["num"] = intval($user_score/300) + intval($user_num); $arr["score"] = $user_score; $arr["count"] = $GLOBALS["db"]->getOne("SELECT count(*) FROM ".DB_PREFIX."turntable_user_goods WHERE user_id = ".$GLOBALS["user_info"]["id"]." AND type="t_box""); return $arr; }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/50249.html
摘要:京東券電影票淘寶券代碼如下按照概率抽取一個獎品返回獎品所有獎品的概率總和應該為總概率基數方式二該方式如果直接看代碼比較難理解。 首發于 樊浩柏科學院 需求:首先用戶通過以一定方式(好友點贊等)開啟抽獎資格,然后按照用戶 100% 中獎概率進行抽獎,且系統的發放獎品需要按照各個獎品整體的期望中獎比例來進行分布,最后用戶抽中獎品調用第三方發放接口發放獎品并記錄保存,另有些獎品存在發放數量...
摘要:演示下載地址效果圖三個金蛋一把錘子及中獎結果代碼如下錘子當鼠標滑向金蛋時,錘子會僅靠金蛋右上方,通過來控制位置。當揮動錘子砸向金蛋前,我們先把金蛋中的數字編號隱藏起來。最后,我們向后臺發送一個請求,后臺程序會處理獎項分配并把中獎結果返回。 演示下載地址:http://www.erdangjiade.com/js...效果圖:showImg(https://segmentfault.co...
閱讀 550·2021-11-25 09:44
閱讀 2636·2021-11-24 09:39
閱讀 2305·2021-11-22 15:29
閱讀 3520·2021-11-15 11:37
閱讀 3379·2021-09-24 10:36
閱讀 2507·2021-09-04 16:41
閱讀 992·2021-09-03 10:28
閱讀 1833·2019-08-30 15:55