简单随机抽奖小活动

小抽奖活动

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <title>lingquregister</title>
    <style type="text/css">
        .content {
            height: 74px;
            padding-top: 19em;
            text-align: center;
            clear: both;
        }
        div {
            -moz-border-radius: 2px;
            -webkit-border-radius: 2px;
        }
        input[type='button'] {
            -webkit-appearance: none;
            -moz-border-radius: 2px;
            -webkit-border-radius: 2px;
            resize: none;
        }

        .bu_lingqu {
            margin: 0 auto;
            height: 62px;
            width: 160px;
        }

            .bu_lingqu img {
                height: 62px;
                width: 160px;
            }

        .tk {
            position: absolute;
            left: 0px;
            top: 0px;
            font-size: 0.7em;
        }

        .money {
            position: absolute;
            top: 22%;
            left: 50%;
            margin-left: -110px;
            height: 82px;
            width: 220px;
        }

        .noMoney {
            position: absolute;
            top: 30%;
            left: 50%;
            margin-left: -110px;
            height: 62px;
            width: 220px;
        }

        .p1 {
            position: absolute;
            top: 36%;
            left: 50%;
            margin-left: -110px;
            width: 240px;
            color: white;
        }

        .p2 {
            position: absolute;
            top: 40%;
            left: 50%;
            margin-left: -100px;
            width: 220px;
            color: white;
        }

        .btn_ok {
            position: absolute;
            top: 52%;
            left: 50%;
            margin-left: -110px;
        }

            .btn_ok img {
                height: 62px;
                width: 220px;
            }
        .div_loading {
            position: absolute;
            top: 48%;
            left: 50%;
            margin:-40px;
            display:none;
        }
        .div_confirm {
            height:60px;
            width:180px;
            position: absolute;
            top: 42%;
            left: 50%;
            margin:-90px;
            background-color:#808080;
            opacity:0.9;
            text-align:center;
            display:none;
        }
        .p_message {
            font-size:1em;
            line-height:2.5em;
        }
    </style>
    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/Scripts/Drow.js"></script>
</head>
<body>
    @RenderPage("head.cshtml")
    <div class="content">
        <div class="bu_lingqu">
            <img src="~/Content/themes/clickme.png" />
        </div>
    </div>
    @RenderPage("footer.cshtml")
    <div class="tk">
        <img class="bg" src="~/Content/themes/touming.png" />
        <div class="div_money"></div>
        <p class="p1">奖金已充入账户<span>138****2222</span>的电子钱包中,</p>
        <p class="p2">请于8月31日的注册莱尔美依账户领取。</p>
        <div class="btn_ok">
            <img src="~/Content/themes/确认按钮.png" />
        </div>
    </div>

    <!-- 等待载入画面 start -->
        <div class="div_loading">
            <img src="~/Content/themes/loading.png" style="height: 30px;width:80px"/>
        </div>

    <!-- congfirm区域 start -->
    <div class="div_confirm">
        <p class="p_message"></p>
        <p class="p_confirm">确认</p>
    </div>
</body>
</html><pre name="code" class="csharp">using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class Default1Controller : Controller
    {
        Models.bagContext db = new bagContext();
        //
        // GET: /Default1/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Drow(string userName)
        {
            int num = 0;
            try
            {
                var list = db.bags.Where(p => p.userName == userName).OrderByDescending(p => p.time);
                if (list.Count() == 0)
                {
                    num = CreateMoney();
                    bags bag = new bags();
                    bag.userName = userName;
                    bag.money = num;
                    bag.time = DateTime.Now;
                    db.bags.Add(bag);
                    int i = db.SaveChanges();
                    if (i == 0)
                    {
                        num = 0;
                    }
                    //Users user = db.Users.Single(p => p.UserName == userName);
                    //user.CreditsPlus += num;
                    //db.proc_insert_rechargelog(user.Id, "红包赠送", DateTime.Now, 0, num, 0);

                    //int i = db.SaveChanges();
                    //if (i == 0)
                    //{
                    //    num = 0;
                    //}

                }
                else {
                    num = -1;
                }
            }
            catch (Exception)
            {

            }
            return Content(num+"");
        }

        Random random = new Random();
        public int CreateMoney()
        {
            List<KeyValuePair<int, double>> elements = new List<KeyValuePair<int, double>>();

            elements.Add(new KeyValuePair<int, double>(200, 0.001));
            elements.Add(new KeyValuePair<int, double>(100, 0.002));

            elements.Add(new KeyValuePair<int, double>(0, 0.3));

            elements.Add(new KeyValuePair<int, double>(50, 0.697));

            int selectedElement = 0;

            double diceRoll = random.NextDouble();

            double cumulative = 0.0;

            for (int i = 0; i < elements.Count; i++)
            {
                cumulative += elements[i].Value;

                if (diceRoll <= cumulative)
                {
                    selectedElement = elements[i].Key;
                    break;
                }
            }
            return selectedElement;
        }

    }
}

 
$(document).ready(function () {
    $(".tk").hide();
    //test delete remember
    //localStorage.UserName="15680816067";
    if (!localStorage.UserName) {
        showconfirm("请先登陆!");
    }
    $(".bu_lingqu").click(function () {
        onSubmitStart(); username = localStorage.UserName;
        $.post("/Default1/Drow", { UserName: username}, function (data) {
            onSubmitEnd();
            if (data == -1) {
                showconfirm("您已经领过了哦!")
                return;
            }
            else if (data == 200)
                $(".div_money").append("<img class='money' src='/Content/themes/200.png' />");
            else if (data == 100)
                $(".div_money").append("<img class='money' src='/Content/themes/100.png' />");
            else if (data == 50)
                $(".div_money").append("<img class='money' src='/Content/themes/50.png' />");
            else {
                $(".div_money").append("<img class='noMoney' src='/Content/themes/0.png' />");
                $(".p1").hide(); $(".p2").hide();
            }
            $(".p1 span").html(username);
            $(".tk").slideDown(200);
            //test delete remember
            //localStorage.clear();
        })
    })
    function onSubmitStart() {
        $(".div_loading").show();
    }

    function onSubmitEnd() {
        $(".div_loading").hide();
    }

    function showconfirm(str) {
        $(".p_message").html(str);
        $(".div_confirm").slideDown();
    }

    $(".p_confirm").click(function () {
        //window.location = "";
        alert("跳走了~~")
    })
    $(".btn_ok").click(function () {
        //window.location = "";
        alert("跳走了~~")
    })
})



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值