PHP--翻牌活动(概率中奖..............)

控制器:

public function Remake(){
      //距离下场秒杀开始时间
        if(date('Y-m-d') == '2017-12-12'){
            if(date('H') < '10'){
                $time=strtotime(date('2017-12-12 10:00:00'))-time();
            }else if(date('H') < '18'){
                $time=strtotime(date('2017-12-12 18:00:00'))-time();
            }else{
                $time=0;
            }
        }
        //翻牌
        $this->Flop();
        //翻牌end
        $this->assign('time',$time);
        $this->display();
    }
private function Flop(){
        //翻牌
        if($this->uid){
            $flopcount_model=M('flopcount');
            $flopcount=$flopcount_model->find($this->uid);
            if(empty($flopcount)){
                $flopcount_model->uid=$this->uid;
                $flopcount_model->count=0;
                $flopcount_model->add();
                $this->assign("flopcount",0);
            }else{
                $this->assign("flopcount",$flopcount['count']);
            }
            $flop_ulist_model=M('flop_ulist');
            $flop_ulist1=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>1])->find();
            $flop_ulist2=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>2])->find();
            $flop_ulist3=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>3])->find();
            $flop_ulist4=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>4])->find();
            $flop_ulist5=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>5])->find();
            $flop_ulist6=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>6])->find();
            $flop_ulist7=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>7])->find();
            $flop_ulist8=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>8])->find();
            $this->assign("flop_ulist1",$flop_ulist1);
            $this->assign("flop_ulist2",$flop_ulist2);
            $this->assign("flop_ulist3",$flop_ulist3);
            $this->assign("flop_ulist4",$flop_ulist4);
            $this->assign("flop_ulist5",$flop_ulist5);
            $this->assign("flop_ulist6",$flop_ulist6);
            $this->assign("flop_ulist7",$flop_ulist7);
            $this->assign("flop_ulist8",$flop_ulist8);
        }else{
            $this->assign("flopcount",0);
        }
        //翻牌end
    }
public function open(){
        if($this->isAjax()){
            if(strtotime(C('FLOP_ENDTIMES'))<time())ajaxmsg('活动已结束',2);
            if(time()<strtotime(C('FLOP_STATUS_TIMES')))ajaxmsg('活动未开始',2);
            if(!$this->uid)ajaxmsg('请先登录',2);
            $flopcount_model=M('flopcount');
            $flopcount=$flopcount_model->getFieldByUid($this->uid,'count');
            if($flopcount>0){
                $flop_res=$flopcount_model->where(['uid'=>$this->uid])->setDec('count');
                if($flop_res){
                    if(mt_rand(0,1)){
                        $FLOP_TYPE=C('FLOP_TYPE');
                        $flop_goods_model=M('flop_goods');
                        $type_arr=$flop_goods_model->field('type')->where(['last_num'=>['gt',0]])->select();
                        if(!empty($type_arr)){//没牌了就都是没中的牌
                            $type=$type_arr[array_rand($type_arr,1)]['type'];//随机
                            $flop_goods_updata['last_num']=['exp',"last_num-1"];
                            $flop_goods_updata['hits']=['exp',"hits+1"];
                            $flop_goods_model->where(['type'=>$type])->save($flop_goods_updata);//减少牌数
                            $flop_ulist_model=M('flop_ulist');
                            $flop_ulist_find=$flop_ulist_model->where(['type'=>$type,'uid'=>$this->uid])->find();//增加用户里面的牌
                            if(empty($flop_ulist_find)){//查询有没有记录
                                $flop_ulist_model->uid=$this->uid;
                                $flop_ulist_model->type=$type;
                                $flop_ulist_model->num=1;
                                $flop_ulist_model->last_num=1;
                                $flop_ulist_model->hits=0;
                                $flop_ulist_model->add();
                            }else{
                                $flop_ulist_map['uid']=$this->uid;
                                $flop_ulist_map['type']=$type;
                                $flop_ulist_updata['num']=['exp',"num+1"];
                                $flop_ulist_updata['last_num']=['exp',"last_num+1"];
                                $flop_ulist_model->where($flop_ulist_map)->save($flop_ulist_updata);
                            }
                            ajaxmsg($FLOP_TYPE[$type]['imgurl']);
                        }else{
                            ajaxmsg('/Style/suim/pubilc/image/flop/bl_no.png');
                        }
                    }else{
                        ajaxmsg('/Style/suim/pubilc/image/flop/bl_no.png');
                    }
                }else{
                    ajaxmsg('服务器繁忙',2);
                }
            }else{
                ajaxmsg('次数不足',2);
            }
        }
    }
 //兑换
    public function exchange(){
        if($this->isAjax()){
            if(!$this->uid)ajaxmsg('请先登录',2);
            $types=$this->_post('types');
            $flop_ulist_model=M('flop_ulist');
            if($types!=1 && $types!=2 && $types!=3 && $types!=4)ajaxmsg("参数错误",2);
            $flop_ulist1=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>1])->find();//
            $flop_ulist2=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>2])->find();//
            $flop_ulist3=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>3])->find();//
            $flop_ulist4=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>4])->find();//
            $flop_ulist5=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>5])->find();//
            $flop_ulist6=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>6])->find();//
            $flop_ulist7=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>7])->find();//
            $flop_ulist8=$flop_ulist_model->field('last_num')->where(['uid'=>$this->uid,'type'=>8])->find();//

            $market_log_model=M('market_log');
            $true=false;
            $flop_ulist_map['uid']=$this->uid;
            $flop_ulist_updata['last_num']=['exp','last_num-1'];
            $flop_ulist_updata['hits']=['exp','hits+1'];

            if($types==1 && $flop_ulist1['last_num']>0 && $flop_ulist2['last_num']>0){
                $market_log_model->gid=76;//商品ID
                $market_log_model->name='10元现金红包';//名称
                $market_log_model->price=10;//价值
                $market_log_model->cost=0;//兑换积分
                $flop_ulist_map['type']=['in','1,2'];
                $flop_ulist_model->where($flop_ulist_map)->save($flop_ulist_updata);
                $true=true;
            }
            if($types==2 && $flop_ulist1['last_num']>0 && $flop_ulist2['last_num']>0 && $flop_ulist3['last_num']>0 && $flop_ulist4['last_num']>0){
                $market_log_model->gid=77;//商品ID
                $market_log_model->name='20元现金红包';//名称
                $market_log_model->price=20;//价值
                $market_log_model->cost=0;//兑换积分
                $flop_ulist_map['type']=['in','1,2,3,4'];
                $flop_ulist_model->where($flop_ulist_map)->save($flop_ulist_updata);

                $true=true;
            }
            if($types==3 && $flop_ulist1['last_num']>0 && $flop_ulist2['last_num']>0 && $flop_ulist3['last_num']>0 && $flop_ulist4['last_num']>0 && $flop_ulist5['last_num']>0 && $flop_ulist6['last_num']>0){
                $market_log_model->gid=78;//商品ID
                $market_log_model->name='50元话费';//名称
                $market_log_model->price=50;//价值
                $market_log_model->cost=0;//兑换积分
                $flop_ulist_map['type']=['in','1,2,3,4,5,6'];
                $flop_ulist_model->where($flop_ulist_map)->save($flop_ulist_updata);
                $true=true;
            }
            if($types==4 && $flop_ulist1['last_num']>0 && $flop_ulist2['last_num']>0 && $flop_ulist3['last_num']>0 && $flop_ulist4['last_num']>0 && $flop_ulist5['last_num']>0 && $flop_ulist6['last_num']>0 && $flop_ulist7['last_num']>0 && $flop_ulist8['last_num']>0){
                $market_log_model->gid=79;//商品ID
                $market_log_model->name='100元现金红包';//名称
                $market_log_model->price=100;//价值
                $market_log_model->cost=0;//兑换积分
                $flop_ulist_map['type']=['in','1,2,3,4,5,6,7,8'];
                $flop_ulist_model->where($flop_ulist_map)->save($flop_ulist_updata);
                $true=true;
            }
            if($true){
                $market_log_model->uid=$this->uid;
                $market_log_model->type=1;
                $market_log_model->style='';
                $market_log_model->num=1;//兑换数量
                $market_log_model->info="处理中";//信息
                $market_log_model->add_ip=get_client_ip();
                $market_log_model->add_time=time();
                $market_log_model->status= 0;//未领取
                $market_log_model->way= 2;//快递
                $market_log_model->way= 2;//快递
                $market_log_model->add();
                ajaxmsg("兑换成功");
            }else{
                ajaxmsg("兑换失败",2);
            }
        }
    }

前端展示:

<include file="Pub:header-up" />
<title>赚翻双十二,翻卡牌赢大奖</title>
<style>
    .content {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        overflow: auto;}
    .activity img {
        width: 100%;
        margin: 0;
        padding: 0;
        display: block;
        /*pointer-events: none;*/
    }
    .activity-register {
        position: relative;
    }
    .activity-register-nav-2 {
        position: absolute;
        width: 90%;
        top: 0;
        left: 50%;
        right: 50%;
        margin-left: -45%;
        border-radius: .5rem;
        text-align: center;
    }
    .activity-register .activity-register-nav-2 .activity-input {
        width: 75%;
        height: 1.8rem;
        display: inline-block;
        border-radius: .2rem;
        display: inline-block;
        margin: 0 auto;
        background-color: white;
        text-align: left;
        margin-bottom: .6rem;
    }
    li{list-style-type:none;float:left}
    em{font-style: normal}
    .seckill_time{margin-top:2rem;color:#fff;font-size:.5rem;line-height:1.1rem}
    .opportunity em,.seckill_time em{display:inline-block;background:#fff;height:1rem;width:1rem;margin-right:.1rem;color:#000}
    .active_time{text-align:center;color:rgb(168,99,253);font-size:.6rem;line-height:1.1rem}
    .active_typw img{width:38%;float:left;text-align: center}
    .opportunity{font-size: .7rem;color:rgb(255,180,100);}
    .opportunity em{background:rgb(233,212,127);color:rgb(193,47,8);border-radius: 5px;text-align: center}
    .nu img{
        width: 10%;
    }
    .activity-register .my_num img{width: 10%;float: left}
    .duih{float:left;width: 40%;margin: 0rem 0.5rem}
    .duihuan{padding:0rem 1rem}
    .artGroup {display: block;width: 25%;height: 80px; position: relative;float: left;}
    .artwork {display: block;width: 100%;height: 100%;}
    .artGroup img {width: 100%;
        height: 100%;
        position: absolute;
        display: block;
    }
    .artGroup .detail {
        display: block;
        /*background: #fff;*/
        width: 100%;
        height: 100%;
        position: absolute;
    }
    .artGroup .detail h3 {
        font: 300 18px/1.1 Raleway,"Microsoft YaHei",Dosis, sans-serif;
        text-align: center;
        color: orange;
    }
    .artGroup .detail p {
        font: 200 13px/1.2 Raleway,"Microsoft YaHei",Dosis, sans-serif;
        text-align: left;
        padding: 0 0.25em;
    }
    article {
        clear: both;
        font: 300 15px/1.2 Raleway,"Microsoft YaHei",Dosis, sans-serif;
        margin: 2em auto;
        max-width: 600px;
    }

    /* Older Browsers */
    .artGroup.slide {
        overflow: hidden;
    }
    .artGroup.slide .detail {
        bottom: -364px;
    }
   /* .artGroup.flip .detail>img{
       display: none;
    }*/

    /* Newer Browsers */
    .artGroup.flip {
        -webkit-perspective: 800px;
        perspective: 800px;
    }
    .artGroup.flip .artwork {
        -webkit-transition: -webkit-transform 1s ease;
        transition: transform 1s ease;

        -webkit-transform-style: preserve-3d;
        transform-style: preserve-3d;
    }

    .artGroup.flip .detail, .artGroup.flip .theFlip {
        -webkit-transform: rotateY(-180deg);
        transform: rotateY(-180deg);
    }

    .artGroup.flip img {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    .content-padded {
        margin: .8rem;
    }
</style>
<div class="content activity">
    <img src="__ROOT__/Style/active/wapimg/bg_01.png">
    <a name="regist"></a>
    <div class="activity-register">
        <img src="__ROOT__/Style/active/wapimg/bg_02.png">
        <div class="activity-register-nav-2">
            <div class="seckill_time" id="seckill_time">距离下场秒杀开始时间:<em id='hour'></em><em id='minute'></em><em id='second'></em></div>
            <div class="active_time">活动时间:2017.12.12</div>
            <div style="text-align:center">
                <div class="active_typw">
                    <img src="__ROOT__/Style/active/wapimg/tzq_blue_g.png" id="am"style="margin:0rem 1.5rem">
                    <img src="__ROOT__/Style/active/wapimg/tzq_red_g.png" id="pm">
                </div>
            </div>
        </div>
    </div>
    <img src="__ROOT__/Style/active/wapimg/jk_01.png">
    <div class="activity-register">
        <img src="__ROOT__/Style/active/wapimg/jk_02.png">
        <div class="activity-register-nav-2">
            <div class="opportunity" style="height: .9rem"></div>
            <div style="margin:auto;background:rgb(193,47,8);width: 88%">
                <div style="width:7.5rem;color:rgb(255,180,100)">您还有<span id="count">{$flopcount}</span>次机会</div>
            </div>
            <div class="fpai">
                <div style="margin: auto;width:85%;overflow:auto">
                    <div class="fanpai" style="overflow: auto;text-align:center;">
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="artGroup slide">
                            <div class="artwork"> <img src="__ROOT__/Style/active/wapimg/kapian.png">
                                <div class="detail">
                                    <img src="__ROOT__/Style/active/wapimg/kapian_k.png" alt="">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="activity-register-nav-2">
        </div>
        <div class="activity-register">
            <img src="__ROOT__/Style/active/wapimg/jk_03.png">
            <div class="activity-register-nav-2">
                <div style="height: .8rem"></div>
                <div style="margin: auto;width:95%;height: 160px;margin-top:0.3rem ">
                    <div class="content" style="margin-top:0.1rem">
                        <div class="content-padded grid-demo">
                            <div class="row">
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist1.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_1.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist2.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_2.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist3.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_3.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist4.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_4.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist5.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_5.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist6.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_6.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25)">{$flop_ulist7.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_7.png"></li>
                                </div>
                                <div class="col-25" style="text-align:right">
                                    <em style="margin-right:0.3rem;color:rgb(231,78,25);">{$flop_ulist8.last_num|default=0}</em>
                                    <li style="margin-top:-1.3rem"><img src="__ROOT__/Style/active/wapimg/text_8.png"></li>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <img src="__ROOT__/Style/active/wapimg/jkp_02.png" >
        </div>
        <div class="activity-register">
            <img src="__ROOT__/Style/active/wapimg/dhbg_01.png" alt="">
        </div>
        <div class="activity-register">
            <img src="__ROOT__/Style/active/wapimg/dhbg_02.png" width="100%">
            <div class="activity-register-nav-2">
                <div style="overflow: auto" class="duihuan">
                    <div class="duih" data="1">
                        <img src="__ROOT__/Style/active/wapimg/dhsp_01.png"  >
                    </div>
                    <div class="duih" data="2">
                        <img src="__ROOT__/Style/active/wapimg/dhsp_02.png">
                    </div>
                </div>
                <div style="overflow: auto;margin-top: 1rem" class="duihuan">
                    <div class="duih" data="3">
                        <img src="__ROOT__/Style/active/wapimg/dhsp_03.png"  >
                    </div>
                    <div class="duih" data="4">
                        <img src="__ROOT__/Style/active/wapimg/dhsp_04.png">
                    </div>
                </div>
            </div>
        </div>
        <div class="activity-register">
            <img src="__ROOT__/Style/active/wapimg/bg_05.jpg" width="100%">
        </div>
    </div>

</div>
<script src="__ROOT__/Style/active/js/jquery.js"></script>
<script type="text/javascript">
    $(function () {
        $('.artGroup').removeClass('slide').addClass('flip');
        $('.artGroup').on('click', function () {
            var ff=$(this);
            $.post({
                url:"__URL__/open",
                dataType:"json",
                type:"post",
                success:function (data) {
                    if(data.status==1){
                        ff.find('.detail img').attr('src',data.message);
                        ff.find('.artwork').addClass('theFlip');
                        $("#count").text($("#count").text()-1);
                    }else{
                        alert(data.message);
                    }
                }
            });
        });
    });
    $(".duih").click(function () {
        $.post({
            url:"__URL__/exchange",
            dataType:"json",
            type:"post",
            data:{types:$(this).attr('data')},
            success:function (data) {
                alert(data.message);
                if(data.status==1){
                    setTimeout( function(){window.location.href="/market/my_exchange";} , 1500);
                }
            }
        });
    })
    $("#am").click(function(){
        var type = 1;
        $.ajax({
            url:'__URL__/envelopeSnatching',
            type:'post', 
            dataType:'json',
            data:{type:type}, 
            success:function(data){ 
                alert('您来晚了,券已抢完!'); 
            } 
        }); 
    }); 
    $("#pm").click(function(){ 
        var type = 2; 
        $.ajax({ 
            url:'__URL__/envelopeSnatching', 
            type:'post', 
            dataType:'json', 
            data:{type:type}, 
            success:function(data){ 
                alert('您来晚了,活动已经结束了!'); 
            } 
        }); 
    }); 
    var time='{$time}'; 
    if(time == 0){ 
        $("#hour").html('00');//计算小时  
        $("#minute").html('00');//计算分钟  
        $("#second").html('00');//计算秒杀  
    }else{ 
        var hour_elem = $('#hour'); 
        var minute_elem = $('#minute'); 
        var second_elem = $('#second'); 
        var timer = setInterval(function(){ 
            if(time > 1){ 
                var hour = Math.floor((time / 3600) % 24); 
                var minute = Math.floor((time / 60) % 60);
                var second = Math.floor(time % 60); 
                $("#hour").text(hour<10?"0"+hour:hour);//计算小时  
                $("#minute").text(minute<10?"0"+minute:minute);//计算分钟  
                $("#second").text(second<10?"0"+second:second);//计算秒杀 --time; 
            }else{ 
                clearInterval(timer); 
            } },1000); 
    } 
    </script>

 

posted @ 2018-12-22 19:10  爱跑步的乌龟  阅读(287)  评论(0编辑  收藏  举报