<?php
// +----------------------------------------------------------------------
// | 天方夜谭 [ 世界上最好用的QQ秒赞系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014~2019 http://www.eirds.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 天方夜谭 <17404785@qq.com>
// +----------------------------------------------------------------------

//页面标题
define('Title', '控制台');

//新用户抽奖
if (POST('action')=='luck'){
    header('Content-Type:application/json; charset=utf-8');
    if ($GLOBALS['users']['luck']=='1'){
        $arr = array('state'=>'no','msg'=>'对不起，您的机会已经用完！');
    }else{
        $prize_arr = object_array($TFYT_DB->get_results("select * from ".PREFIX."website_prize order by id desc"));
        foreach ($prize_arr as $key => $val) {
            $arr[$val['id']] = $val['luck'];
        }
        $rid = get_rand_luck($arr); //根据概率获取奖项id
        if ($TFYT_DB->query("update ".PREFIX."users_service set luck='1' where `only`='{$GLOBALS['users']['only']}'")){
            $luck = $prize_arr[$rid];
            if ($luck['mold']=='money'){
                $TFYT_DB->query("update ".PREFIX."users_service set money=money+'{$luck['num']}' where `only`='{$GLOBALS['users']['only']}'");
            }elseif ($luck['mold']=='q_quota'){
                $TFYT_DB->query("update ".PREFIX."users_service set q_quota=q_quota+'{$luck['num']}' where `only`='{$GLOBALS['users']['only']}'");
            }elseif ($luck['mold']=='p_quota'){
                $TFYT_DB->query("update ".PREFIX."users_service set p_quota=p_quota+'{$luck['num']}' where `only`='{$GLOBALS['users']['only']}'");
            }elseif ($luck['mold']=='u_quota'){
                $TFYT_DB->query("update ".PREFIX."users_service set u_quota=u_quota+'{$luck['num']}' where `only`='{$GLOBALS['users']['only']}'");
            }
            $arr = array('state'=>'ok','msg'=>'抽奖成功！','data'=>$luck);
        }else{
            $arr = array('state'=>'no','msg'=>'抽奖失败，请稍后再试！');
        }
    }
    exit(json_encode($arr));
}

//获取数据
$leader_list = $TFYT_DB->get_results("select * from ".PREFIX."website_leader order by id desc");

//获取登录记录
$users_lastlog = $TFYT_DB->get_results("select * from ".PREFIX."users_lastlog where uid='{$GLOBALS['users']['uid']}' order by lasttime desc limit 3");

//获取新消息
$player_list = $TFYT_DB->get_results("select * from ".PREFIX."player order by id desc limit 5");

//加载头部
Load_Template(Mains.'head.php');

//加载视图
Load_Template(Mains.'index.php');

//加载底部
Load_Template(Mains.'foot.php');