Exemplo n.º 1
0
     //print_r($row);
     // echo "命中大概率".$currentTime.'--'.$row->release_time.'---'.$LOTTERY_RELEASE_DUR[$lotteryId];
 } else {
     //不在释放时间内取低概率
     $lotteryId = get_rand($LOTTERY_LOW_PROB);
     if ($lotteryId == 0) {
         $result['msg'] = '手气不太好';
     }
 }
 // $lotteryId=5测试抽奖;
 if (defined('ENV') && ENV != 'production') {
     // $lotteryId=rand(0,5);
 }
 //$lotteryId=5;
 if ($lotteryId != 0) {
     $prizeRst = getPrizeResult();
     while ($row = $prizeRst->fetch_object()) {
         //print_r($row);
         if ($row->id == $lotteryId) {
             break;
         }
     }
     if ($row->remain > 0) {
         ///if(updatePrize($row->id,$row->remain-1)){
         $_SESSION['prize'] = array("lotteryTime" => time(), "daily_limit" => $row->daily_limit, "pid" => $row->id, "describe" => $row->describe, 'total' => $row->total);
         //header('Location:http://127.0.0.1/nandu/src/php/main.php?op=saveform');
         $result['msg'] = '抽到了!';
         $result['prizeNum'] = $lotteryId;
         //saveLotteryInfo();
         //};
     } else {
Exemplo n.º 2
0
function saveHistory($form)
{
    //$form = array('name'=>'value');
    global $mysqli;
    $code = 0;
    //-1已经领过 0已经领完
    $id = 0;
    $ipaddress = getIP();
    $sessionid = session_id();
    //检查重复提交
    $sql = "select id from " . TABLE_PREFIX . "history  where ( name=? and phone=? ) or ( sessionid=? )";
    //准备一条语句放到服务器中
    //$sql="select id from ".TABLE_PREFIX."history  where pid=?";    //准备一条语句放到服务器中
    $stmt = $mysqli->prepare($sql);
    //放到数据库教程
    $stmt->bind_param("sss", $form['name'], $form['phone'], $sessionid);
    //给占位符传值,类型-变量(不能是值)
    //$stmt->bind_param("sss",$form['pid'],);
    $stmt->execute();
    $id = 0;
    $stmt->bind_result($id);
    while ($stmt->fetch()) {
        if (!empty($id)) {
            return -1;
        }
    }
    //检查是否超出当日最大抽奖数
    $sql = "select id from " . TABLE_PREFIX . "history  where pid='" . $form['pid'] . "'";
    $result = $mysqli->query($sql);
    if ($result->num_rows >= $form['total']) {
        return 0;
    }
    $toadyStartTime = strtotime(date('Y-m-d', time()));
    $todayEndTime = $toadyStartTime + 86400;
    $todayStartDate = date('Y-m-d', $toadyStartTime);
    $todayEndDate = date('Y-m-d', $todayEndTime);
    $result = getDailyHistory($form['pid'], $todayStartDate, $todayEndDate);
    if ($result->num_rows >= $form['daily_limit']) {
        return 0;
    }
    $r = getPrizeResult($form['pid']);
    //检查缓冲表内是否有剩余奖品
    if (checkPrizePool($form['pid'])) {
        //更新缓冲表
        updatePrizeMemory($form['pid']);
        //更新奖品表
        updatePrize($form['pid']);
        //插入奖品记录表
        $sql = "insert into " . TABLE_PREFIX . "history  (`name`,`phone`,`address`,`pid`,`describe`,`ip_address`,`sessionid`) values(?,?,?,?,?,?,?)";
        //准备一条语句放到服务器中
        $stmt = $mysqli->prepare($sql);
        //放到数据库教程
        $stmt->bind_param("sssssss", $form['name'], $form['phone'], $form['address'], $form['pid'], $form['describe'], $ipaddress, $sessionid);
        //给占位符传值,类型-变量(不能是值)
        $stmt->execute();
        //执行
        $id = $stmt->insert_id;
        $stmt->close();
        return 1;
    } else {
        return 0;
    }
    /*$stmt->bind_result($id);
      while($stmt->fetch())
      {
      	if(!empty($id)){
      		return false;
      	}
      }
      */
    //print_r($stmt);exit;
}