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

class Site_user_model extends CI_Model{

	public $table = 'user';
	public function __construct()
	{
		parent::__construct();
		$this->config->load('otherconf',TRUE);

	}

	#统计用户总数
	public function countuser()
	{
		//$this->db->where('end_time >', time());
		$this->db->where('status', 1);
		return $this->db->count_all_results($this->table);
	}

	public function listuser($fields,$limit,$offset)
	{
		$this->db->select($fields);
		$this->db->where('status', 1);
		$this->db->order_by('createtime', 'DESC');
		$query = $this->db->get($this->table,$limit,$offset);
		return $query->result_array();
	}

	public function listexuser($fields,$limit,$offset)
	{
		$this->db->select($fields);
		$this->db->where('status', 1);
		$this->db->order_by('createtime', 'DESC');
		$query = $this->db->get($this->table,$limit,$offset);
		$k=0;
		$data = array();
		$format_data = '';
        $status = $this->config->item('status','otherconf');
        $type = $this->config->item('type','otherconf');
        $sex = $this->config->item('sex','otherconf');
		while ($row = $query->unbuffered_row())
		{

		    $data[$k]['username'] = iconv('utf-8','gb2312//IGNORE',$row->username);
			$data[$k]['opencard_time'] = date('Y-m-d',$row->createtime);
			$data[$k]['realname'] = iconv('utf-8','gb2312//IGNORE',$row->realname);
			$data[$k]['tel'] = $row->tel;
			$data[$k]['sex'] = iconv('utf-8','gb2312//IGNORE',$sex[$row->sex]);
			$data[$k]['age'] = $row->age;
			$data[$k]['buys'] = $row->buys;
		    $data[$k]['status'] = iconv('utf-8','gb2312//IGNORE',$status[$row->status]);
            $data[$k]['start_time'] = date('Y-m-d',$row->start_time);
            $data[$k]['end_time'] = date('Y-m-d',$row->end_time);
            $data[$k]['type'] = iconv('utf-8','gb2312//IGNORE',$type[$row->type]);
            $format_data = $format_data.implode(",",$data[$k])."\n";
		}
		return $format_data;	
	}
}