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

/**
* 邀请码兑换相关
*/
class Invitecode extends MY_Controller
{

	public $postdata = array('frombg' => 1, 'mod' => '', 'act' => '', '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->_url = ($this->env == 2) ? $this->config->item('localUrl') : $this->config->item('officialUrl');
	}


	public function index()
	{
		$data = array();

		//时间查询
		$dateArr = array();
		if( $stime = get_cookie('ic_start_time') ){
			$data['stime'] = $stime;
			$dateArr['stime'] = strtotime($stime.'1:0:0');
		}else{
			$dateArr['stime'] = strtotime('-3 days 1:0:0');//默认开始时间
			$data['stime'] = date('Y-m-d', $dateArr['stime']);
		}

		if( $etime = get_cookie('ic_end_time') ){
			$data['etime'] = $etime;
			$dateArr['etime'] = strtotime($etime.'23:59:59');
		}else{
			$dateArr['etime'] = strtotime('-1 days 23:59:59');//默认结束时间
			$data['etime'] = date('Y-m-d', $dateArr['etime']);
		}

		$postData = array_merge($dateArr, $this->postdata);
        $postData['mod'] = 'Invitecode';
        $postData['act'] = 'getlist';
        $this->env == 2 && $postData['demo'] = 1;
        $res = $this->curl->req($this->_url, $postData);
        $retData = json_decode($res, TRUE);
		$data['list'] = $retData;
		$this->load->view('invitecode/index', $data);
	}
}