<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of market_bid_house_manage
 *
 * @author Administrator
 */
class market_bid_house_manage extends MY_Controller {

    private $uid;
    private $info;
    
    private $house;
    
    private $brokerLevel;
    
    private $bidBlockWords;
    
    private $arrBlockId;
    
    private $arrHotSearchWords;

	private $arrDistrictSearchWords;

	private $arrStreetSearchWords;
    
    private $bidBehavior = array(
		1 => '成功', 2 => '失败', 3 => '暂未投放',
		4 => '暂未投中', 5 => '竞投中', 6 => '暂投中'
	);
    
    private $growthBrokerCredit;
    private $growthBrokerBidHouse;
    
    public function __construct($type = NULL) {
        parent::__construct($type);
        $this->initUserInfo();
        $this->checkAuth();
        $this->load->library('TabPage');
        $this->house = $this->config->item('house');
        $this->growthBrokerCredit = new GrowthBrokerCredit($this->broker);
        $this->initGrowthBrokerBidHouse();
        $this->load->helper('common_url');
    }


    private function initUserInfo() {
        $info = $this->broker_model->get_user_session();

        $groupId = $info['package_id']; //套餐
        //$brokerType = $info['groupid'];//免费or付费
        $gbe = new GrowthBrokerExp(array('id' => $info['uid'], 'groupid' => $groupId));
        $gbc = new GrowthBrokerCredit(array('id' => $info['uid'], 'groupid' => $groupId));
        $this->load->model('payment_model');
        $info['payment_url'] = $this->payment_model->get_module_url('recharge');   
        //等级
        $info['level'] = $gbe->getLevel(2);
        //经验
        $info['exp'] = $gbe->getExp();
        //升级天数
        /*
          $allLevel = $this->allLevel();
          $info['nextLevel'] = $this->nextLevel($info['level'],$allLevel);
          $growthExpDayLimit = $this->getGroupDayMaxExp($groupId);
          $info['level_day'] = $this->calUpgradeDays($info['nextLevel'],$growthExpDayLimit,$info['exp']);
         */
        //房豆
        $info['credit'] = $gbc->getValidCredit();
        $this->info = $info;
        $this->uid = $info['uid'];
        
        $broker['id'] = $this->uid;
        $broker['level'] = 'LV'.$this->info['level'];
        $broker['credit'] = $this->info['credit'];
        $broker['groupid'] = $groupId;
        $broker['is_pay'] = $this->info['is_pay'];
        $this->broker = $broker;
    }

    /**
     * 初始化成长体系类
     */
    private function initGrowthBrokerBidHouse() {
        $growthConfig = $this->config->item('growth');
        $mode = $growthConfig['mode'];
        $this->growthBrokerBidHouse = new GrowthBrokerBidHouse($this->broker, $this->growthBrokerCredit,$mode);
        $this->growthBrokerBidHouse->setCheckStar(true);
        $additionalScore = $growthConfig['additionalScore']['house'];
        $this->growthBrokerBidHouse->setAdditionalScore($additionalScore);
    }

    public function index() {
        exit;
    }

    public function all() {
//        if(GB_CITY == 'wh'){
//            $this->jump('/', '竞投服务已关闭！');
//        }
        $brokerLevel = $this->getBrokerLevel();
        $check = $this->checkBidLevel($brokerLevel);
        $broker_new_info =$this->broker_model->get_broker_info_by_uid($this->uid);//20160226 add
		//var_dump($broker_new_info);
        if($check!==true || intval($broker_new_info[0]['starlevel'])<3) {//检查不通过跳转//20160226 add
           // $page_text = "您升级至&nbsp;<span style='color:green;'>{$check}</span>&nbsp;级就可以使用此功能哦 ！<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先去升级吧，加油！";
            $page_text = "您升级至&nbsp;<span style='color:green;'>3</span>&nbsp;星就可以使用此功能哦 ！<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先去升级吧，加油！";
            $this->jump('/', $page_text, 4000);
        }

		//黑名单权限验证
		$this->checkJoinBlacklistAuth();

        $viewData['brokerLevel'] = $brokerLevel;
        $tab = 'all';
        $viewData['js'] = load_js('common/js/jquery.jcountdown.js');
        $viewData['css'] = load_css('zsb/css/v1.0/style1.css');
        //发布房源地址
        $addHouseUrl = '#';//$addSellHouseUrl;
        //修改房源地址
        $modfiyHouseUrl = '#';//$modfiySellHouseUrl;
        
        $arrBroker = array('id' => $this->uid);
        
        $searchWhere = array('esta' => 1, 'uid' => $arrBroker['id'], 'agentcode' => 'B000');
        
        $keywords = $this->input->get("keywords");
        $infotype = $this->input->get('infotype');
        if ($infotype) {
            $searchWhere['infotype'] = $infotype;
        }
        $viewData['infotype'] = $infotype;
        $viewData['infotypeSelect'] = $this->widget('imitateSelect',
                array('label'=>'房源类型','value'=>$infotype,'key'=>'infotype','options'=>$this->house['infotype']));
        
        $k_id = $this->input->get("k_id")?$this->input->get("k_id"):1;
        if ($k_id == 1 && $keywords != '') {
            $searchWhere['blockshowname'] = " LIKE '%$keywords%'";
        } else if ($k_id == 2 && $keywords != '') {
            $searchWhere['id'] = $keywords;
        }
        //<dd><a class="link" href="####" oid="1">小区名称</a></dd>
        //<dd><a class="link" href="####" oid="2">房源编号</a></dd>
        $viewData['k_idSelect'] = $this->widget('imitateSelect',
                array('label'=>'小区名称','value'=>$k_id,'key'=>'k_id','options'=>array('1'=>'小区名称','2'=>'房源编号'),'def'=>false));
        $viewData['keywords'] = $keywords;
        //房豆
        $growthCredit = new GrowthCredit();
        $brokerCredit = $growthCredit->findByBrokerId($this->uid);
        $brokerCredit['credit'] = $brokerCredit['credit'] == '' ? 0 : $brokerCredit['credit'] - $brokerCredit['frozen'];
               
        $growthBrokerBidHouse = $this->growthBrokerBidHouse;//new GrowthBrokerBidHouse($arrBroker, $growthBrokerCredit);

        $growthBidPeriods = new GrowthBidPeriods();
        $cBidPeriods = $growthBidPeriods->currentBidPeriods(2);
        if(!$cBidPeriods) {
            show_404('出错啦');
        }
        $viewData['cBidPeriods'] = $cBidPeriods;

        //type 1,小区词，2,热搜词，3,板块词
        $growthBidHouse = new GrowthBidHouse();
        
		$this->getDistrictSearchWords($growthBidHouse,$cBidPeriods['id']);
		$this->getStreetSearchWords($growthBidHouse,$cBidPeriods['id']);

        $viewData['arrBlockId'] = $this->getBidBlockId($growthBidHouse,$cBidPeriods['id']);
        $viewData['arrHotSearchWords'] = $this->getHotSearchWords($growthBidHouse,$cBidPeriods['id']);
        $viewData['bidBlockWords'] = $this->getBlockWordLevel();
        $viewData['bidHotSearchWords'] = $this->getHotSearchWordsLevel();
        
        //以房源为基础
        $rows_all = $growthBrokerBidHouse->findHouseCountNew($searchWhere);
        $rows_all = is_array($rows_all) ? 0 : $rows_all;
	  
        $per_page = 5;
        $pageSegment = 4;
        $page = $this->input->get('page')?$this->input->get('page'):1;
        $queryArray = array();
        $queryArray['infotype'] = $infotype;
        $queryArray['k_id'] = $k_id;
        if($keywords) {
            $queryArray['keywords'] = $keywords;
        }
        $queryString = http_build_query($queryArray);
        $base_url = '/market_bid_house_manage/all/?'.$queryString;
        $data_info = array();
        if ($rows_all > 0) {
           $start = ($page-1)*$per_page;
           $limit =$per_page;
           $houseInfo = $growthBrokerBidHouse->findHouseListNew($searchWhere, 'creattime', 'DESC', $start, $limit);
           $data_info = $growthBrokerBidHouse->findBidHouseRecordList($cBidPeriods, $houseInfo);
        }
		
        $viewData['bidBehavior'] = $this->bidBehavior;
        $viewData['rows_all'] = $rows_all;
        $viewData['data_info'] = $data_info;
        $viewData['info'] = $this->info;
        $viewData['person'] = $this->widget('person');
		$viewData['hotword'] = $this->widget('hotword');
        $viewData['tab'] = $this->overViewTab('all');//tab页
        $viewData['house'] = $this->house;
		$viewData['functionSwitch'] = $this->config->item('functionSwitch');
        $viewData['self'] = $this;
        $viewData['page'] = $this->page($rows_all,$per_page,$pageSegment,$base_url);
		$viewData['google_analytics'] = get_ga_js_code('/营销中心/房源竞投/全部房源/');
        $this->view('market', 'market_bid_house_manage/all', $viewData);
    }
    
    public function on() {
        
        $brokerLevel = $this->getBrokerLevel();
        $check = $this->checkBidLevel($brokerLevel);
        $broker_new_info =$this->broker_model->get_broker_info_by_uid($this->uid);//20160226 add
        if($check!==true || intval($broker_new_info[0]['starlevel'])<3) {//检查不通过跳转//20160226 add
           // $page_text = "您升级至&nbsp;<span style='color:green;'>{$check}</span>&nbsp;级就可以使用此功能哦 ！<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先去升级吧，加油！";
            $page_text = "您升级至&nbsp;<span style='color:green;'>3</span>&nbsp;星就可以使用此功能哦 ！<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;先去升级吧，加油！";
            $this->jump('/', $page_text, 4000);
        }

        //黑名单权限验证
		$this->checkJoinBlacklistAuth();


        $viewData['brokerLevel'] = $brokerLevel;
        
        $tab = 'on';
        $viewData['js'] = load_js('common/js/jquery.jcountdown.js');
        $viewData['css'] = load_css('zsb/css/v1.0/style1.css');
        //发布房源地址
        $addHouseUrl = '#';//$addSellHouseUrl;
        //修改房源地址
        $modfiyHouseUrl = '#';//$modfiySellHouseUrl;
        
        $arrBroker = array('id' => $this->uid);
        //房豆
        $growthCredit = new GrowthCredit();
        $brokerCredit = $growthCredit->findByBrokerId($this->uid);
        $brokerCredit['credit'] = $brokerCredit['credit'] == '' ? 0 : $brokerCredit['credit'] - $brokerCredit['frozen'];
               
        $growthBrokerBidHouse = $this->growthBrokerBidHouse;//new GrowthBrokerBidHouse($arrBroker, $growthBrokerCredit,'房豆','房豆');
        //$growthBrokerBidHouse->setCheckStar(true);
        $growthBidPeriods = new GrowthBidPeriods();
        $cBidPeriods = $growthBidPeriods->currentBidPeriods(2);
        if(!$cBidPeriods) {
            show_404('出错啦');
        }
        $viewData['cBidPeriods'] = $cBidPeriods;

        //type 1,小区词，2,热搜词，3,板块词
        $growthBidHouse = new GrowthBidHouse();

		$this->getDistrictSearchWords($growthBidHouse,$cBidPeriods['id']);
		$this->getStreetSearchWords($growthBidHouse,$cBidPeriods['id']);
        
        $viewData['arrBlockId'] = $this->getBidBlockId($growthBidHouse,$cBidPeriods['id']);
        $viewData['arrHotSearchWords'] = $this->getHotSearchWords($growthBidHouse,$cBidPeriods['id']);
        $viewData['bidBlockWords'] = $this->getBlockWordLevel();
        $viewData['bidHotSearchWords'] = $this->getHotSearchWordsLevel();
        
        //以竞投中记录为基础
        $rows_all = $growthBrokerBidHouse->findBidOnHouseRecordCount();
        
        $per_page = 5;
        $pageSegment = 4;
        $page = $this->input->get('page')?$this->input->get('page'):1;
        $queryArray = array();
        $queryString = http_build_query($queryArray);
        $base_url = '/market_bid_house_manage/on/?'.$queryString;
        
        $data_info = array();
        if ($rows_all > 0) {
           $start = ($page-1)*$per_page;
           $limit =$per_page;
           $bidRecord = $growthBrokerBidHouse->findBidOnHouseRecord('utime', 'DESC', $start, $limit);
           $data_info = $growthBrokerBidHouse->findBidOnHouseRecordList($cBidPeriods, $bidRecord);
        }

        $viewData['bidBehavior'] = $this->bidBehavior;
        $viewData['rows_all'] = $rows_all;
        $viewData['data_info'] = $data_info;
        $viewData['info'] = $this->info;
        $viewData['person'] = $this->widget('person');
		$viewData['hotword'] = $this->widget('hotword');
        $viewData['tab'] = $this->overViewTab('on');//tab页
        $viewData['house'] = $this->house;
        $viewData['functionSwitch'] = $this->config->item('functionSwitch');
        $viewData['self'] = $this;
        $viewData['page'] = $this->page($rows_all,$per_page,$pageSegment,$base_url);
		$viewData['google_analytics'] = get_ga_js_code('/营销中心/房源竞投/本期参与的房源/');
        $this->view('market', 'market_bid_house_manage/on', $viewData);
    }
    
    public function history() {
        $tab = 'all';
        $viewData['js'] = load_js('common/js/jquery.jcountdown.js');
        $viewData['css'] = load_css('zsb/css/v1.0/style1.css');
        //发布房源地址
        $addHouseUrl = '#';//$addSellHouseUrl;
        //修改房源地址
        $modfiyHouseUrl = '#';//$modfiySellHouseUrl;
        
        $arrBroker = array('id' => $this->uid);
        
        $searchWhere = array('esta' => 1, 'uid' => $arrBroker['id'], 'agentcode' => 'B000');
        

        $infotype = $this->input->get('infotype');
        if ($infotype) {
            $searchWhere['infotype'] = $infotype;
        } 
        $viewData['infotypeSelect'] = $this->widget('imitateSelect',
                array('label'=>'房源类型','value'=>$infotype,'key'=>'infotype','options'=>$this->house['infotype']));
        $viewData['infotype'] = $infotype;
        
        $keywords = $this->input->get("keywords");
        $k_id = $this->input->get("k_id")?$this->input->get("k_id"):1;
        if ($k_id == 1 && $keywords != '') {
            $searchWhere['blockshowname'] = " LIKE '%$keywords%'";
        } else if ($k_id == 2 && $keywords != '') {
            $searchWhere['id'] = $keywords;
        }
        $viewData['keywords'] = $keywords;
        //<dd><a class="link" href="####" oid="1">小区名称</a></dd>
        //<dd><a class="link" href="####" oid="2">房源编号</a></dd>
        $viewData['k_idSelect'] = $this->widget('imitateSelect',
                array('label'=>'小区名称','value'=>$k_id,'key'=>'k_id','options'=>array('1'=>'小区名称','2'=>'房源编号'),'def'=>false));
        $viewData['keywords'] = $keywords;
        //房豆
        $growthCredit = new GrowthCredit();
        $brokerCredit = $growthCredit->findByBrokerId($this->uid);
        $brokerCredit['credit'] = $brokerCredit['credit'] == '' ? 0 : $brokerCredit['credit'] - $brokerCredit['frozen'];
               
        

        $growthBidPeriods = new GrowthBidPeriods();
        $cBidPeriods = $growthBidPeriods->currentBidPeriods(2);
        if(!$cBidPeriods) {
            show_404('出错啦');
        }
        $viewData['cBidPeriods'] = $cBidPeriods;

        //type 1,小区词，2,热搜词，3,板块词
        $growthBidHouse = new GrowthBidHouse();

        $viewData['bidBlockWords'] = $this->getBlockWordLevel();
        $viewData['bidHotSearchWords'] = $this->getHotSearchWordsLevel();
        
        $growthBrokerBidHouse = $this->growthBrokerBidHouse;
        //以房源为基础
        
        $rows_all = $growthBrokerBidHouse->findBidHistoryHouseRecordCount($searchWhere);
        $per_page = 5;
        $pageSegment = 4;
        $page = $this->input->get('page')?$this->input->get('page'):1;
        $queryArray = array();
        $queryArray['infotype'] = $infotype;
        $queryArray['k_id'] = $k_id;
        if($keywords) {
            $queryArray['keywords'] = $keywords;
        }
        $queryString = http_build_query($queryArray);
        $base_url = '/market_bid_house_manage/history/?'.$queryString;
        $data_info = array();
        if ($rows_all > 0) {
           $start = ($page-1)*$per_page;
           $limit =$per_page;
           $bidRecord = $growthBrokerBidHouse->findBidHistoryHouseRecord($searchWhere, 'utime', 'DESC', $start, $limit);
           $data_info = $growthBrokerBidHouse->findBidHistoryHouseRecordList($bidRecord);
        }

        $viewData['bidBehavior'] = $this->bidBehavior;
        $viewData['rows_all'] = $rows_all;
        $viewData['data_info'] = $data_info;
        $viewData['info'] = $this->info;
        $viewData['person'] = $this->widget('person');
		$viewData['hotword'] = $this->widget('hotword');
        $viewData['tab'] = $this->overViewTab('history');//tab页
        $viewData['house'] = $this->house;
        $viewData['page'] = $this->page($rows_all,$per_page,$pageSegment,$base_url);
		$viewData['google_analytics'] = get_ga_js_code('/营销中心/房源竞投/竞投历史/');
        $this->view('market', 'market_bid_house_manage/history', $viewData);
    }
	
	//获取二手房热搜词数据
	public function getHotWordData()
	{
		$this->load->model('hotword_model');
		$result = $this->hotword_model->getHotWordData(1);
		
		return $result;
	}
    
    private function getBidBlockId($growthBidHouse,$cBidPeriodsId) {
        $arrBidBlock = $growthBidHouse->findPeriodsBlock($cBidPeriodsId);
        $arrBlockId = array();
        if ($arrBidBlock) {
            foreach ($arrBidBlock as $v) {
                $arrBlockId[] = $v['block_id'];
            }
        }
        $this->arrBlockId = $arrBlockId;
        return $arrBlockId;
    }
    /**
     * 使用概况标签页
     * @param type $curPage
     * @return type
     */
    private function overViewTab($curPage) {
        $tabData = array();
        //$allTab = array('all' => '全部房源', 'on' => '本期我参与的房源', 'history' => '竞投历史');
        $tabData['all'] = array('url'=>'/market_bid_house_manage/all/','name'=>'全部房源');
        $tabData['on'] = array('url'=>'/market_bid_house_manage/on/','name'=>'本期我参与的房源');
        $tabData['history'] = array('url'=>'/market_bid_house_manage/history/','name'=>'竞投历史');

		$documentation = $this->config->item('documentation');
		
        $rightBtns = array();
        $rightBtns[] = array('url'=>$documentation['bid_house_rule'],'name'=>'房源竞投说明');
        return $this->tabpage->generate($tabData,$curPage,$rightBtns);
    }
    
    //获取竞投词等级
    private function getBlockWordLevel() {
        //获取竞投词和热搜词的等级
        $growthBidHouseLevel = new GrowthBidHouseLevel();
        $bidHouseLevel = $growthBidHouseLevel->findAll();
        $bidBlockWords = array();
        if ($bidHouseLevel) {
            foreach ($bidHouseLevel as $v) {
                 if ($v['type'] == 1) {
               $bidBlockWords = explode(',', $v['levels']);
                 }
            }
        }
        $this->bidBlockWords = $bidBlockWords;
        return $bidBlockWords;
    }
    //热搜词的等级
    private function getHotSearchWordsLevel() {
        $growthBidHouseLevel = new GrowthBidHouseLevel();
        $bidHouseLevel = $growthBidHouseLevel->findAll();
        $bidHotSearchWords = array();
        if ($bidHouseLevel) {
            foreach ($bidHouseLevel as $v) {
                if ($v['type'] == 2) {
                $bidHotSearchWords = explode(',', $v['levels']);
                }
            }
        }
        $this->bidHotSearchWords = $bidHotSearchWords;
        return $bidHotSearchWords;
    }
    
    private function getHotSearchWords($growthBidHouse,$cBidPeriodsId) {
        $arrBidHotSearch = $growthBidHouse->findPeriodsHotSearch($cBidPeriodsId);
        $arrHotSearchWords = array();
        if ($arrBidHotSearch) {
            foreach ($arrBidHotSearch as $v) {
                $arrHotSearchWords[] = $v['keyword'];
            }
        }
        $this->arrHotSearchWords = $arrHotSearchWords;
        return $arrHotSearchWords;
    }

	private function getDistrictSearchWords($growthBidHouse,$cBidPeriodsId) 
	{
        $arrBidDistrictSearch = $growthBidHouse->findPeriodsDistrictSearch($cBidPeriodsId);
        $arrDistrictSearchWords = array();
        if($arrBidDistrictSearch) 
		{
            foreach($arrBidDistrictSearch as $v) 
			{
                $arrDistrictSearchWords[] = $v['keyword'];
            }
        }
        $this->arrDistrictSearchWords = $arrDistrictSearchWords;
        return $arrDistrictSearchWords;
    }

	private function getStreetSearchWords($growthBidHouse,$cBidPeriodsId) 
	{
        $arrBidStreetSearch = $growthBidHouse->findPeriodsStreetSearch($cBidPeriodsId);
        $arrStreetSearchWords = array();
        if($arrBidStreetSearch) 
		{
            foreach($arrBidStreetSearch as $v) 
			{
                $arrStreetSearchWords[] = $v['keyword'];
            }
        }
        $this->arrStreetSearchWords = $arrStreetSearchWords;
        return $arrStreetSearchWords;
    }
    
    private function getBrokerLevel() {
        //经纪人成长值等级数据  
        $growthExp = new GrowthExp();
        $brokerExp = $growthExp->findOneByBrokerId($this->uid);
        $brokerExp['exp'] = !isset($brokerExp['exp']) || $brokerExp['exp'] == '' ? 0 : $brokerExp['exp'];
        $growthLevel = new GrowthLevel();
        $brokerLevel = $growthLevel->findOneByExp($brokerExp['exp']);
        $this->brokerLevel = $brokerLevel;
        return $brokerLevel;
    }
    
    /**
     * 检查可以参与的等级
     */
    private function checkBidLevel($brokerLevel) {
        
        //判断有无权访问
        $brokerLevelNum = intval(substr($brokerLevel['name'], 2));
        //经纪人操作等级最低权限
        $growthBidLowLevel = new GrowthBidLowLevel();
        $lowLevel = $growthBidLowLevel->findLevelByType(2);
        $lowLevelId = intval(substr($lowLevel, 2));
        if ($brokerLevelNum < $lowLevelId || $brokerLevelNum == '') {
            return $lowLevel;
        } else {
            return true;
        }
    }
    
    private function hasGetLoginScore() {
        //当日有无领取房豆
        $growthCreditDayCount = new GrowthCreditDayCount();
        $ctime = date('Y-m-d');
        $brokerCreditDayLoginActivity = $growthCreditDayCount->findByTimeWayAliasBrokerId($ctime, 'loginActivity', $_SESSION['broker']['uid']);
        return $isBrokerCreditLogin = count($brokerCreditDayLoginActivity) > 0 ? true : false;
    }
    
    public function generateBidHouseUrl($houseId,$blockId,$tabName='on') {
        $error = 0;
        $result = '';
        //$brokerLevel,$bidBlockWords,$arrBlockId;
        $brokerLevel = $this->brokerLevel;
        $arrBlockId = $this->arrBlockId;
        $bidBlockWords = $this->bidBlockWords;
        if (!in_array($brokerLevel['name'], $bidBlockWords)) {
                $error = 1;
                $result = $bidBlockWords[0];
        } else if (!in_array($blockId, $arrBlockId)) {//$row['block_id'];//$row['house_id'];
                $error = 2;
        }
        if (!$error) {
                $url = '<a href="/market_bid_house/block/'.$tabName.'/'.$houseId.'" class="link_fun">小区词</a>'; 
               // $url = '<span class="noneblock" error = "' . $error 
                 //. '" result="' .$result .'">小区词</span>'; 
        } else {
                $url = '<span class="noneblock" error = "' . $error 
                 . '" result="' .$result .'">小区词</span>'; 
        }
        return $url;
    }
    
    public function generateBidHouseUrlHot($houseId,$content,$tabName='on') {
        $error = 0;
        $result = '';
        $brokerLevel = $this->brokerLevel;
        $arrHotSearchWords = $this->arrHotSearchWords;
        $bidHotSearchWords = $this->bidHotSearchWords;
        $hotSearchWords = implode('|', $arrHotSearchWords);
        if (!in_array($brokerLevel['name'], $bidHotSearchWords)) {
                $error = 1;
                $result = $bidHotSearchWords[0];
        } else if (!preg_match("/{$hotSearchWords}/", $content)) {
                $error = 2;
        }
        if (!$error) {
                return  '<a href="/market_bid_house/hotword/'.$tabName.'/'.$houseId.'" class="link_fun">热搜词</a>';
        } else {
                return '<span class="nonehotsearch" style="color:#999;" house_id="'.$houseId .'" error = "'.$error.'" result="'.$result .'">热搜词</span>';
        }
    }
	
	//区属词竞投URL
	public function generateBidHouseDistrictUrl($houseId,$content,$tabName='on') {
        $error = 0;
        $result = '';
        $arrDistrictSearchWords = implode('|', $this->arrDistrictSearchWords);

        if (!preg_match("/{$arrDistrictSearchWords}/", $content)) 
		{
			$error = 2;
        }

        if(!$error) 
		{
			return  '<a href="/market_bid_house/districtword/'.$tabName.'/'.$houseId.'" class="link_fun">区属词</a>';
        } 
		else 
		{
			return '<span class="noneDistrict" style="color:#999;" house_id="'.$houseId .'" error = "'.$error.'" result="'.$result .'">区属词</span>';
        }
    }
	
	//板块词竞投URL
	public function generateBidHouseStreetUrl($houseId,$content,$tabName='on') {
        $error = 0;
        $result = '';
        $arrStreetSearchWords = implode('|', $this->arrStreetSearchWords);
        if(!preg_match("/{$arrStreetSearchWords}/", $content)) 
		{
			$error = 2;
        }

        if(!$error) 
		{
			return  '<a href="/market_bid_house/streetword/'.$tabName.'/'.$houseId.'" class="link_fun">板块词</a>';
        } 
		else 
		{
			return '<span class="noneStreet" style="color:#999;" house_id="'.$houseId .'" error = "'.$error.'" result="'.$result .'">板块词</span>';
        }
    }
    
    private function widget($name,$data=null) {
        switch ($name) {
            case 'person':

				// 2016-1-14 添加星级数据 -----------start -------->
				$info = $this->broker_model->get_user_session();
				
				$this->load->model('broker_model');
				//echo $uid;die;
				$broker_new_info =$this->broker_model->get_broker_info_by_uid($info['uid']);
				// 2016-1-14 添加星级数据 -----------end -------->
				
				$documentation = $this->config->item('documentation');

                $data = array(
					'info'=>  $this->info,
					'introUrl'=>$documentation['what_credit'],
					'broker_new_info' => $broker_new_info,
					'functionSwitch' => $this->config->item('functionSwitch')   //功能开关	
				);
                $person = $this->load->view('widget/person', $data, true);
                return $person;
                break;
            case 'imitateSelect':
                $value = $data['value'];
                if($value) {
                    $data['name'] = $data['options'][$value];
                } else {
                    $data['name'] = '不限';
                }
                if(!isset($data['def'])) {
                    $data['def'] = true;
                }
                $widget = $this->load->view('widget/imitateSelect', $data, true);
                return $widget;
                break;
			case 'hotword':
                $data = array('info'=> $this->getHotWordData(),'title' => '二手房');
                $widget = $this->load->view('widget/hotword', $data, true);
                return $widget;
                break;
            default:
                break;
        }
    }
    
    private function page($total,$per_page,$pageSegment,$base_url) {
        //分页配置
        $this->load->library('pagination');
        $config['use_page_numbers'] = TRUE;
        $config['full_tag_open'] = '<div class="picPreviewPag">';
        $config['full_tag_close'] = '</div>';
        //首页
        $config['first_link'] = '首页';
        $config['first_tag_open'] = '<span class="prev">';
        $config['first_tag_close'] = '</span>';
        //末页
        $config['last_link'] = '末页';
        $config['last_tag_open'] = '<span class="next">';
        $config['last_tag_close'] = '</span>';
        //下一页
        $config['next_link'] = '下一页&gt;';
        $config['next_tag_open'] = '<span class="next">';
        $config['next_tag_close'] = '</span>';
        //上一页
        $config['prev_link'] = '&lt;上一页';
        $config['prev_tag_open'] = '<span class="prev">';
        $config['prev_tag_close'] = '</span>';
        //当前页
        $config['cur_tag_open'] = '<span class="lin current">';
        $config['cur_tag_close'] = '</span>';
        //其他页
        $config['num_tag_open'] = '<span class="lin">';
        $config['num_tag_close'] = '</span>';
        $config['anchor_class'] = 'class="xx"';
        
        $config['base_url'] = $base_url;//
        $config['total_rows'] = $total;
        $config['per_page'] = $per_page;
        $config['uri_segment'] = $pageSegment;
        $config['num_links'] = 3;
        $config['page_query_string'] = TRUE;
        $config['query_string_segment'] = 'page';
        $this->pagination->initialize($config); 

        return $this->pagination->create_links();
    }
    
    private function checkAuth() {
        if($this->info['is_pay'] != payStatus){
            $this->jump('/', '您当前套餐没有此功能的权限，请联系客户经理开通！');
            exit;
        }
    }


	
	//黑名单权限验证
    private function checkJoinBlacklistAuth(){
        $this->load->model('complain_model');
        $complainList = $this->complain_model->getLastBidBlackList($this->user_arr['uid']);
        if($complainList['isJoin']){
            $endtime = $complainList['end_time'];
            $page_text = "很抱歉，由于您的竞投房源为虚假房源，现取消您参与付费推广的资格。<br/>限制期至 ：{$endtime}";
            $this->jump('/', $page_text, 4000);
            return;            
        }
    }
}

?>
