<?php
namespace app\console\controller;
use app\common\controller\Authentication;
use app\common\model\AccountModel;
use app\common\model\RoleModel;
use app\common\model\RoleListModel;
use \think\Db;


class Console extends Authentication{
    
    private static $M_account,$M_role,$M_rolelist;
    public function __construct(){
        parent::__construct();
    }
    public function index(){
        // 游戏总人数
        $query_count = "select count(1) count from jr_account";
        $result['count'] = Db::query($query_count)[0]['count'];

        // 过关总人数
        $query_pass = "select count(1) count from (select id from jr_account_role where lv = 10 GROUP BY account_id) a";
        $result['count_pass'] = Db::query($query_pass)[0]['count'];

        // 平均过关需要玩多少次
        $query_pass_count = "select a.account_id,count(1) count from jr_account_role a join jr_account_role_list b on a.id = b.account_role_id where a.lv = 10 GROUP BY a.account_id order by count(1) desc";
        $list = Db::query($query_pass_count);
        $sum = 0;
        foreach ($list as $item) {
            if($item['count']){
                $sum += $item['count'];
            }
        }
        $result['pass_count'] = intval($sum / count($list));

        // Leads列表
        $query_leads = "select nickname,mobile,lead_created from jr_account where mobile != '' order by id desc";
        $result['leads'] = Db::query($query_leads);

        // Leads完成数
        $query_leads_count = "select count(1) count from jr_account_role t where status = 'leads_success'";
        $result['leads_count'] = Db::query($query_leads_count)[0]['count'];

        // Share完成数
        $query_share_count = "select count(1) count from jr_account_role t where status = 'share_success'";
        $result['share_count'] = Db::query($query_share_count)[0]['count'];

        // return json($result);

        return view('index',['data'=> $result]);
    }

}
