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

/**
* tradeplus相关数据
*/
class Tradeplus extends MY_Controller
{

    protected $pageNum = 15;//分页
    protected $pageConfig = array(
        'first_tag_open' => '<li>',
        'first_tag_close' => '</li>',
        'last_tag_open' => '<li>',
        'last_tag_close' => '</li>',
        'next_tag_open' => '<li>',
        'next_tag_close' => '</li>',
        'prev_tag_open' => '<li>',
        'prev_tag_close' => '</li>',
        'cur_tag_open' => "<li class='active'><a hef='#'>",
        'cur_tag_close' => "</a></li>",
        'num_tag_open' => "<li>",
        'num_tag_close' => "</li>",
    );

	public function __construct()
	{
        parent::__construct();
		$this->load->helper('url');
		$this->load->helper('cookie');
        $this->load->library('pagination');
		$this->load->model('oo');
	}

    /**
     * tradeplus统计数据
     */
    public function index($limit = 0){
		$data = ['stime' => '', 'etime' => ''];
        $dateArr = array();
        if( $stime = get_cookie('remain_stime')){
            $stime = strtotime($stime);
            $stime = empty($stime) ? date('Ymd', strtotime('-7 days 0:0:1')): date('Ymd', $stime);
        }else{
            $stime = date('Ymd', strtotime('-7 days 0:0:1'));
        }
        $data['stime'] = date('Y-m-d', strtotime($stime));

        if( $etime = get_cookie('remain_etime')){
            $etime = strtotime($etime);
            $etime = empty($etime) ? date('Ymd', strtotime('-1 days 23:59:59')): date('Ymd', $etime);
        }else{
            $etime = date('Ymd', strtotime('-1 days 23:59:59'));
        }
        $data['etime'] = date('Y-m-d', strtotime($etime));
        //
        $retData = oo::commonOprModel('tradeplus')->getData($stime, $etime, $limit, $this->pageNum);

        //分页
        $pageConfig = $this->pageConfig;
        $pageConfig['base_url'] = base_url('#tradeplus/index');
        $pageConfig['total_rows'] = $retData['total'];
        $pageConfig['per_page'] = $this->pageNum;
        $this->pagination->initialize($pageConfig);
        $pageurl = $this->pagination->create_links();
        $data['pageurl'] = $pageurl;
        $data['page'] = $page;
        $data['list'] = $retData['list'];
        $data['total'] = $retData['total'];
        $data['groups'] = oo::commonOprModel('tradeplus')->getUserGroupNamesConfig();
        $this->load->view('tradeplus/index', $data);
    }
}
