<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pay extends CI_Controller {

	function __construct(){
		parent::__construct();
        	$this->load->helper('url');
                $this->load->library('session'); //加载session
		$this->load->model('CsdjDB');
		$this->load->model('CsdjAdmin');
		$this->load->model('CsdjSkins');
                $this->db->cache_off();
	        $this->CsdjAdmin->Admin_Login();
	}

	public function index()
	{
 	    $kstime = $this->input->get_post('kstime');
 	    $jstime = $this->input->get_post('jstime');
 	    $dingdan = $this->input->get_post('dingdan');
 	    $user = $this->input->get_post('user');
 	    $pid = $this->input->get_post('pid');
 	    $page = $this->input->get('page');
            if(empty($page)) $page=1;

	    $sql_string = "SELECT * FROM ".CS_SqlPrefix."pay where 1=1";
            if($kstime){
	          $sql_string.=" and cs_addtime >= '".date('Y-m-d',strtotime($kstime)-86400)."'";
            }
            if($jstime){
	          $sql_string.=" and cs_addtime <= '".date('Y-m-d',strtotime($jstime)+86400)."'";
            }
            if($dingdan){
	          $sql_string.=" and cs_dingdan like '%".$dingdan."%'";
            }
            if($user){
	          $sql_string.=" and cs_user like '%".$user."%'";
            }
            if($pid==1){
	          $sql_string.=" and cs_pid=1";
            }
            if($pid==2){
	          $sql_string.=" and cs_pid=0";
            }
	    $sql_string.=" order by CS_ID desc";
	    $query = $this->db->query($sql_string); 
	    $total = $query->num_rows();

            $base_url = site_url('admin/pay/index/')."?kstime=".$kstime."&jstime=".$jstime."&dingdan=".$dingdan."&user=".$user."&pid=".$pid;
	    $per_page = 20; 
            $totalPages = ceil($total / $per_page); // 总页数
	    $data['nums'] = $total;
            if($total<$per_page){
               $per_page=$total;
            }
            $sql_string.=' limit '. $per_page*($page-1) .','. $per_page;
	    $query = $this->db->query($sql_string);

	    $data['pay'] = $query->result();
	    $data['pages'] = $this->CsdjAdmin->get_page($base_url,$totalPages,$page,10); //获取分页类

            $this->load->view('admin/pay_list',$data);
        }

	public function pldel()
	{
            $this->CsdjAdmin->Admin_Qx('45');
	    $ids=$this->input->post('CS_ID');
            if(empty($ids)) $this->CsdjAdmin->Admin_Url('<font color=red>参数错误，ID为空！</font>','javascript:history.back();');
            $id=implode(',', $ids);
            $this->db->query("delete from ".CS_SqlPrefix."pay where CS_ID in (".$id.")");
            $this->CsdjAdmin->Admin_Url('<font color=#0000ff>恭喜您，删除成功！</font>',$_SERVER['HTTP_REFERER'],'ok');
        }
}

