예제 #1
0
 $gua = rand(0, 3);
 // Draw lottery. 抽奖放在这里
 $wls = new WechatLotteryService();
 // Today's drawing time. 第几次抽奖
 $today_time = $wls->save_onelot($openid);
 $rewardDao = new RewardDao();
 $reward_row = $rewardDao->getByOpenid($openid);
 if ($today_time == WechatLotteryService::OVER_LIMIT) {
     // Draw action over daily limit
     header("Location:result.php?price=-1&casa=" . $r . "&gua=" . $gua);
 } else {
     if ($reward_row) {
         // Already won, 中过奖了
         header("Location:result.php?price=0&casa=" . $r . "&gua=" . $gua);
     } else {
         $win = $wls->draw();
         // 中奖了
         if ($win) {
             // 中了几等奖
             $price_level = $wls->draw_price();
             // save in session
             $sc = new SessionController();
             $sc->addCode($openid);
             // save in database
             $wls->save_winner($openid, $price_level);
             // redirect
             header("Location:result.php?price=" . $price_level . "&casa=" . $r . "&gua=" . $gua);
         } else {
             header("Location:result.php?price=0&casa=" . $r . "&gua=" . $gua);
         }
     }