做的一个项目 :涉及抽奖的转盘

做的一个项目 :涉及抽奖的转盘_第1张图片
[百度网盘链接链接html页面: https://pan.baidu.com/s/1U2T6JIVTlapjawvV9gE8qw
取码:ciw3
复制这段内容后打开百度网盘手机App,操作更方便哦]

前段点击go 请求代码

$('.pointer2').click(function (){
		    var token = "{$_GET['token']}";
		    var sign = "{$_GET['sign']}";
		    if(turnplate.bRotate)return;
			turnplate.bRotate = !turnplate.bRotate;
			//获取随机数(奖品个数范围内)
			var item;
            $.ajax({
                url: "index.php?s=shop&c=memberinfo&m=dazhuanpan&token="+token+"&sign="+sign,
                type: 'GET',
                dataType: 'json',
                async: false,
                success: function(res){
                    if(res.code==1){
                        console.log(res);
                        item = res.data.result;
                        var t = $('.turnplate').find('span');
                        var number = t.text()-1<0 ? 0 : t.text()-1;
                        t.text(number)                        
                    } else if(res.code==-2){
                        alert(res.msg);
                    } else {
                        item = -1;
                        showRule();
                    }
                }
            })
			//奖品数量等于10,指针落在对应奖品区域的中心角度[252, 216, 180, 144, 108, 72, 36, 360, 324, 288]
			if(turnplate.restaraunts[item-1]=="谢谢参与"){
				rotateFn(item,"谢谢参与");
			}else if(item>=0){
				rotateFn(item,"获得:
"+turnplate.restaraunts[item-1]); } });

请求的接口

// 大转盘
    public function dazhuanpan(){
        $get = $this->input->get();
        if($get['token'] && $get['sign']){
            $this->uid = $this->models('member/login')->authcode_check($get['token'], $get['sign']);
        }
        $uid= (int)$this->uid;
        //读取后台配置【注index,1~6】
        $config = $this->db->where("rate!=0")->order_by("id")->get(SITE_ID . "_reward")->result_array();
        if(IS_AJAX){
            //暂定扣除30积分后台设置
            $value = (int)dr_var("kcjf");
            $experience = (int)dr_member_info($uid)['experience'];
            if($experience > $value){
                // var_dump($experience - $value);die;
              $this->db->set("experience","experience -".$value,FALSE)->where('uid',$uid)->update('member'); 
            }else{
                x_json(0,$uid,'积分不足');
            }
            // 确认抽奖机会,标记已抽奖
            $mark = "admin_test";
            //构建奖池,进行抽奖
            $floor = 0;
            $weight = array_column($config,"rate");
            
            foreach($weight as $t){
                $pool[] = $floor+$t;
                $floor += $t;
            }
            
            $rand = rand(1,$floor);
            foreach($pool as $i=>$t){
                if($t>=$rand){
                    $index = 1+$i;
                    break;
                }
            }
            
            //奖品存量不足,自动转向“抽空项”
            if($config[$index-1]['nums']==0){
                x_json(array(
                    "result"=>(sizeof($config)),
                    ));
            }
            //发放奖品
            if($config[$index-1]['types']==1){
                //积分直接发放
                // $score = dr_string2arrays($config[$index-1]['config'])['discount'];
                $score =(int)$config[$index-1]['discount'];
                $this->db->set("experience","experience +".$score,FALSE)->where("uid",$uid)->update("member");
                $this->db->insert(SITE_ID . "_reward_experience",array(
                    "uid" => $uid,
                    "type" => 0,
                    "value" => $score,
                    "mark" => "dazhuanpan",
                    "note" => "转盘抽奖",
                    "inputtime" => SYS_TIME
                    ));
               
            }
            $conf = dr_string2arrays($config[$index-1]['config']);
               
            $this->db->insert(SITE_ID . "_reward_record",array(
                "uid" => $uid,
                "alevel" => $config[$index-1]['id'] - 12,
                "award" => $config[$index-1]['title'],
                "value" => $config[$index-1]['types']==1?(int)$config[$index-1]['discount']:0,
                "inputtime" => SYS_TIME,
                "mark" => $mark,
                'status' =>9,
                ));
            //更新奖品数量
            $this->db->set("nums","nums - 1 ",FALSE)->where("id",$index)->update(SITE_ID . "_reward");
            //通知结果
           
            x_json(array("result"=>$index));
        }
        $this->template->assign(array(
            "award" => array_column($config,"title"),
            "uid" => $uid));
        $this->template->display("dazhuanpan.html");
        
    }

你可能感兴趣的:(php)