国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

php抽獎實現

fsmStudy / 2506人閱讀

摘要:抽獎地址主要代碼其他引用可以在上面地址頁面根據引用地址下載頁面點我注冊立即簽到抽獎次數前名九宮格抽獎

抽獎地址: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 = "
    "; for(i = 0, l = a[k].length; i < l; i++){ html += "
  • "+ a[k][i].user_name +""+ a[k][i].goods_name +"
  • "; } html += "
"; $(".lottery-list").html(html); } /* 中獎列表滾動插件 */ $(".lottery-list ul").totemticker({ row_height: "21px", next: "#ticker-next", previous: "#ticker-previous", stop: "#stop", start: "#start", mousestop: true }); }, "json"); } /* 獲取剩余抽獎次數 */ function get_win_num(){ $.get("/index.php?ctl=lottery&pc_ct=get_win_num&type=t_box", function(a){ if(typeof a != "object"){ return; } $(".score").html(a.score); $(".num").html(a.num); $(".count").html(a.count); }, "json"); } /* 獲取抽獎排行 */ function get_tot_num(){ $.get("/index.php?ctl=lottery&pc_ct=get_tot_num", function(a){ if(typeof a != "object"){ return; } var html = ""; $.each(a, function(i, n){ html = html+""+(i+1)+":"+n.user_name+"("+n.num+"次)"; }); $(".c_count").html(html); }, "json"); } var click = false; $(function() { var ajax_url = "/index.php?ctl=lottery&pc_ct=get_win"; lottery.init("lottery"); /* 開始抽獎 */ $("#lottery a").click(function() { console.log(click); if (click) { return false; } else { $.post(ajax_url, {uid: 1}, function(a) { // 獲取獎品,也可以在這里判斷是否登陸狀態 if(!a.code){ var _url = a.status == 2 ? "/index.php?ctl=user&act=login" : "/index.php?ctl=deals"; return $.showErr(a.msg, function(){window.location = _url;}); }else if(a.win){ $("#lottery").attr("prize_site", a.win.id); $("#lottery").attr("prize_name", a.win.name); lottery.speed = 100; roll(); click = true; return false; }else{ $.showSuccess("通訊錯誤 稍后再試"); } }, "json") } }); /*獲取積分和用戶抽獎次數*/ get_win_num(); /*獲取中獎信息*/ get_win_list(); /* 獲取抽獎前十名 */ get_tot_num(); })

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/22098.html

相關文章

  • php抽獎實現

    摘要:抽獎地址主要代碼其他引用可以在上面地址頁面根據引用地址下載頁面點我注冊立即簽到抽獎次數前名九宮格抽獎 抽獎地址:https://www.huijindaicn.com/i...主要代碼:(其他引用可以在上面地址頁面根據引用地址下載)1、html頁面 ...

    IamDLY 評論0 收藏0
  • php抽獎實現

    摘要:抽獎地址主要代碼其他引用可以在上面地址頁面根據引用地址下載頁面點我注冊立即簽到抽獎次數前名九宮格抽獎 抽獎地址:https://www.huijindaicn.com/i...主要代碼:(其他引用可以在上面地址頁面根據引用地址下載)1、html頁面 ...

    hlcfan 評論0 收藏0
  • php抽獎實現

    摘要:抽獎地址主要代碼其他引用可以在上面地址頁面根據引用地址下載頁面點我注冊立即簽到抽獎次數前名九宮格抽獎 抽獎地址:https://www.huijindaicn.com/i...主要代碼:(其他引用可以在上面地址頁面根據引用地址下載)1、html頁面 ...

    MangoGoing 評論0 收藏0
  • 按照獎品概率分布抽獎實現

    摘要:京東券電影票淘寶券代碼如下按照概率抽取一個獎品返回獎品所有獎品的概率總和應該為總概率基數方式二該方式如果直接看代碼比較難理解。 首發于 樊浩柏科學院 需求:首先用戶通過以一定方式(好友點贊等)開啟抽獎資格,然后按照用戶 100% 中獎概率進行抽獎,且系統的發放獎品需要按照各個獎品整體的期望中獎比例來進行分布,最后用戶抽中獎品調用第三方發放接口發放獎品并記錄保存,另有些獎品存在發放數量...

    Tamic 評論0 收藏0
  • jQuery+PHP實現砸金蛋抽獎

    摘要:演示下載地址效果圖三個金蛋一把錘子及中獎結果代碼如下錘子當鼠標滑向金蛋時,錘子會僅靠金蛋右上方,通過來控制位置。當揮動錘子砸向金蛋前,我們先把金蛋中的數字編號隱藏起來。最后,我們向后臺發送一個請求,后臺程序會處理獎項分配并把中獎結果返回。 演示下載地址:http://www.erdangjiade.com/js...效果圖:showImg(https://segmentfault.co...

    Invoker 評論0 收藏0

發表評論

0條評論

fsmStudy

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<