<?php
if ( ! defined('CSCMSPATH')) exit('No direct script access allowed');

class Sfq_Qiandao_module extends CI_Module {

	function __construct(){
		    parent::__construct();
        	$this->load->helper('url');
	        $this->load->database();
            $this->load->library('session');
	        $this->load->model('CsdjDB'); 
            $this->load->model('CsdjSkins'); 
			require_once PLUGINDIR.'sfq/conxiu.php'; 
	        $dir = $this->uri->segment(2);
            $sql="SELECT CS_SID FROM ".CS_SqlPrefix."plugins where cs_dir='".$dir."'";
	        $row=$this->CsdjDB->get_all($sql);
	        if($row){
                      if($row[0]->CS_SID==1){
                             $this->CsdjAdmin->Admin_Url('<font color=red>未开启</font>',"javascript:history.back();");
                      }
            }else{
                      $this->CsdjAdmin->Admin_Url('<font color=red>未安装</font>',"javascript:history.back();");
            }
	}

	public function index()
	{
	        $content = $this->input->post('qdao', TRUE);
			$id = $this->session->userdata('cs_id');
			if($content==''){
			echo'心情不能为空';
			}
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Vip,CS_Hits,CS_Qdtian,CS_Qdsjian,CS_Leiji FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($this->datetime($row->CS_Qdsjian)>86400){
			if($row->CS_Vip>0){
			$updata['CS_Cion']= $row->CS_Cion+jinbi+1;
			}else{
			$updata['CS_Cion']= $row->CS_Cion+jinbi;
			}
			$updata['CS_Qdsjian']= date('Y-m-d');
			if($row->CS_Leiji+1==31){
			$updata['CS_Leiji']= 1;
			$updata['CS_Qda']= 0;
			$updata['CS_Qdb']= 0;
			$updata['CS_Qdc']= 0;
			$updata['CS_Qdd']= 0;
			}else{
			$updata['CS_Leiji']= $row->CS_Leiji+1;
			}
			$updata['CS_Qdtian']= $row->CS_Qdtian+1;
                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);

				
			$upqd['CS_Name']= $this->session->userdata('cs_name');
			$upqd['CS_Content']= $content;
			if($row->CS_Vip>0){
			$upqd['CS_Cion']= jinbi+1;
			}else{
			$upqd['CS_Cion']= jinbi;
			}	
			$upqd['CS_Qdtime']= date('Y-m-d H:i:s');
			$upqd['CS_Y']= date('Y');
			$upqd['CS_M']= date('m');
			$upqd['CS_D']= date('d');
			$this->CsdjDB->get_insert('qd',$upqd);
			
				die("<script language='javascript'>alert('签到成功');window.parent.location='".site_url('m/sfq')."';</script>");
            }else{
			die("<script language='javascript'>alert('已签到');window.parent.location='".site_url('m/sfq')."';</script>");
			}
			}else{
			die("<script language='javascript'>alert('请先登录');window.parent.location='".site_url('user/login')."';</script>");
			}
			}
			
			
				public function qian()
	{
	        $content = $this->input->post('qdao', TRUE);
			$id = $this->session->userdata('cs_id');
			if($content==''){
			echo'心情不能为空';
			}
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Vip,CS_Hits,CS_Qdtian,CS_Qdsjian,CS_Leiji FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($this->datetime($row->CS_Qdsjian)>86400){
			if($row->CS_Vip>0){
			$updata['CS_Cion']= $row->CS_Cion+jinbi+1;
			}else{
			$updata['CS_Cion']= $row->CS_Cion+jinbi;
			}
			$updata['CS_Qdsjian']= date('Y-m-d');
			if($row->CS_Leiji+1==31){
			$updata['CS_Leiji']= 1;
			$updata['CS_Qda']= 0;
			$updata['CS_Qdb']= 0;
			$updata['CS_Qdc']= 0;
			$updata['CS_Qdd']= 0;
			}else{
			$updata['CS_Leiji']= $row->CS_Leiji+1;
			}
			$updata['CS_Qdtian']= $row->CS_Qdtian+1;
                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);

				
			$upqd['CS_Name']= $this->session->userdata('cs_name');
			$upqd['CS_Content']= $content;
			if($row->CS_Vip>0){
			$upqd['CS_Cion']= jinbi+1;
			}else{
			$upqd['CS_Cion']= jinbi;
			}	
			$upqd['CS_Qdtime']= date('Y-m-d H:i:s');
						$upqd['CS_Y']= date('Y');
			$upqd['CS_M']= date('m');
			$upqd['CS_D']= date('d');
			$this->CsdjDB->get_insert('qd',$upqd);
			
				die("<script language='javascript'>alert('签到成功');window.parent.location='".site_url('user/edit/qian')."';</script>");
            }else{
			die("<script language='javascript'>alert('已签到');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			}else{
			die("<script language='javascript'>alert('请先登录');window.parent.location='".site_url('user/login')."';</script>");
			}
			}
			//前台JS签到调用数据
				public function jsqian()
	{
			$id = $this->session->userdata('cs_id');
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Vip,CS_Hits,CS_Qdtian,CS_Qdsjian,CS_Leiji FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($this->datetime($row->CS_Qdsjian)>86400){
			if($row->CS_Vip>0){
			$updata['CS_Cion']= $row->CS_Cion+jinbi+1;
			}else{
			$updata['CS_Cion']= $row->CS_Cion+jinbi;
			}
			$updata['CS_Qdsjian']= date('Y-m-d');
			if($row->CS_Leiji+1==31){
			$updata['CS_Leiji']= 1;
			$updata['CS_Qda']= 0;
			$updata['CS_Qdb']= 0;
			$updata['CS_Qdc']= 0;
			$updata['CS_Qdd']= 0;
			}else{
			$updata['CS_Leiji']= $row->CS_Leiji+1;
			}
			$updata['CS_Qdtian']= $row->CS_Qdtian+1;
                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);

				
			$upqd['CS_Name']= $this->session->userdata('cs_name');
			$upqd['CS_Content']= $content;
			if($row->CS_Vip>0){
			$upqd['CS_Cion']= jinbi+1;
			}else{
			$upqd['CS_Cion']= jinbi;
			}	
			$upqd['CS_Qdtime']= date('Y-m-d H:i:s');
						$upqd['CS_Y']= date('Y');
			$upqd['CS_M']= date('m');
			$upqd['CS_D']= date('d');
			$this->CsdjDB->get_insert('qd',$upqd);
			exit('10004');//签到成功
            }else{
			exit('10005');//已经签到
			}
			}else{
			exit('10003');//请去登陆
			}
			}
			
			
			//前台JS调用数据结束
            function datetime($TimeTime){
    		$limit=time()-strtotime($TimeTime);
  		    return $limit;
	        }
			
			
				public function qda()
	{
	       
			$id = $this->session->userdata('cs_id');
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Hits,CS_Qda,CS_Qdb,CS_Qdc,CS_Qdd,CS_Qde,CS_Qdf,CS_Leiji,CS_Qdsjian,CS_Qdtian FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($row->CS_Leiji<5){
			die("<script language='javascript'>alert('累计天数不够');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Qda==5){
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Leiji>=5&&$row->CS_Qda!=5){
			$updata['CS_Cion']= $row->CS_Cion+wjinbi;
			
			$updata['CS_Qda']= 5;
                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);


			
				die("<script language='javascript'>alert('领取成功');window.parent.location='".site_url('user/edit/qian')."';</script>");
            }else{
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			}else{
			die("<script language='javascript'>alert('请先登录');window.parent.location='".site_url('user/login')."';</script>");
			}
			}
			
			
			public function qdb()
	{
	       
			$id = $this->session->userdata('cs_id');
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Hits,CS_Qda,CS_Qdb,CS_Qdc,CS_Qdd,CS_Qde,CS_Qdf,CS_Leiji,CS_Qdsjian,CS_Qdtian FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($row->CS_Leiji<7){
			die("<script language='javascript'>alert('累计天数不够');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Qdb==7){
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Leiji>=7&&$row->CS_Qdb!=7){
			$updata['CS_Cion']= $row->CS_Cion+qjinbi;
			
			$updata['CS_Qdb']= 7;
                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);

			
				die("<script language='javascript'>alert('领取成功');window.parent.location='".site_url('user/edit/qian')."';</script>");
            }else{
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			}else{
			die("<script language='javascript'>alert('请先登录');window.parent.location='".site_url('user/login')."';</script>");
			}
			}
			
			
			public function qdc()
	{
	       
			$id = $this->session->userdata('cs_id');
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Hits,CS_Qda,CS_Qdb,CS_Qdc,CS_Qdd,CS_Qde,CS_Qdf,CS_Leiji,CS_Qdsjian,CS_Qdtian,CS_Vip,CS_EndTime FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($row->CS_Leiji<15){
			die("<script language='javascript'>alert('累计天数不够');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Qdc==15){
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Leiji>=15&&$row->CS_Qdc!=15){
			if($row->CS_Vip==0){
			$t = time();
			$updata['CS_Vip']= vip;
			}else{ 
			$t = strtotime(''.$row->CS_EndTime.''); 
			} 
			$t = strtotime("+".swtian." days", $t);   
			$time= date("Y-m-d", $t);
			$updata['CS_Cion']= $row->CS_Cion+swjinbi;
			$updata['CS_EndTime']=$time;
			$updata['CS_Qdc']= 15;

                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);


			
				die("<script language='javascript'>alert('领取成功');window.parent.location='".site_url('user/edit/qian')."';</script>");
            }else{
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			}else{
			die("<script language='javascript'>alert('请先登录');window.parent.location='".site_url('user/login')."';</script>");
			}
			}
			public function qdd()
	{
	       
			$id = $this->session->userdata('cs_id');
			$row=$this->db->query("SELECT CS_Logo,CS_Qianm,CS_Nichen,CS_Name,CS_Cion,CS_Hits,CS_Qda,CS_Qdb,CS_Qdc,CS_Qdd,CS_Qde,CS_Qdf,CS_Leiji,CS_Qdsjian,CS_Qdtian,CS_Vip,CS_EndTime FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
			if($id!=''){
			if($row->CS_Leiji<30){
			die("<script language='javascript'>alert('累计天数不够');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Qdd==30){
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			if($row->CS_Leiji>=30&&$row->CS_Qdd!=30){
			if($row->CS_Vip==0){
			$t = time();
			$updata['CS_Vip']= vip;
			}else{ 
			$t = strtotime(''.$row->CS_EndTime.''); 
			} 
			$t = strtotime("+".sstian." days", $t);   
			$time= date("Y-m-d", $t);
			$updata['CS_Cion']= $row->CS_Cion+ssjinbi;
			$updata['CS_EndTime']=$time;
			$updata['CS_Qdd']= 30;
                $this->CsdjDB->get_update ('user',$this->session->userdata('cs_id'),$updata);


			
				die("<script language='javascript'>alert('领取成功');window.parent.location='".site_url('user/edit/qian')."';</script>");
            }else{
			die("<script language='javascript'>alert('已领取过了');window.parent.location='".site_url('user/edit/qian')."';</script>");
			}
			}else{
			die("<script language='javascript'>alert('请先登录');window.parent.location='".site_url('user/login')."';</script>");
			}
			}
			//jieshu
            }
