<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
* 用户相关
*/
class Rank extends MY_Controller
{

    public $postData = array('frombg' => 1, 'lid' => 1, 'sid' => 1);

	public function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->helper('cookie');
		$this->load->library('curl');
		$this->env = get_cookie($this->_wenenv);
		$this->load->model('oo');
	}

	public function index($sid = 999)
	{
        $data = oo::commonOprModel('rank')->index('money', $sid);
        $uid = '';
        $money = '';
        foreach ($data['data'] as $row){
        	if(in_array($row['uid'],$data['pay_list'])){
        		$row['uid'] = $row['uid']."(*)";
        	}
            $uid .= $row['uid'].'","';
            $money .= $row['money'].',';
        }
        $out['money']=[
            'uid'=>'"'.trim($uid,',').'"',
            'money'=>trim($money,','),
        ];
        //星星排行
        $data = oo::commonOprModel('rank')->star();
        $star = '';
        $uid = '';
        foreach ($data['data'] as $row){
            if(in_array($row['uid'],$data['pay_list'])){
        		$row['uid'] = $row['uid']."(*)";
        	}
            $uid .= $row['uid'].'","';
            $star .= $row['star'].',';
        }
        $out['star'] = [
            'uid'=>'"'.trim($uid,',').'"',
            'star'=>trim($star,','),
        ];
        //等级排行
        $data = oo::commonOprModel('rank')->level();
        $level = '';
        $uid = '';
        foreach ($data['data'] as $row){
            if(in_array($row['uid'],$data['pay_list'])){
        		$row['uid'] = $row['uid']."(*)";
        	}
            $uid .= $row['uid'].'","';
            $level .= $row['level'].',';
        }
        $out['level'] = [
            'uid'=>'"'.trim($uid,',').'"',
            'level'=>trim($level,','),
        ];
        
        //体力排行
        $data = oo::commonOprModel('rank')->spins();
        $spins = '';
        $uid = '';
        foreach ($data['data'] as $row){
            if(in_array($row['uid'],$data['pay_list'])){
        		$row['uid'] = $row['uid']."(*)";
        	}
            $uid .= $row['uid'].'","';
            $spins .= $row['spins'].',';
        }
        $out['spins'] = [
            'uid'=>'"'.trim($uid,',').'"',
            'spins'=>trim($spins,','),
        ];

        //钻石排行
        $data = oo::commonOprModel('rank')->diamond();
        $diamond = '';
        $uid = '';
        foreach ($data['data'] as $row){
            if(in_array($row['uid'],$data['pay_list'])){
        		$row['uid'] = $row['uid']."(*)";
        	}
            $uid .= $row['uid'].'","';
            $diamond .= $row['diamond'].',';
        }
        $out['diamond'] = [
            'uid'=>'"'.trim($uid,',').'"',
            'diamond'=>trim($diamond,','),
        ];
        
        $out['sid'] = $sid;
        
		$this->load->view('rank/index',$out);
	}

	public function day($day = ''){
	    if($day == ''){
            $day = date('Ymd');
        }
        $data = oo::commonOprModel('rank')->day($day);
        $keys = oo::commonOprModel('statistics')->getResources();
        foreach($keys as $k => $v){
        	foreach($data[$v] as $data_k => $data_v){
        		if(in_array($data_k,$data[$v."Vip"])){
        			$data[$v][$data_k."(*)"] = $data_v;
        			unset($data[$v][$data_k]);
        		}
        	}
        	arsort($data[$v]);
        }
        $data['day'] = $day;
        $this->load->view('rank/day',$data);
    }

}
