Commit 66d66036 by doszhang

dos

parent 8e4e184b
......@@ -25,12 +25,169 @@ class IndexController extends Controller
// $this->request_auth($this->get_url());
// return;
// }
session_start();
$_SESSION['joinTime'] = time();
$this->display();
}
public function tryPrize()
{
$referer = $_SERVER['HTTP_REFERER'];
$refererInfo = parse_url( $referer );
if( $refererInfo['host'] != $_SERVER['HTTP_HOST'] )
{
header("HTTP/1.0 404 Not Found");
exit;
}
session_start();
if(!$_SESSION['joinTime'] || time() - $_SESSION['joinTime'] < 2)
{
header("HTTP/1.0 404 Not Found");
exit;
}
$user = $this->get_user_info_from_cookie();
if (!$user) {
$this->ajaxReturn(array(
'status' => 404,
'msg' => '用户信息错误',
'step' => 0
));
return;
}
// if($user['chance'] <= 0)
// {
// $this->ajaxReturn(array(
// 'status' => -1,
// 'msg' => '机会用光了',
// 'step' => 1
// ));
// return false;
// }
// M('user')->where(array(
// 'id' => $user['id']
// ))->setDec('chance');
$count = M('prize' . $_SESSION['src'])->where(array(
'user_id' => $user['id']
))->count();
if($count > 0)
{
$this->ajaxReturn(array(
'status' => 0,
'msg' => '很遗憾,没有中奖',
'step' => 5,
));
return false;
}
$prize = $this->get_random_prize($user);
if ($prize) {
$this->ajaxReturn(array(
'status' => 1,
'msg' => '恭喜您中奖了!',
'prize_type' => $prize['type'],
'step' => 4
));
}
else {
$this->ajaxReturn(array(
'status' => 0,
'msg' => '很遗憾,没有中奖',
'step' => 6,
));
}
}
private function get_random_prize($user)
{
session_start();
$v = rand(0, 1000000) / 1000000;
$today_ratio = 1;
if ($v > $today_ratio) {
return false;
}
$now = time();
$req_type = array();
$type_list = array(1,2,3);
foreach ($type_list as $type) {
$c = M('prize')->where(array(
'type' => $type,
'is_get' => 1,
))->count();
if ($type == 1) {
if ($c >= 25) {
continue;
}
}
else if ($type == 2) {
if ($c >= 500) {
continue;
}
}
else if ($type == 3) {
if ($c >= 1000) {
continue;
}
}
$req_type[] = $type;
}
if (empty($req_type)) {
return false;
}
$prize = M('prize')->where(array(
'is_get' => 0,
'user_id' => 0,
'type' => array('in', $req_type),
))->order('rand()')->limit(1)->find();
if (!$prize) {
return false;
}
$status = M('prize')->where(array(
'id' => $prize['id'],
'is_get' => 0,
'user_id' => 0,
))->save(array(
'is_get' => 1,
'user_id' => $user['id'],
'take_time' => time(),
'last_ip' => $this->getIP()
));
if($status === false || $status === 0)
{
return false;
}
else
{
return $prize;
}
}
public function cookie()
{
SignedCookie::set_cookie($this->cookie_uid_key, 'oVsrlt0zUWMLvMx2-KPGVmY2I-Xc', C('cookie_sign'), 86400 * 60);
}
public function addprize() {
for($i = 0;$i < 1000;$i++)
{
M('prize')->add(array(
'type' => 3,
'prize_name' => '1元全网手机话费'
));
if($i < 500) {
M('prize')->add(array(
'type' => 2,
'prize_name' => '2元全网手机话费'
));
} if($i < 25) {
M('prize')->add(array(
'type' => 3,
'prize_name' => '优酷VIP视频月卡'
));
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment