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

class Welcome_test extends MY_Controller 
{
    
    private $uid_arr;
    
    /**
    * 解析函数
    */
    public function __construct()
    {
        parent::__construct();
        
        $this->config_cityflag = 'nj';
        $this->uid_arr = $this->user_arr;
        
        //套餐信息
        $this->load->model('package_model');
        $this->package_info = $this->package_model->find_by_id($this->uid_arr['package_id']);
        $this->load->model('statistics_model','stat');
        $this->load->model('welcome_model');
        $this->load->model('welcome_test_model');
    }
    
    
    /**
     *首页
     */
    public function index()
    {
        //第一次登陆显示提示 
        $show_message = $this->first_message_show();
        $uid = $this->uid_arr['uid'];
        $is_pay = $this->uid_arr['is_pay'];
        $package_id = $this->uid_arr['package_id'];

        //获取诚信logo状态
        $honesty_status = $this->welcome_test_model->get_honesty_status($uid);

        //应用       
        $app_custom = $this->welcome_model->get_app_custom($uid); 
        $app_arr = $this->my_unserialize($app_custom);
        $app_custom_arr = $this->config->item('app_custom_arr');
        $today	= date('Y-m-d',time());
        //应用处理（用户应用为空或者免费用户）
        $app_arr = $this->app_manage($app_arr,$app_custom_arr,$is_pay);
        
        //数据统计
        //套餐信息
        $package_info = $this->package_info;
        $info['package_info'] = $package_info;
        //当日
        $today_stat = $this->stat->overViewToday( $uid , $package_id );
        //急推房源统计
        $today_stat['jtLabelCount'] = isset($today_stat['jtLabelCount']) ? $today_stat['jtLabelCount'] : '';
        $today_stat['remainJtLable'] = isset($today_stat['remainJtLable']) ? $today_stat['remainJtLable'] : '';
        //房源剩余量
        $today_stat['house_remain'] = $this->remain_house_num($today_stat);//还可发布量
        //库存量，库存剩余
        $today_stat['package_stock'] = $package_info['package_stock_num'];//库存量
        $today_stat['used_stock'] = $this->used_stock($uid,$today_stat);//库存使用量
        $today_stat['remain_stock'] = $this->remain_house_stock($today_stat['package_stock'],$today_stat['used_stock']);//库存剩余
        //刷新未执行
        $reserveRefreshNum = $this->stat->getReserveRemainNum($uid);
        $today_stat['reserveRefreshNum'] = $this->reserve_refresh_num($today_stat['refreshNumber'],$today_stat['refreshCountToday'],$reserveRefreshNum);
        //刷新剩余
        $today_stat['remain_refresh'] = $this->remain_refresh($today_stat['refreshNumber'], $today_stat['refreshCountToday'], $reserveRefreshNum);
        $yestrday_stat = $this->yestrday_stat_info();
        $yestrday_stat['remain_refresh'] = $this->remian_refresh($package_info['package_refresh_num'],$yestrday_stat['house_refresh_y']);
        
        //成长体系信息
        $gbe = new GrowthBrokerExp(array('id'=>$uid,'groupid'=>$package_id));
        $gbc = new GrowthBrokerCredit(array('id'=>$uid,'groupid'=>$package_id));
        $allLevel = $this->allLevel();
        //等级
        $info['level'] = $gbe->getLevel();
        //等级数字
        $info['level_num'] = intval(substr($info['level'],2));
        //经验
        $info['exp'] = $gbe->getExp();
        //下个等级信息
        $info['nextLevel'] = $this->nextLevel($info['level_num'],$allLevel);
         //本等级信息
        $info['level_info'] = $this->brokerLevelInfo($info['level_num'],$allLevel);
        
        //升下个等级提示线
        $info['brokerLevelWidth'] = $this->next_Level_width($info['exp'], $info['level_info']['down_exp'], $info['nextLevel']['down_exp'], $info['level_info']['down_exp']);
        //房豆(房豆)
        $info['credit'] = $gbc->getValidCredit();
        //公告通知
        $system_notice = $this->system_notice($uid);
        
        $this->load->model('broker_model');
        $this->broker_model->set_uid($uid);      
        $info['company'] = $this->broker_model->get_broker_company();//经纪人门店信息
        $broker_detail = $this->broker_model->get_broker_detail();//经纪人详细信息
        
        if(isset($broker_detail['master']))
        {
            $info['accout_manager'] = $this->broker_model->get_account_manager($broker_detail['master']);//客户经理
        }
        $info['expiredate'] = $broker_detail['expiredate'] != '0000-00-00' ? date("Y-m-d", strtotime($broker_detail['expiredate'])) : '';
        $info['remain_days'] = $this->get_days( $today , $info['expiredate']);
        //帐号到期提醒设置cookies
        $account_expired_show = $this->account_expired();
        $this->load->model('payment_model');
        //帐号开通首次登录提醒
        $growth_broker_pay_message = $this->growth_broker_pay_account($uid,$package_id);
        //帐号快到期提醒扣除分值
        $accountFailureScore = $this->accountFailure($package_id);
		//是否提醒帐号已发虚假房源
        $is_warn = $this->is_warn($this->uid_arr['uid'],$this->uid_arr['is_warn']);
        //生日祝福
        //$is_birthday = $this->brithdayMessage();
        $data = array();
        //头部
        $data['page_title'] = '租售宝';
        $data['css'] = load_css('zsb/css/v1.0/index.css');
        $data['show_message'] = $show_message;
        $data['app_arr'] = $app_arr;
        $data['app_custom_arr'] = $app_custom_arr;
        $data['info'] = $info;
        $data['broker'] = $this->uid_arr;
        $data['today_stat'] = $today_stat;
        $data['yestrday_stat'] = $yestrday_stat;
        $data['system_notice'] = $system_notice;
        $data['payment_url'] = $this->payment_model->get_module_url('recharge');   
        $data['growth_broker_pay_message'] = $growth_broker_pay_message;
        $data['accountFailureScore'] = $accountFailureScore;
        $data['account_expired_show'] = $account_expired_show;
		$data['is_warn'] = $is_warn;
		// $data['is_birthday'] = $is_birthday;
	    $data['google_analytics'] = get_ga_js_code('/首页/');

        //引导
        $this->load->library('guide');
        $data['guide_show'] = $this->guide->check_guide($uid, 'zsb_welcome');
        
        //首页的广告位
        $this->load->library('Advertisement', '', 'advertisement');
        $data['ad1'] = $this->advertisement->get_ad_commons_html(2457);
		$data['ad2'] = $this->advertisement->get_ad_commons_html(2481);
           
        //诚信logo
        $data['honesty_status'] = $honesty_status;

        //加载模板
        $this->view('index', 'welcome_test', $data);
    }
    
    
    //应用管理
    public function desktop_app()
    {
        //不显示的应用
        $no_show_app = array();
        //无出售套餐
        if(isset($this->package_info['package_sell_purview']) 
                    && $this->package_info['package_sell_purview'] != 1){
            $no_show_app = array('sell_pulish','sell_manage');
        } 
        //无出租套餐
        if(isset($this->package_info['package_rent_purview']) 
                    && $this->package_info['package_rent_purview'] != 1){
            $no_show_app = array('rent_pulish','rent_manage');
        }
       
        $uid = $this->uid_arr['uid'];
        $is_pay = $this->uid_arr['is_pay'];    
        $data = array();
        $app_custom = $this->welcome_model->get_app_custom($uid);   
        $app_arr = $this->my_unserialize($app_custom);
      
        $app_custom_arr = $this->config->item('app_custom_arr');
        //应用处理（用户应用为空或者免费用户）
        $app_arr = $this->app_manage($app_arr,$app_custom_arr,$is_pay);
  
        $action = $this->input->post('action');
        if($action == 'save_app_custom'){
            $active_app = $this->input->post('active_app');
            if(count($active_app) > 12){                
                $this->jump(GB_WO_URL.'/welcome/desktop_app/', '您最多可以添加<b> 12 </b>个应用！');
	        return;
            }else{
                //保存自定义菜单命令
                if( $is_pay == 1 ){	//免费帐号屏蔽付费应用
                    $temp_arr = array();//过滤付费应用
                    if(is_array($active_app) && !empty($active_app)){
                        foreach ($active_app as $key =>$vlaue){
                            if($app_custom_arr[$vlaue]['auth'] == 'base'){
                                $temp_arr[$key] = $vlaue;
                            }
                        }
                    }
                    $active_app = $temp_arr;
                }
                $active_app_s	= $this->my_serialize($active_app);//序列化
                $this->welcome_model->update_app_custom($uid,$active_app_s); 
                $this->jump(GB_WO_URL, '常用功能设置成功！');
	        return;
            }
        }else{
            $growthExp = new GrowthExp();
            $brokerExp = $growthExp->findOneByBrokerId($uid);
           
            $brokerExp['exp'] = $brokerExp['exp'] == '' ? 0 :$brokerExp['exp'];
            //等级
            $growthLevel = new GrowthLevel();
            $brokerLevel = $growthLevel->findLevelNameByExp($brokerExp['exp']);
            $brokerLevelNum = intval(substr($brokerLevel,2));

            //经纪人操作等级最低权限
            $growthBidLowLevel = new GrowthBidLowLevel();
            //经纪人操作等级的权限
            $growthLevelWayPermission = new GrowthLevelWayPermission();
            //获取小区专家竞投最低等级
            $lowExpertLevelId = $growthBidLowLevel->findLevelByType(1);
           
            $lowExpertLevelId = 'LV2';//TEST
            $lowExpertLevelId = intval(substr($lowExpertLevelId['level'],2));
            // $lowExpertLevelId = $growthLevelWayPermission->findLowLevelBidBlockExpert();
            //获取房源竞投最低等级
            //$lowHouseLevelId = $growthLevelWayPermission->findLowLevelBidHouse();
            $lowHouseLevelId = $growthBidLowLevel->findLevelByType(2);
            $lowHouseLevelId = intval(substr($lowHouseLevelId['level'],2));
           
            $data['lowExpertLevelId'] = $lowExpertLevelId;
            $data['lowHouseLevelId'] = $lowHouseLevelId;
            $data['brokerLevelNum'] = $brokerLevelNum;
        }

        $data['page_title'] = '常用功能管理';
        $data['css'] = load_css('zsb/css/v1.0/style2.css'); //需要加载的css
    
        $data['is_pay'] = $is_pay;
        $data['app_custom_arr'] = $app_custom_arr;
        $data['app_arr'] = $app_arr;
        $data['no_show_app'] = $no_show_app;
        
        $this->view('welcome','desktop_app_custom',$data);
    }
    
    
    //第一次登录消息显示
    private function first_message_show()
    {
        $show_message = '';
        $login_frist = $this->input->cookie('login_frist', TRUE);
        if($login_frist!=1){
            
            $show_message = 1;
            $cookie = array(
                   'name'   => 'login_frist',
                   'value'  => 1,
                   'expire' => 3600,    // 设置一个小时的有效期            
            );          
            $this->input->set_cookie($cookie);
        }
        return $show_message; 
    }
    
    
     //到期提醒缓存
    private function account_expired()
    {
        $account_expired_show = '';
        $account_expired = $this->input->cookie('account_expired', TRUE);
        if($account_expired!=1){
            
            $account_expired_show = 1;
            $cookie = array(
                   'name'   => 'account_expired',
                   'value'  => 1,
                   'expire' => 3600,    // 设置一个小时的有效期            
            );          
            $this->input->set_cookie($cookie);
        }
        return $account_expired_show; 
    }
    
    
    //帐号首次登录提醒赠送成长值
    private function growth_broker_pay_account($brokerId,$packageId)
    {
        //判断帐号是否第一次开通，如果是则弹窗提示
        $growthBrokerPayAccount = new GrowthBrokerPayAccount();
        $growthExpWayPackage = new GrowthExpWayPackage();
        $brokerPayAccount = $growthBrokerPayAccount->findByBorkerId($brokerId);
        $isKnow = false;
        $openPayExpScore = "";
        if (isset($brokerPayAccount['is_know']) && $brokerPayAccount['is_know'] == 0) {
            $isKnow = true;
            $openPayExpScore = $growthExpWayPackage->findScoreByWayAliasAndPackageId('openPayPackage', $packageId);
            $growthBrokerPayAccount->setIsKnowToOne($brokerId);
        }
        $arr = array('isKnow'=>$isKnow,'openPayExpScore'=>$openPayExpScore);
        return $arr;
    }
    
    
    //反序列号
   private function my_unserialize($data_info)
   {
      $arr = !empty($data_info) ? unserialize($data_info) : '';
      return $arr;
   }
   
   
   //序列化
   private function my_serialize($active_app)
   {
      return is_array($active_app) ? serialize( $active_app ) : '';
   }
   
   
   //应用处理
   private function app_manage($app_arr,$app_custom_arr,$is_pay)
   {
       //不显示的套餐
       $no_show_app = array();
       //无出售套餐
        if(isset($this->package_info['package_sell_purview']) 
                    && $this->package_info['package_sell_purview'] != 1){
            $no_show_app = array('sell_pulish','sell_manage');
        }
        //无出租套餐
        if(isset($this->package_info['package_rent_purview']) 
                    && $this->package_info['package_rent_purview'] != 1){
            $no_show_app = array('rent_pulish','rent_manage');
        }
    
        if(!is_array($app_arr)){
            //如果为空，则默认显示基础的应用，付费应用只有付费账号才能选择
	        if(is_array($app_custom_arr) && !empty($app_custom_arr) ){
                foreach($app_custom_arr as $key=>$value){
                    if($value['auth'] == 'base'&& !in_array($key, $no_show_app)){
                        $app_arr[] = $key;
		            }                 
		        }
	        }else{
                $app_arr = array();
	        }
        }else{
            if( $is_pay == 1 ){	//免费帐号屏蔽付费应用
                $temp_arr = array();//过滤付费应用
                if(is_array($app_arr) && !empty($app_arr)){
                    foreach ($app_arr as $key =>$vlaue){
                        if($app_custom_arr[$vlaue]['auth'] == 'base' && !in_array($vlaue, $no_show_app)){
                            $temp_arr[$key] = $vlaue;
			            }
		            }
		        }
		        $app_arr = $temp_arr;
	        }
        }
       
        return $app_arr;
    }
   
    
    /**
     * 返回下一个等级
     * @param type $level
     * @param type $allLevel
     * @return boolean
     */
    private function nextLevel($level,$allLevel) {
        if($allLevel) {
            foreach ($allLevel as $key => $value) {
                if($value['level_id']==$level+1) {
                    return $value;
                }  else {
                    continue;
                }
            }
            return FALSE;
        }
    }
    
    
    /**
     * 当然经纪人等级信息
     * @param type $level
     * @param type $allLevel
     * @return boolean
     */
    private function brokerLevelInfo($level,$allLevel) {
        if($allLevel) {
            foreach ($allLevel as $key => $value) {
                if($value['level_id']==$level) {
                    return $value;
                }  else {
                    continue;
                }
            }
            return FALSE;
        }
    }
    
    
    /**
     * 返回全部等级数组
     * @return type
     */
    private function allLevel() {
        $key = $this->config_cityflag."_growth_level_data";
        $allLevel = $this->mc->get($key);
        if($allLevel === false) {
            $growthLevel = new GrowthLevel();
            $allLevel = $growthLevel->findAllLevelData();
            $this->mc->set($key,$allLevel,600);	
        }
        return $allLevel;
    }
    
    
    //获取经纪人帐号到期后每天倒扣的成长值
    private function accountFailure($package_id){
        $key = $this->config_cityflag . '_exp_way_alias_package_accountFailure_' .$package_id;
        $growthExpWayPackage = new GrowthExpWayPackage();
        $accountFailureScore = $this->mc->get($key);
        if ($accountFailureScore === false) {
            $accountFailureScore = $growthExpWayPackage->findScoreByWayAliasAndPackageId('accountFailure', $package_id);
            $this->mc->set($key,$accountFailureScore,6000);
        }
        return $accountFailureScore;
    }
    
    //生日弹窗
    private function brithdayMessage(){        
        $this->load->model('broker_model');
        $is_brithday = $this->broker_model->is_brithday();       
        $show_birthday = FALSE;
        if($is_brithday){
                 $show_birthday = TRUE;
        }
        return $show_birthday;
    }
    
    
    //系统公告通知
    private function system_notice($uid)
    {   
        $message_info = array();
        
        if( $uid > 0)
        {
            $tbl = 'agent_announceitem';
            $this->load->model('message_model');
            $this->message_model->set_tbl($tbl);
            $join_arr = array('agent_announce'=>'agent_announceitem.announceid=agent_announce.id');
            $this->message_model->set_join_table($join_arr,'left');
            $cond_where ="agent_announceitem.uid = ".$this->uid_arr['uid']." and agent_announce.issystem = 0";
            $message_info = $this->message_model->find_all_by($cond_where,0,5); 
        }
        
        return $message_info;
    }
    
    
    //升级下个等级提示性
    private function next_Level_width($brokerExp,$brokerLevelDownExp,$nextBrokerLeveldownExp,$brokerLevelDownExp)
    {
        return ($nextBrokerLeveldownExp-$brokerLevelDownExp) > 0 ? intval(($brokerExp-$brokerLevelDownExp)/($nextBrokerLeveldownExp-$brokerLevelDownExp)*100) : 0;
    }
    
    
    //房源剩余量
    private function remain_house_num($today_stat)
    {
        $house_remain = intval($this->uid_arr['postlimit'] - intval($today_stat['sellCount'] + $today_stat['rentCount']));
        $house_remain = $house_remain < 0 ? 0 : $house_remain;
        return $house_remain;
    }
    
    
    //库存已使用
    private function used_stock($uid,$today_stat)
    {
        $sell_num_invalid = $this->stat->sellNumInvalid($uid);//库存写个方法
        $rent_num_invalid = $this->stat->rentNumInvalid($uid);
        $used_stock =  intval($today_stat['sellCount'] + $today_stat['rentCount']+$sell_num_invalid+$rent_num_invalid);
        return $used_stock;
    }
    
    
    //剩余刷新量
    private function remian_refresh($package_refresh_num,$house_refresh_y)
    {
        $remian_refresh = intval($package_refresh_num - $house_refresh_y);
        $remian_refresh = $remian_refresh >0 ? $remian_refresh : 0;
        return $remian_refresh;
    }


    //剩余库存量
    private function remain_house_stock($package_stock,$used_stock)
    {
        $remain_stock = intval($package_stock - $used_stock);
        $remain_stock = $remain_stock > 0 ? $remain_stock : 0;
        
        return $remain_stock;
    }
    
     /**
     * reserve_refresh_num
     * 预约未刷新
     * @param int $refresh_limit 帐号刷新总数
     * @param int $refreshnum 已经刷新数
     * @param int $reserveRefreshNum 预约刷新数
     * @return int
     */
    private function reserve_refresh_num($refresh_limit,$refreshnum,$reserveRefreshNum)
   {        
        //此处逻辑是为了让预约未执行与已执行之和等于刷新总量
        $need2reserveRefreshNum = (int)$refresh_limit - (int)$refreshnum;
        $reserveRefreshNum = $reserveRefreshNum >= $need2reserveRefreshNum ? $need2reserveRefreshNum : $reserveRefreshNum;
        
        return $reserveRefreshNum;
    }
    
    
    /**
     * remain_refresh
     * 剩余刷新量
     * @param int $refresh_limit 帐号刷新总数
     * @param int $refreshnum 已经刷新数
     * @param int $reserveRefreshNum 预约刷新数
     * @return int
     */
    private function remain_refresh($refresh_limit,$refreshnum,$reserveRefreshNum)
    {        
        //今日还可刷新
        $remain_refresh = (int)$refresh_limit - (int)$refreshnum - $reserveRefreshNum;
        $remain_refresh = $remain_refresh > 0 ? $remain_refresh : 0;
        return $remain_refresh;
    }
    
    //昨天套餐使用情况记录
    private function yestrday_stat_info()
    {
        $uid = $this->uid_arr['uid'];
        //昨天
        $yestrday = date('Y-m-d',strtotime('-1day'));
        $key = $this->config_cityflag."_".$yestrday."yestrday_stat_by_".$uid;
        //$this->mc->delete($key);
        $yeseterday_info = $this->mc->get($key);
        if($yeseterday_info===false){
            $yestrday_stat = $this->stat->historyDay($uid,$yestrday);

            //昨日激活房源
            $yeseterday_info['postlimit_y']	= isset($yestrday_stat['postlimit']) ?  intval($yestrday_stat['postlimit']) : 0;	//昨日端口限制
            $yeseterday_info['house_num_y'] = isset($yestrday_stat['house_num']) ? intval($yestrday_stat['house_num']) : 0;	//昨日有效房源量
            $yeseterday_info['sell_num_y'] = isset($yestrday_stat['sell_house_num']) ? intval($yestrday_stat['sell_house_num']) : 0;//昨日出售房源量
            $yeseterday_info['rent_num_y'] = isset($yestrday_stat['rent_house_num']) ? intval($yestrday_stat['rent_house_num']) : 0;		//昨日出租房源量
            $yeseterday_info['remain_num_y'] = $yeseterday_info['postlimit_y'] - $yeseterday_info['house_num_y'];			//昨日端口剩余数量
          
            //激活多图出租
            $yeseterday_info['rent_star_num'] = isset($yestrday_stat['rent_star_num']) ? intval($yestrday_stat['rent_star_num']) : 0;

            //激活多图出售
            $yeseterday_info['sell_star_num'] = isset($yestrday_stat['sell_star_num']) ? intval($yestrday_stat['sell_star_num']) :0;

            //新增有效
            $yeseterday_info['sell_add'] = isset($yestrday_stat['sell_add']) ? intval($yestrday_stat['sell_add']) : 0;
            $yeseterday_info['rent_add'] = isset($yestrday_stat['rent_add']) ? intval($yestrday_stat['rent_add']) : 0;
            $yeseterday_info['house_add_y']	= intval( $yeseterday_info['sell_add'] + $yeseterday_info['rent_add'] );
            //新增失效
            $yeseterday_info['sell_add_valid'] = isset($yestrday_stat['sell_add_valid']) ? intval($yestrday_stat['sell_add_valid']) : 0;
            $yeseterday_info['rent_add_valid'] = isset($yestrday_stat['rent_add_valid'] ) ? intval($yestrday_stat['rent_add_valid'] ) : 0;
            $yeseterday_info['house_add_y_valid']	= intval( $yeseterday_info['sell_add_valid'] + $yeseterday_info['rent_add_valid'] );
            //昨日刷新
            $yeseterday_info['house_refresh_y'] = isset($yestrday_stat['refresh']) ? intval( $yestrday_stat['refresh']) : 0;
            //昨日点击量
            $yestrday_stat['click_num'] = isset($yestrday_stat['click_num']) ? intval($yestrday_stat['click_num']) : 0;
            $yeseterday_info['sell_click_y'] = isset($yestrday_stat['sell_click']) ? intval( $yestrday_stat['sell_click']) : 0;
            $yeseterday_info['rent_click_y'] =  intval( $yestrday_stat['click_num'] - $yeseterday_info['sell_click_y'] );

            //昨日急推标签
            $yeseterday_info['package_tag_num_y'] = isset($yestrday_stat['package_tag_num']) ? intval($yestrday_stat['package_tag_num']) : 0;//昨日套餐标签
            $yeseterday_info['tag_number_y'] = isset($yestrday_stat['is_tag_num']) ? intval( $yestrday_stat['is_tag_num']) : 0;	//已使用
            $yeseterday_info['tag_number_remain_y']	= $yeseterday_info['package_tag_num_y'] - $yeseterday_info['tag_number_y'];//昨日剩余套餐数量
            $this->mc->set($key,$yeseterday_info,600);
        }
       
        return $yeseterday_info;
    }
    
    //两日期差
    private function get_days($date1, $date2)
    {
        $d1 = strtotime($date1);
        $d2 = strtotime($date2);
        $days = round(($d2 - $d1) / 3600 / 24);
        return $days;
    }

	//是否提醒虚假房源
	public function is_warn($uid,$is_warn){  
	    //查看是否超过2次
        //$this->load->model('complain_model');
		//$num = $this->complain_model->getBrokerComplainNum($uid);
		//$return = ($is_warn == 1 && $num >= 2) ? TRUE : FALSE;
		$return = $is_warn == 1  ? TRUE : FALSE;
		return $return;
	}
    


    //设置打印SQL的COOKIE
    public function debug()
    {
        $cookie = array(
               'name'   => 'admin_debug',
               'value'  => 1,
               'expire' => 86400,    // 设置一天的有效期            
        );          
        $this->input->set_cookie($cookie);

        $this->jump(GB_WO_URL, '已获得SQL调试打印权限！');
    }

	
	public function del_old_message($page = 1)
	{
		//查询14年之前的数据删除
		$for_num = 1107498;
		$this->load->model('message_model');
		$limit = 80;
		$start = ($page-1)* $limit;
		$cond_where = "creattime <= 1402502400";
		$this->message_model->set_tbl('agent_announce');
		$this->message_model->set_select_fields(array('id'));
		$annouce_arr = $this->message_model->get_annouce_list_by_cond($cond_where,$start,$limit);

		$annouce_num = count($annouce_arr);
		
		
		if( $annouce_num > 0)
		{	
			$arr_id = array();

			for($i = 0 ; $i < $annouce_num ; $i ++)
			{
				$arr_id[$i] = $annouce_arr[$i]['id'];
			}
			
			$affect_num = 0;
			if(!empty($arr_id))
			{
				$del_where = '';
				$id_field = 'announceid';
				$this->message_model->set_tbl('agent_announceitem');
				$affect_num = $this->message_model->delete_message($del_where,$id_field,$arr_id);
			}
			
			echo '影响行数'.$affect_num;
			if( $page % 10 == 0)
			{
				sleep(1);
			}

			$page ++;
            echo '<script type="text/javascript">location.href="http://nj.zsb.house365.com/welcome_test/del_old_message/'.$page.'";</script>';
		}
		else
		{
			echo 'is_over';
		}

		exit;
	}

	public function del_old_annouce_message($page = 1)
	{	

		//查询14年之前的数据删除
		$start_time = 1210931327;
		$creattime = $start_time + 86400 * ($page-1);
		
		if($creattime >= 1465660800)
		{
			echo 'over';
			exit;
		}
		
		$this->load->model('message_model');
		$del_where = "creattime <= '".$creattime."'";
		//$this->message_model->set_tbl('agent_announceitem');
		$affect_num = $this->message_model->delete_message_annouce($del_where);
		
		echo '影响行数'.$affect_num;
		//exit;
		if( $page % 10 == 0)
		{
			sleep(1);
		}
		exit;
		$page ++;
		echo '<script type="text/javascript">location.href="http://nj.zsb.house365.com/welcome_test/del_old_annouce_message/'.$page.'";</script>';
		exit;
	}


	function get_mem_test($page = 1)
	{
		$arr = array();
		
		if($page >= 100)
		{
			echo 'over';
			exit;
		}
		$date = $this->mc->get('fdsfdsddd');
		
		echo '数据开始';
		var_dump($date);
		echo '数据结束';
		
		$page ++;
		echo '<script type="text/javascript">location.href="http://nj.zsb.house365.com/welcome_test/get_mem_test/'.$page.'";</script>';
		exit;
	}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
