<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
/**
 * Sell Class
 *
 * 租售宝二手房管理模块
 *
 * @package     zsb
 * @subpackage      Controllers
 * @category        Controllers
 * @author      liuhu
 */
class Sell extends MY_Controller {
    
    /**
    * 城市参数
    *
    * @access private
    * @var stringupdatedisable
    */


    protected  $_city = GB_CITY;
    
    /**
     * 房源模板模块
     * @var type 
     */
    private $_house_template_module = 'sell';

    /**
    * 当前用户uid
    *
    * @access private
    * @var int
    */
    private  $_uid = 0;

    /**
    * 当前页码
    *
    * @access private
    * @var string
    */
    private $_current_page = 1;

    /**
    * 每页条目数
    *
    * @access private
    * @var int
    */
    private $_limit = 20;

    /**
    * 偏移
    *
    * @access private
    * @var int
    */
    private $_offset = 0;

    /**
    * 条目总数
    *
    * @access private
    * @var int
    */
    private $_total_count = 0;
    
    
    /**
    * 解析函数
    *
    * @access public
    * @return void
    */
    public function __construct()
    {     
        parent::__construct();

        //加载房源模型类
        $this->load->model('sell_model');
        $this->load->helper('common_house_helper');

        //可发出售和出租的权限 @todo
        $is_permission = $this->sell_model->get_public_permission($this->user_arr['package_id']);

		//兼容获取微信二维码
		if(!$is_permission && $this->router->fetch_method() == 'get_ajax_wechat_image')
		{
			$is_permission = true;
		}

		//增加判断开通时间是否小于等于当前时间，是则可发，否则不可发布
		$this->load->model('broker_model');
		$info_extra = $this->broker_model->get_broker_detail($this->user_arr['uid']);
		
		/*if(time()-strtotime($info_extra['usetime'])<0){
			//$use_access	= true;
			$is_permission = false;
			//var_dump($is_permission);die;
		}
	
        if ($is_permission === false) 
        {
            $this->jump(GB_WO_URL);
            exit;
        }*/
        //南京站身份证限制发布房源
        if(GB_CITY == 'nj'){
            //判断身份证认证
            $id_certificate = $this->broker_model->get_certificate_info('idcard',$this->user_arr['uid']);
            if($id_certificate['valid_flag'] == 2 || empty($id_certificate['pic1']) || empty($info_extra['idno']))
            {
                define('NEED_ID_CARD', 1);
            }
        }
    }

    
    /**
    * 初始化分页参数
    *
    * @access public
    * @param  int  $current_page
    * @param  int  $page_size
    * @return void
    */
    private function _init_pagination($current_page = 1 , $page_size = 0)
    {
        /** 当前页 */
        $this->_current_page = ( $current_page && is_numeric( $current_page ) ) ?
                intval( $current_page ) : 1;

        /** 每页多少项 */
        $this->_limit = ( $page_size && is_numeric( $page_size ) ) ?
                intval( $page_size ) : $this->_limit;

        /** 偏移量 */
        $this->_offset = ( $this->_current_page - 1 ) * $this->_limit;

        if($this->_offset < 0)
        {
            redirect(base_url());
        }
    }

    /**
     * 渲染房源信息
     * @param type $data_page
     */
    private function render_publish($data_page = array())
    {

        //头部
        $data_page['css'] = load_css('zsb/css/v1.0/style1.css,zsb/css/v1.0/autocomlete.css');
        
        //页面加载需要的数据
        $data_page['page_js'] = load_js('common/js/swf/swfupload.js,'
                . 'zsb/js/v1.0/uploadpic.js,common/js/jquery.validate.min.js,'
                . 'common/js/jquery_ui_autocomplete/ui/jquery.ui.core.js,'
                . 'common/js/jquery_ui_autocomplete/ui/jquery.ui.position.js,'
                . 'common/js/jquery_ui_autocomplete/ui/jquery.ui.widget.js,'
                . 'common/js/jquery_ui_autocomplete/ui/jquery.ui.autocomplete.js,'
                . 'common/js/jquery.ui.mouse.min.js,'
                . 'common/js/jquery.ui.sortable.min.js,zsb/js/v1.0/house.js,'
				. 'zsb/js/v1.0/jquery.jsonp.js,zsb/js/v1.0/wechatUploadImage.js');
        $data_page['house'] = $this->config->item('house');
        $data_page['upload_pic_url'] = $this->config->item('base_url') . 'pic/house/';
		
		//360全景图片类型
		$imageType = $this->config->item('imageType');
		
		$data_page['newImageType'] = $imageType;

		foreach($imageType as $key => $value)
		{
			$imageType[$key] = iconv('gbk','utf-8',$value);
		}
        $data_page['imageType'] = $imageType;
        
		// 2016-1-15 添加星级数据 -----------start -------->
		$uid = $this->user_arr['uid'];
		$data_page['house']['broker_new_info'] =$this->broker_model->get_broker_info_by_uid($uid);
		// 2016-1-15 添加星级数据 -----------end -------->
		
		/*
		//微信类
		$this->load->model('wechat_model');

		//微信上传全景图
		$data_page['wechatPanoramaData'] = $this->wechat_model->get_wechat_info($this->_city);
		
		//微信上传室内图
		$data_page['wechatDoorinData'] = $this->wechat_model->get_wechat_info($this->_city);
		
		//微信上传室外图
		$data_page['wechatDooroutData'] = $this->wechat_model->get_wechat_info($this->_city);

		//微信上传户型图
		$data_page['wechatLayoutData'] = $this->wechat_model->get_wechat_info($this->_city);
		*/

		//房源类型发布规则
		$this->load->model('house_publish_rule_model');

		$houseRuleData = $this->house_publish_rule_model->getHouseRuleOneData(array("type" => "type='1'"));
		
		//正常发布范围
		$data_page['publish_range'] = array();
		if(!empty($houseRuleData['publish_range']))
		{
			$data_page['publish_range'] = unserialize($houseRuleData['publish_range']);
		}
		
		//系统拦截范围
		$data_page['system_intercept_range'] = array();
		if(!empty($houseRuleData['system_intercept_range']))
		{
			$data_page['system_intercept_range'] = unserialize($houseRuleData['system_intercept_range']);
		}
		
		//疑似虚假价格范围
		$data_page['suspected_sham_range'] = array();
		if(!empty($houseRuleData['suspected_sham_range']))
		{
			$data_page['suspected_sham_range'] = unserialize($houseRuleData['suspected_sham_range']);
		}

        //疑似虚假价格范围2
        $data_page['suspected_sham_range2'] = array();
        if(!empty($houseRuleData['suspected_sham_range2']))
        {
            $data_page['suspected_sham_range2'] = unserialize($houseRuleData['suspected_sham_range2']);
        }

        //房源占比
        $data_page['house_ratio'] = !empty($houseRuleData['house_ratio']) ? $houseRuleData['house_ratio']/100 : 0;
		
		//禁止发布范围
		$data_page['ban_publish_range'] = array();
		if(!empty($houseRuleData['ban_publish_range']))
		{
			$data_page['ban_publish_range'] = unserialize($houseRuleData['ban_publish_range']);
		}

		//判断是否全景图片上传权限
		$data_page['panoramaStatus'] = $this->getPanoramaStatus();

		//die("111");
        $this->view('house_manage', 'sell_modify', $data_page);
    }
    

    /**
     * 默认首页
     */
    public function index()
    {
        $this->manage();
    }
    

    /**
     * 发布房源页面
     */
    public function add() 
    {
        $uid = $this->user_arr['uid'];
        $package_id = $this->user_arr['package_id'];
        $tbl = $this->sell_model->get_tbl();
        //可发出售和出租的权限 加到__construct
        //判断库存是否已满 房源列表页地址，用于跳转的
        $url_manage = $this->sell_model->find_func_url();
        $this->load->model('broker_model');
        $this->load->model('package_model');

        // 请求接口验证是否能发布房源（合肥）
        if ( GB_CITY == 'hf' ) {
            $brokerInfo = $this->broker_model->get_broker_info_new();
            if ( !isset( $brokerInfo['license_number'] ) || empty( $brokerInfo['license_number'] ) ) {
                $this->jump( $url_manage, '根据政策要求，房地产经纪机构以及公司从业人员，需至相关部门完成实名登记后方可发布房源；' );
                return;
            }
        }

        $package = $this->package_model->find_by_id($package_id);
        //判断库存量和套餐库存量
        $stock_house_num = $this->broker_model->stock_house_num();
        if ($stock_house_num >= $package["package_stock_num"])
        {
            $this->jump($url_manage, "对不起,已超过帐号房源库存量上限("
                    . "上限{$package['package_stock_num']},已用$stock_house_num) 
                        请到您的房源管理里删除过期房源!");
            return;
        }
        $data_page = array();

		//获取经纪人星级//20160309 xue add
		$broker_info =$this->broker_model->get_broker_info();
        $data_page['broker_starlevel'] = $broker_info['starlevel'];
        $real_status = $broker_info['real_status'];
        $data_page['real_status'] = $real_status;


        //读取房源模板信息
        $template_module = $this->_house_template_module;
        $this->load->model('house_template_model');
        //房源模板数量
        $data_page['template_num'] = $this->house_template_model->
                find_count_by_module($template_module, $uid);
        //模板数 > 0 跳转列表，否则跳转添加页
        if ($data_page['template_num'] > 0)
        {
            //还可保存多少套模板
            $data_page['remain_num'] = $this->house_template_model->template_num 
                    - $data_page['template_num'];
            //模板列表
            $data_page['template_list'] = $this->house_template_model->
                    find_by_module($template_module, $uid);
            $data_page['url_template_manage'] = $this->house_template_model->
                    find_func_url('manage') . $template_module . '/';
        }
        else
        {
           $data_page['url_template_manage'] = $this->house_template_model->
                    find_func_url('add') . $template_module . '/';
        }
        $data_page['url_template_add'] = $this->house_template_model->
                 find_func_url('add') . $template_module . '/';
        //获取发布过房源历史小区信息
        $this->sell_model->set_select_fields(array('blockid', 'blockshowname'));
        $data_page['publish_block'] = $this->sell_model->find_publish_block($uid);
        //房源特色
        $this->load->model('house_feature');
        $data_page['feature_arr'] = $this->house_feature->find_feature($tbl, 1);
        $data_page['feature'] = $this->house_feature->find_house_feature('', $tbl);
      /*  if($this->_city == 'wh'){
            $filterArr = array(12,13,15,22,64);
            foreach ($data_page['feature_arr'] as $k=>$val){
                if(in_array($k,$filterArr)){
                    unset($data_page['feature_arr'][$k]);
                }
            }

        }*/
        //发布多图和普通房源添加成长值的分值
        $gcep = new GrowthExpWayPackage();
        $starScore = $gcep->findScoreByWayAliasAndPackageId('pStarHouse', $package_id);
        $noStarScore = $gcep->findScoreByWayAliasAndPackageId('pNoStarHouse', $package_id);
        $data_page['star_score'] = $starScore;
        $data_page['no_star_score'] = $noStarScore;
        //允许发布的房源类型
        $data_page['allow_publish_infotype'] = $this->sell_model->
                get_public_infotype_permission($package_id);
        //当天发布共获得多少成长值
        $growthExpDayCount = new GrowthExpDayCount();
        $publishEventArray = array('pQualityHouse','pStarHouse','pNoStarHouse');
        $exp_rank_day = $growthExpDayCount->getExpAndRank($uid, $publishEventArray);

        $data_page['growthDaySum'] = $exp_rank_day['exp'];
        //当前用的排序名次百分比
        $data_page['rankRate'] = $exp_rank_day['rate'];
        //帮助文档
        $data_page['documentation'] = $this->config->item('documentation');
        //页面基本参数
        $data_page['method'] = 'add';
        $data_page['url_house_submit'] = $this->sell_model->find_func_url('insert');
        //统计代码
        $data_page['page_title'] = '房源管理-发布出售';
		$data_page['google_analytics'] = get_ga_js_code('/房源管理/发布出售/');
		//提交验证随机码
	
		if(!$this->broker_model->get_rand_post()){
		    $this->broker_model->set_rand_post();
		}
		
		$data_page['post_rand'] = $this->broker_model->get_rand_post();

		/*$cacheRepeatFromValue = $this->_city.'_'.$uid.'_'.time();
		$cacheRepeatFromKey = $this->_city.'_cacheRepeatFromKey_'.$uid;

		$this->mc->set($cacheRepeatFromKey,$cacheRepeatFromValue,1200);
		
		$data_page['post_rand'] = array('post_key' => $cacheRepeatFromKey,'post_value' => $cacheRepeatFromValue);*/

		// 是否能够发全景房
		$config = $this->config->item('is_publish_360');
		if($config === false){
			$config = true;
		}else{
			if($config == 1){
				$config = true;
			}else{
				$config = false;
			}
		}

        $packageId = $this->user_arr['package_id'];
        $realNumLimit =$this->broker_model->get_realnum_by_packageid($packageId);
        
        $data_page['realNumLimit'] = $realNumLimit;  //套餐可发真房源数量
        $this->load->model('real_house_model');
        $data_page['realHouseNum']= $this->real_house_model->getUidRealHouseNum($uid); //经纪人 已发真房源数量
        $data_page['balance']= $this->real_house_model->getBrokerRealHouseMoney($uid);//经纪人账号余额

		$data_page['is_publish_360'] = $config;
		$data_page['notice360'] = $this->sell_model->get360Notice();
        $data_page['p_filename_real'] =array();
        //print_r($this->config->item('isOwnerCheck'));die;
        // Owner
        if ($this->config->item('isOwnerCheck')) {
            $this->load->model('Owner');
            $owner = new Owner();
            //var_dump($owner->getContractType());
            $data_page['ownerContractType'] = $owner->getContractType();
        }
	    $is_open_real_house = $this->config->item('is_open_real_house');

        $is_show_real = 0;
        if($real_status && $is_open_real_house){
	        $is_show_real = 1;
        }
	    $data_page['is_show_real'] = $is_show_real;
        //加载模板
        $this->render_publish($data_page);
    }
    
    /**
     * 插入房源数据 model
     */
    public function insert() 
    {

        //一、获取经纪人UID
		$this->load->model('broker_model');
		$session_info = $this->broker_model->get_user_session();
		
        $uid = $this->user_arr['uid'];
        $package_id = $this->user_arr['package_id'];
        $companycode = $this->user_arr['agentcode'];
        $tbl = $this->sell_model->get_tbl();
        $nowtime = time();
        //二、发布出售权限
        //房源列表页地址，用于跳转的
        $url_manage = $this->sell_model->find_func_url();
        //控制发布房源的时间限制
        $session_key = $uid . '_last_sell_add_time';
        $session_value = $this->session->userdata($session_key);
        /*if ($session_value > 0 && $nowtime - $session_value <= 5) {
            $this->session->set_userdata(array($session_key => $nowtime));
            $this->jump($url_manage, "服务器正忙，请稍后再试");
            return;
        } else {
            $this->session->set_userdata(array($session_key => $nowtime));
        }*/
        $this->load->model('broker_model');
        $this->load->model('package_model');
        $package = $this->package_model->find_by_id($package_id);

        // 请求接口验证是否能发布房源（合肥）
        if ( GB_CITY == 'hf' ) {
            $brokerInfo = $this->broker_model->get_broker_info_new();
            if ( !isset( $brokerInfo['license_number'] ) || empty( $brokerInfo['license_number'] ) ) {
                $this->jump( $url_manage, '根据政策要求，房地产经纪机构以及公司从业人员，需至相关部门完成实名登记后方可发布房源；' );
                return;
            }
        }

        //防止模拟提交房源数据 xue 2015-06-16
        //提交验证随机码
		$post_rand = $this->broker_model->get_rand_post();
        $post_value = $this->input->post($post_rand['post_key'], true);
	   // if($uid==863987){
		   //var_dump($post_rand);
		   //var_dump($post_value);exit();
		//}
		
		/*if($post_rand['post_value']!=$post_value)
		{
		    echo "<script>alert('参数错误！');history.go(-1);</script>";
            exit;		
		}*/

		//防止模拟提交和多次请求
		//$cacheRepeatFromKey = $this->_city.'_cacheRepeatFromKey_'.$uid;
		//$cacheCheckFromValue = $this->mc->get($cacheRepeatFromKey);
		
        //if(empty($_POST[$cacheRepeatFromKey]) || $_POST[$cacheRepeatFromKey] != $cacheCheckFromValue)
		//{
		    //echo "<script>alert('参数错误！');history.go(-1);</script>";
            //exit;		
		//}
		
		//清空模拟提交和多次请求缓存值
		//$this->mc->delete($cacheRepeatFromKey);	
		
		//360全景图片
		$imageUrlArr = $this->input->post('imageUrl',true);

        //四、判断源活房源是否有否超过上限，规则：360全景图片房源等于2个普通房源
        $valid_house_num = $this->broker_model->valid_house_num();
        //$esta = $valid_house_num >= $package["package_valid_num"] ? 2 : 1;
		
		//360全景房源标签规则
		$address = $this->input->post('address', true);
		$remark = $this->input->post('remark');
		$p_sort_arr = $this->input->post('p_sort', true);

		$is360 = 0;
		$imageUrlTotal = 0;
		if(!empty($imageUrlArr))
		{
			$imageUrlTotal = count($imageUrlArr);
		}
		
		if($imageUrlTotal >= 3 && strlen($address) >= 20 && strlen($remark) >= 60 && !empty($p_sort_arr) && (in_array('0',$p_sort_arr) || in_array('9',$p_sort_arr)) && (in_array('1',$p_sort_arr) || in_array('10',$p_sort_arr)))
		{
			$is360 = 2;
		}
		elseif($imageUrlTotal >= 1)
		{
			$is360 = 1;
		}
		
		/*if($is360 == '2')
		{
			$esta = ($valid_house_num + 2) <= $package["package_valid_num"] ? 1 : 2;
		}
		else
		{
			$esta = ($valid_house_num + 1) <= $package["package_valid_num"] ? 1 : 2;
		}*/

		$esta = ($valid_house_num + 1) <= $package["package_valid_num"] ? 1 : 2;

		$stock_house_num = $this->broker_model->stock_house_num();
		if ($stock_house_num >= $package["package_stock_num"])
		{
			$this->jump($url_manage, "对不起,已超过帐号房源库存量上限("
					. "上限{$package['package_stock_num']},已用$stock_house_num) 
						请到您的房源管理里删除过期房源!");
			return;
		}
		
        if ($esta == 1) //激活房源判断是否刷新超过上限
        {
            $this->load->model('log_refresh');
            $total_refresh_num = $this->log_refresh->findTodayNumberByBrokerId($uid);
            //$esta = $total_refresh_num >= $package["package_refresh_num"] ? 2 : 1;
        }

        /*if ($esta == 2) //失效房源判断库存量和套餐库存量
        {
            $stock_house_num = $this->broker_model->stock_house_num();
            if ($stock_house_num >= $package["package_stock_num"])
            {
                $this->jump($url_manage, "对不起,已超过帐号房源库存量上限("
                        . "上限{$package['package_stock_num']},已用$stock_house_num) 
                            请到您的房源管理里删除过期房源!");
                return;
            }
        }*/

        //五、插入房源信息
        //经纪人发布房源的默认agentcode
        $agentcode = 'B000';
        $this->load->helper('common_string_helper');
        //房源参数
        $fields_values = array();
        /* 前台客户端已验证小区文本框填写的内容是否有效小区，这里根据输入框的值，
         * 来获取小区相关信息，而不是通过post方式提交
         * update 2012-5-7 xz
         */
        $blockshowname = trim($this->input->post('blockshowname', true));
        if($blockshowname != '')
        {
            $this->load->model('block_model');
            $this->block_model->set_select_fields(array('id','blockname','district','streetid','averprice','esta'));//xue modify 2016-03-14
            $block = $this->block_model->find_by_blockname($blockshowname);
            if( !empty($block))
            {
                //住宅不能发布待审核小区房源
                if( intval($this->input->post('infotype', true)) == 1 && $block['esta'] == 0 ){
                    $this->jump($url_manage, '住宅不能发布待审核小区房源，请重新输入小区！', 3000);
                    exit;
                }
                $blockid = $block['id'];
                $district = $block['district'];
                $streetid = $block['streetid'];
                $blockshowname = $block['blockname'];
				$block_averprice = $block['averprice'];//xue modify 2016-03-14
				$block_esta = $block['esta'];
            }
            else
            {
                echo "<script>alert('小区不存在，请重新输入小区名称或添加新小区后在小区列表中选择！');history.go(-1);</script>";
                exit;
            }
            $mright = $this->input->post('mright', true);
			 //住宅类判断价格上下浮动30%  xue modify 2016-03-14
			$lctype = $this->input->post('lctype', true);
			if(intval($this->input->post('infotype', true))==1&&$block_esta==2&&$mright=='产权房'&&$lctype==1){

                /*$fields_values['price'] = $this->input->post('price', true);
			    $fields_values['buildarea'] = $this->input->post('buildarea', true) 
                ? $this->input->post('buildarea', true) : 1;
			    //获取房源均价
			    $house_averprice = round(10000 * $fields_values['price'] 
                / $fields_values['buildarea'], 2);

                $min_averprice = $block_averprice*0.7;
                $max_averprice = $block_averprice*1.3;

				if($house_averprice<$min_averprice ){
				   echo "<script>alert('小区价格太离谱了，亲！');history.go(-1);</script>";
                   exit;
				 
				 }*/
			
			}


        }
        else
        {
            echo "<script>alert('请填写小区！');history.go(-1);</script>";
            exit;
        }
        /*******************基本信息开始***************************/
        $fields_values['infotype'] = intval($this->input->post('infotype', true));
        $allow_infotype = $this->sell_model->get_public_infotype_permission($package_id);
        if (!in_array($fields_values['infotype'], $allow_infotype)) 
        {
            echo "<script>alert('没有权限发布此类型房源，请重新选择');history.go(-1);</script>";
            exit;
        }

        $fields_values['buildingnum'] = $this->input->post('buildingnum', true);
        $fields_values['unitnum'] = $this->input->post('unitnum', true);
        $fields_values['roomnum'] = $this->input->post('roomnum', true);
		
        $fields_values['agentcode'] = $agentcode;
        $fields_values['infofrom'] = get_infofrom_by_agentocde($agentcode);
        $fields_values['uid'] = $uid;
        $fields_values['esta'] = $esta;
        $fields_values['district'] = str_replace('"','',$district);
        $fields_values['streetid'] = $streetid;
        $fields_values['blockid'] = $blockid;
        $fields_values['blockshowname'] = csubstr($this->input->post('blockshowname', true), 20);
        $fields_values['price'] = $this->input->post('price', true);
        $fields_values['priceterm'] = $this->input->post('priceterm', true);
        $fields_values['pricetype'] = $this->input->post('pricetype', true);
		$fields_values['taxonlytype'] = $this->input->post('taxonlytype', true);
		$fields_values['is360'] = $is360;
        $fields_values['buildarea'] = $this->input->post('buildarea', true) 
                ? $this->input->post('buildarea', true) : 1;
        $fields_values['averprice'] = round(10000 * $fields_values['price'] 
                / $fields_values['buildarea'], 2);
        if (500 > $fields_values['averprice'] || $fields_values['averprice'] > 350000) 
		{
            //echo "<script>alert('当前单价为：" . $fields_values['averprice'] . "元/平米，单价必须在2000-350000元/平米之间');history.go(-1);</script>";

			$this->jump($url_manage, '禁止发布', 3000);
            exit;
        }
        //2017-09-07住宅额外增加面积,单价判断判断
        if($fields_values['infotype'] == 1){
            if(15 > $fields_values['buildarea'] || $fields_values['buildarea'] > 9999){
                $this->jump($url_manage, '住宅面积必须在15-500平米之间', 3000);
                exit;
            }
            if(500 > $fields_values['averprice'] || $fields_values['averprice'] > 150000){
                $this->jump($url_manage, '住宅单价必须在500-150000元/平米之间', 3000);
                exit;
            }
        }
        if( 3 > $fields_values['buildarea'] || $fields_values['buildarea'] > 150000)
        {
            echo "<script>alert('面积必须在3-150000平米之间');history.go(-1);</script>";
            exit;
        }

        //住宅使用权房价格限制
        if ($fields_values['infotype'] == 1 && !empty($block_averprice) && $block_averprice > 0 && $mright=='使用权房')
        {
            $min_averprice = $block_averprice*0.6;
            $max_averprice = $block_averprice*1.6;
            if ($min_averprice > $fields_values['averprice'] || $fields_values['averprice'] > $max_averprice)
            {
                $this->jump($url_manage, '禁止发布', 3000);
                exit;
            }
        }

        //只有物业类型 住宅 别墅 有室、厅等参数
        if ($fields_values['infotype'] == 1 || $fields_values['infotype'] == 2) 
        {
            $fields_values['room'] = $this->input->post('room', true);
            $fields_values['hall'] = $this->input->post('hall', true);
            $fields_values['toilet'] = $this->input->post('toilet', true);
            $fields_values['kitchen'] = $this->input->post('kitchen', true);
            $fields_values['balcony'] = $this->input->post('balcony', true);
        }
        else
        {
            //其它类型强制设为0
            $fields_values['room'] = '';
            $fields_values['hall'] = '';
            $fields_values['toilet'] = '';
            $fields_values['kitchen'] = '';
            $fields_values['balcony'] = '';
        }
        //物业类型为车库车位没有楼层
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['subfloor'] = '';
            $fields_values['floor'] = '';
            $fields_values['totalfloor'] = '';
            $fields_values['fitment'] = '';
            $fields_values['forward'] = '';
        }
        else
        {
            //楼层判断
            $lctype = $this->input->post('lctype', true);
            if ($lctype == 1) //单层
            { 
                $floor = $this->input->post('floor', true);
                $totalfloor = $this->input->post('totalfloor', true);
                if ($floor > $totalfloor) 
                {
                    //跳转页面
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = 0;
                $fields_values['floor'] = $floor;
                $fields_values['totalfloor'] = $totalfloor;
            }   
            if ($lctype == 2) //跃层
            { 
                $subfloor = $this->input->post('subfloor', true);
                $floor2 = $this->input->post('floor2', true);
                $totalfloor2 = $this->input->post('totalfloor2', true);
                if ($subfloor > $totalfloor2 || $floor2 > $totalfloor2) 
                {
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = $subfloor;
                $fields_values['floor'] = $floor2;
                $fields_values['totalfloor'] = $totalfloor2;
            }
            $fields_values['fitment'] = $this->input->post('fitment', true);
            $fields_values['forward'] = $this->input->post('forward', true);
        }

        $real_house_set =$this->input->post('real_house_set', true);
	    $infotype = $fields_values['infotype'];
	    if(!in_array($infotype,array(1,2))){
		    $real_house_set = 0;
	    }
        if($real_house_set>0)
        {
            $url_manage = $this->sell_model->find_func_url('add');
            $this->load->model('real_house_model');

            $realnum_limit =$this->broker_model->get_realnum_by_packageid($package_id);
            $realHouseNum= $this->real_house_model->getUidRealHouseNum($uid);
            if($realHouseNum>=$realnum_limit)
            {
                $this->jump($url_manage, '放心看标签数量已达上限，请先取消已勾选标签或升级您的套餐',3000);
                exit;
            }
        }

        //$fields_values['is_real_house'] = $real_house_set;

		//2016-2-25 zhou添加限制重复房源发布 -------- start ------------>


		$block_remove_limit_num = $this->block_model->get_block_remove_info_by_blockid($blockid);
		if($block_remove_limit_num)
		{
			$publish_limit_num =$block_remove_limit_num;
		}
		else
		{
			$publish_limit_num =30;
		}
		
		$price_start		=$fields_values['price']*0.95;
		$price_end  		=$fields_values['price']*1.05;

		$buildarea_start  =$fields_values['buildarea']-0.5;
		$buildarea_end    =$fields_values['buildarea']+0.5;
		$room		=$fields_values['room'];
		$hall		=$fields_values['hall'];
		$toilet		=$fields_values['toilet'];

		$subfloor	=$fields_values['subfloor'];
		$floor		=$fields_values['floor'];
		$totalfloor	=$fields_values['totalfloor'];



		//查询房源条件
        $cond_where = "uid = '".$uid."' AND esta = 1  AND infofrom = '5' and blockid ='$blockid' and subfloor='$subfloor'  and floor='$floor' and totalfloor='$totalfloor' and room='$room' and hall='$hall' and toilet='$toilet' and buildarea > '$buildarea_start' and buildarea < '$buildarea_end' and price> '$price_start' and price < '$price_end' ";

		//echo $cond_where;die;
		

        //符合条件的总行数
        $broker_publish_total_count = $this->sell_model->find_count_by($cond_where,'0');
		
		
		if($broker_publish_total_count>=$publish_limit_num)
		{
			
			$broker_publish_data_info = $this->sell_model->find_all_by($cond_where);
			if(count($broker_publish_data_info)>$publish_limit_num)
			{
				$show_limit_num =$publish_limit_num;
			
			}
			else
			{
				$show_limit_num =count($broker_publish_data_info);
			}
			$str_show ="";
			for($i =0;$i<$show_limit_num;$i++)
			{
				$str_show .=$broker_publish_data_info[$i]['id'].',';
			}

			$str_show =rtrim($str_show,',');
			echo "<script>alert('此房源与房源编号 " . $str_show 
                    . "重复，禁止发布更多重复房源！');history.go(-1);</script>";
            exit;
		
		}
		

		//2016-2-25 zhou添加限制重复房源发布 -------- end ------------>

        $fields_values['mright'] = $this->input->post('mright', true);
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['buildyear'] = $this->input->post('buildyear1', true);
        } 
        else
        {
            $fields_values['buildyear'] = $this->input->post('buildyear', true);
        }
        $fields_values['contactor'] = $this->user_arr['truename'];
        $fields_values['telno'] = $session_info['telno'];
        $fields_values['creattime'] = time();
		if(GB_CITY=='nj')
		{
			$fields_values['expiretime'] = $fields_values['infotype'] == 1 ? strtotime("+60 days") : strtotime("+90 days");
		}
		else
		{
			$fields_values['expiretime'] = $fields_values['infotype'] == 1 ? strtotime("+90 days") : strtotime("+120 days");
		}
		if(GB_CITY=='wh')
		{
			$fields_values['expiretime'] = strtotime("+60 days");
		}
        $fields_values['updatetime'] = time();
        $fields_values['lucupdatetime'] = $fields_values['updatetime'];
        $fields_values['ip'] = get_ip();
        /*******************基本信息结束***************************/

        /*******************补充信息开始***************************/
        if ($fields_values['infotype'] == 2) 
        {
            $housekind = $this->input->post('housekind', true);
        } 
        else if ($fields_values['infotype'] == 6)
        {
            $housekind = $this->input->post('housekindname', true);
        }
        else
        {
            $fields_values['housekind'] = '';
        }
        if (isset($housekind) && $housekind != '')
        {
            //物业类型 厂房车库代表车位属性
            //物业类型 物业类型代表别墅类型
            $fields_values['housekind'] = $housekind;
        }
        //商业分类
        $tradeclass = $this->input->post('tradeclass', true);
        if (isset($tradeclass) && $tradeclass != '')
        {
            $fields_values['tradeclass'] = $tradeclass;
        }
        //商铺分类
        $housekind = $this->input->post('housekind', true);
        if (isset($housekind) && $housekind != '')
        {
            $fields_values['housekind'] = $housekind;
        }
        //物业费
        $fee = $this->input->post('fee', true);
        if (isset($fee) && $fee != '')
        {
            $fields_values['strata_fee'] = $fee;
        }
        //基础设施
        $baseservice = $this->input->post('baseservice', true);
        if ($baseservice)
        {
            $fields_values['baseservice'] = implode(",", $baseservice);
        }
        $fields_values['ownid'] = trim($this->input->post('ownid', true));
        /*******************补充信息结束***************************/
        
        /*******************详细信息开始***************************/
        $fields_values['address'] = htmlspecialchars(csubstr(trim(
                filterSpace($this->input->post('address', true))),60));

		//敏感词过滤
		if(!empty($fields_values['address']))
		{
			$this->load->model('ajax_model');
			$sensitive_word = $this->ajax_model->check_sensitive_word($fields_values['address']);
			
			if(!empty($sensitive_word))
			{
				echo "<script>alert('含有敏感词：".$fields_values['address']."');history.go(-1);</script>";
                return;
			}
		}

        $fields_values['remark'] = check_word($this->input->post('remark'),STATIC_BADWORD_URL);
        //房源特色
        $fields_values['feature'] = '';
        $feature = $this->input->post('feature', true);
		if(count($feature)>5)
		{
			 echo "<script>alert('标签数据过多, 请重新选择!');history.go(-1);</script>";
                    return;
		}
		
        if(is_array($feature) && !empty($feature))
        {
            $this->load->model('house_feature');
            $feature_arr = $this->house_feature->find_feature($tbl, $fields_values['infotype']);
            foreach($feature as $val)
            {	
                $val = intval($val);
                if($feature_arr[$val] != '')
                {
                    $fields_values['feature'] .= '$'.$val;
                }
            }
            if($fields_values['feature'] != '')
            {
                $fields_values['feature'] .= '$';
            }
        }

		//目前房源发布规则，只支持住宅类型房源
		if($fields_values['infotype'] == 1 && $fields_values['mright'] == '产权房')
		{
			//检查房源发布规则
			//$IpHostAllow =explode('.',GetIp());
		    $resultHousePublishRule = $this->checkHousePublishRule($fields_values);
			//判断是否系统拦截
			if($resultHousePublishRule['system_intercept_status'])
			{
				$fields_values['esta'] = '51';
                $fields_values['is_real_house'] = 0;
			}
		}

       /*******************详细信息结束***************************/
        $fields_values['publish_from'] = 1;  // 发布来源
        //插入房源信息，并返回房源编号
        $house_id = $this->sell_model->insert($fields_values);

        //添加发布房源价格区间限制日志信息
        if(!empty($resultHousePublishRule['suspected_sham_status2']))
        {
            $this->load->model('house_publish_rule_log_model');

            $addData = array('type' => 3, 'uid' => $uid, 'houseId' => $house_id, 'houseType' => '1', 'addTime' => time());
            $this->house_publish_rule_log_model->add($addData);
        }


        if ($house_id)
        {

            //判断房源价格是否在预警价格区间，仅对住宅类做判断
    		/*if ($fields_values['blockid'] && $fields_values['infotype']==1){
    		    $_sell = $fields_values;
    		    $_sell['id'] = $house_id;
    	        $check_rs = bm('sellwarning')->checkSellPrice($_sell,'nj');
    		}*/
			
			if($fields_values['infotype'] == 1)
			{
				$_sell = $fields_values;
    		    $_sell['id'] = $house_id;
				$IpHostAllow =explode('.',GetIp());
                $check_rs = bm('sellwarning')->checkSellPriceNew($_sell,GB_CITY,$resultHousePublishRule['suspected_sham_status']);
			}


			
			//室内,外景,户型图数据集合
			$pfile_name = $this->input->post('p_filename', true);

            //房源封面图
            $pic1 = $this->input->post('pic1', true);

			/*逻辑错误
			if($pic1 != '')
            {
                $pic1 = '';
            }
            else
            {
                $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
            }*/

            if(!empty($pic1))
            {
                $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
            }
            elseif(!empty($pfile_name))
            {
                $pic1 = reset($pfile_name);

                $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;

            }
            elseif(!empty($imageUrlArr))
            {
                $pic1 = reset($imageUrlArr);

                $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
            }


            //四、处理房源图片
            $this->load->model('admin_check');
            $pics = array();
            
            if (isset($pfile_name) && $pfile_name != '') 
            {
                $pics = array(
                    'p_filename' => $pfile_name,
                    'p_sort' => $this->input->post('p_sort', true),
                    'p_title' => $this->input->post('p_title', true),
                    'infotype' => $fields_values['infotype']
                );
            }
           
            //判断有无外景图 1为经纪人上传图片 10为图库图片
            if(!in_array(1,$pics['p_sort']) && !in_array(10,$pics['p_sort']))
            {
                //获取小区外景图
                $this->load->model('block_model');
                $imageUrl = $this->block_model->getBlockImg($blockid);
                if($imageUrl)
                {
                    $pics['p_filename'][] = $imageUrl.'?pid=999999';
                    $pics['p_sort'][] = 10;
                    $pics['p_title'][] = '';
                    $pics['infotype'] = $fields_values['infotype'];
                }
            }
//            print_r($pics);die;
            if(!empty($pics) && is_array($pics))
            {
                $pic_check = $this->sell_model->insert_house_pic($pics,
                $tbl, $house_id, $pic1, $blockid);
                $pic_check_arr = $pic_check['pic_check'];
                //更新封面图
                $this->sell_model->update(array('pic1' => $pic_check['indexpic']), $house_id);
                //审核图片入库
                
                if(isset($pic_check_arr) && is_array($pic_check_arr) 
                        && !empty($pic_check_arr) && $uid > 0)
                {
                    foreach($pic_check_arr as $key => $val)
                    {
                        $infotype = $fields_values['infotype'];
                        $fitment = $fields_values['fitment'];
                        $pic_check_arr[$key]['uid'] = $uid;
                        $pic_check_arr[$key]['housetbl'] = $tbl;
                        $pic_check_arr[$key]['houseid'] = $house_id;
                        $pic_check_arr[$key]['fitment'] = $fitment == "简装" ? 2 : ($fitment == "毛坯" ? 3 : 1);
                        $pic_check_arr[$key]['infotype'] = $infotype == 3 ? 4 : ($infotype == 4 ? 3 : $infotype);//商铺、写字楼互换
                        $pic_check_arr[$key]['dateline'] = $nowtime;
                        //进入审核附属表待夜间JOB过滤入库
                        $this->admin_check->insert_check_pic_sub($pic_check_arr[$key]);
                      /*  //来自设备的图片只入待审核库、不入审核库
                        if($pic_check_arr[$key]['surface'] == 0 && $pic_check_arr[$key]['from_device'] == 1)
                        {
                            unset($pic_check_arr[$key]);
                        }*/
                        unset($pic_check_arr[$key]['from_device']);
                        //封面图入审核表
                        /*if($pic_check_arr[$key]['surface'] == 1)
                        {
                            $this->admin_check->insert_check_pic($pic_check_arr[$key]);
                        }*/

						$functionSwitch = $this->config->item('functionSwitch');
						/*if(!empty($functionSwitch['commonImageJoinCheck']) || $pic_check_arr[$key]['surface'] == 1)
						{
							$this->admin_check->insert_check_pic($pic_check_arr[$key]);
						}*/
                        $this->admin_check->insert_check_pic($pic_check_arr[$key]);
                    }
                }
            }

			//兼容360全景封面图片
			if(!empty($pic1) && empty($pic_check['indexpic']))
			{
				 //更新封面图
                $this->sell_model->update(array('pic1' => $pic1), $house_id);
			}
			
			//360全景图片处理
			if(!empty($imageUrlArr))
			{
				//加载360全景图片业务类模块
				$this->load->model('pic_model');

				//加载360全景审核图片业务类模块
				$this->load->model('admin_check');

				//图片标题
				$imageTitle = $this->input->post('imageTitle',true);

				//图片类型
				$imageType = $this->input->post('imageType',true);
				
				//SQL语句组装
				$position = 0;
				foreach($imageUrlArr as $key => $value)
				{
					$position++;

					$title = '';
					if(isset($imageTitle[$key]))
					{
						$title = $imageTitle[$key];
					}

					$roomtype = '0';
					if(isset($imageType[$key]))
					{
						$roomtype = $imageType[$key];
					}

					$filename = $value;
					if(preg_match("/\?/", $value))
					{
						$filename = substr($value, 0, strpos($value, '?'));
					}
					
					$addUpload360Data = array(
						'tbl' => '1',
						'rowid' => $house_id,
						'position' => $position,
						'filename' => $filename,
						'title' => $title,
						'sort' => '0',
						'createtime' => time(),
						'flg' => '0',
						'isfrom' => '2',
						'isinfotype' => $fields_values['infotype'],
						'roomtype' => $roomtype
					);
					
					$picId = $this->pic_model->insert_house_panorama_pic($addUpload360Data);

					//封面图入审核表
					$surface = '0';
                    if($filename == $pic1)
                    {						
						$surface = '1';
					}

					$addAdmin360PiCheckData = array(
						'uid' => $uid,
						'housetbl' => '1',
						'houseid' => $house_id,
						'fitment' => '0',
						'infotype' => $fields_values['infotype'],
						'pictbl' => 'upload360',
						'picid' => $picId,
						'picurl' => $filename,
						'sort' => '0',
						'roomtype' => $roomtype,
						'surface' => $surface,
						'dateline' => time(),
						'file_md5' => ''
					);
					
					$this->admin_check->insert_360_check_pic($addAdmin360PiCheckData);
				}
			}

            //审核房源描述
            /***
            $remark = $fields_values['remark'];
            $check_remark = preg_replace("/[\s*\t\n\r&nbsp;]/", "", strip_tags($remark));
            if($check_remark != '')
            {
                $remark_check_arr['uid'] = $uid;
                $remark_check_arr['housetbl'] = $tbl;
                $remark_check_arr['houseid'] = $house_id;
                $remark_check_arr['blockname'] = $blockshowname;
                $remark_check_arr['remark'] = $check_remark;
                $remark_check_arr['dateline'] = $nowtime;
                $remark_check_arr['file_md5'] = md5($check_remark);
                $this->admin_check->insert_check_remark_sub($remark_check_arr);
            }***/
            /**
             * 对房成长值的操作
             * 每天成长值的上限；成长值操作房源条数的上限
             */
            /**
            $startTime = strtotime(date('Y-m-d',time()));//当天零点时间戳
            $growthHouseLog = new GrowthHouseLog();
            $publishHouseNum = $growthHouseLog->findCountBy($uid, $startTime);
            $expControllPackage = new GrowthExpControllPackage();                 
            $upperLimitNum = $expControllPackage->findScoreByWayAliasPackageId(
               'dayHouseNum', $package_id);
            $upperFlag = $publishHouseNum < $upperLimitNum ? 1 : 0;***/
			
            $gbe  = new GrowthBrokerExp(array('id' => $uid, 'groupid' => $package_id));		
            $gewp = new GrowthExpWayPackage();
            $ghl  = new GrowthHouseLog();
            //判断优质，多图 先有多图再有优质
            $fields_values['id'] = $house_id;
            $this->load->model('sell_star_model');
            $this->sell_star_model->set_houseinfo($fields_values);
			
            //$this->sell_star_model->set_rowid($house_id);
            $is_star_house = $this->sell_star_model->check_star_standard();
			
            //日志记录房源状态
            $logesta = $fields_values['esta'];
            if ($is_star_house || $is360 == '2')
            {
                $exp = $gewp->findScoreByWayAliasAndPackageId('pStarHouse', $package_id);					 
                $inExpStatus = $gbe->increase('pStarHouse','发布多图房源',$exp);
                $ghl->insertHouseGradeLog($house_id, $tbl, 2, $uid);
                $logesta = $fields_values['esta'] == 1 ? 5 : 6;
                //设置房源属性为多图
                $this->sell_star_model->set_star();
	            //设置放心看
	            $infotype = $fields_values['infotype'];
	            if(in_array($infotype,array(1,2))){
		            if($real_house_set){
			            $this->load->model('zsb_api_model');
			            $this->zsb_api_model->getRequrstData('setRealHouse',array('house_id'=>$house_id));
		            }
	            }

            } 
            else 
            {
                //普通房源
                $exp = $gewp->findScoreByWayAliasAndPackageId('pNoStarHouse', $package_id);					 
                $inExpStatus = $gbe->increase('pNoStarHouse','发布非多图房源',$exp); 
                $ghl->insertHouseGradeLog($house_id, $tbl, 1, $uid);
            }
            $growthMessage = '';
			/*
            if($inExpStatus['status'] == 2 ){
                $growthMessage = "您今天的成长值已达峰值！";
            } elseif($inExpStatus['status'] == 1){
                $growthMessage = "成长值+" . $exp;
            }
			*/
			//$growthMessage = '';
            //记录用户行为
            $this->sell_model->action_log($companycode, $uid, $tbl, $house_id, $logesta);
            if ($fields_values['esta'] == 1) {
                //刷新房源
				if(GB_CITY=='nj')
				{
					refresh_house($uid, $tbl, $house_id);
				}
                $this->sell_model->action_log($companycode, $uid, $tbl, $house_id, 7);

                // 上报房源
                $url = 'https://newrenttest.house365.com/api/tf-app/add-house-detail-report-job?house_id=' . $house_id;
                $this->curl_get_contents($url);
            }
            //中间件数据提交接口
            $this->load->library('statistics');
            //加载门店类
            $this->load->model('agency_model');
            $relation_info = array();
            $relation_info = $this->agency_model->get_relation_by_agentcode($companycode);
            $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
            $parentcode = '';
            if( is_array($relation_info) && !empty($relation_info))
            {	 
                $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
            }
            else
            {	
                $parentinfo = array();
                $select_array = array('parentcode');
                $this->agency_model->set_select_fields($select_array);
                $parentinfo = $this->agency_model->get_company_info_by_code($companycode);
                $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
            }

            $this->statistics->sub_operatecount($uid,$companycode,1,$house_id,
                    '', $tbl, $domain, $parentcode);
            $page_text = "房源发布成功!" . $growthMessage;
            
            //房源冻结后的提醒信息
            if($fields_values['esta'] == '51')
			{
				$url_manage = '/sell/manage/sysfrozen/';
                $page_text = '您发布的房源严重低于市场价格，已被系统自动拦截，如您需要继续发布，可在租售宝后台“系统拦截”中进行申诉，如果该房源被查出虚假，账号会被降1星。';
            }
        }
        else
        {
            $page_text = "抱歉，房源发布失败!";
        }

        // Owner
        if ($this->config->item('isOwnerCheck')) {
            $this->load->model('Owner');
            $owner = new Owner();
            $contractType = $owner->getContractType();
            $ownerData = array();
            $ownerData['land_right_number'] = isset($_POST['owner_land_right_number']) ? $_POST['owner_land_right_number'] : '';
            $ownerData['contract_type'] = isset($_POST['owner_contract_type']) ? $_POST['owner_contract_type'] : '';
            foreach ($contractType as $key => $value) {
                if ($value == $ownerData['contract_type']) {
                    $ownerData['contract_type'] = $key;
                    break;
                }
            }
            $ownerData['contract_number'] = isset($_POST['owner_contract_number']) ? $_POST['owner_contract_number'] : '';
            $ownerData['name'] = isset($_POST['owner_name']) ? $_POST['owner_name'] : '';
            $ownerData['phone'] = isset($_POST['owner_phone']) ? $_POST['owner_phone'] : '';
            $ownerData['identity_card_number'] = isset($_POST['owner_identity_card_number']) ? $_POST['owner_identity_card_number'] : '';
            $ownerDataHouse = array();
            $ownerDataHouse['id'] = $house_id;
            $ownerDataHouse['district'] = $fields_values['district'];
            $ownerDataHouse['area'] = $fields_values['buildarea'];
            $ownerData['house'] = $ownerDataHouse;
            $owner->updateSell($ownerData);

            //添加房产证图片
            if(!empty($_POST['p_filename_real'])) {
                $this->load->model('real_house_model');
                $realHouseMoney = $this->real_house_model->insertCreditImage(1,$house_id,$_POST['p_filename_real']);
            }

        }

        $this->jump($url_manage, $page_text, 3000);
    }


     /**
     * 插入房源数据 model
     */
     public function insertdisable() 
    {       
        //一、获取经纪人UID
		$this->load->model('broker_model');
		$session_info = $this->broker_model->get_user_session();
		
        $uid = $this->user_arr['uid'];
        $package_id = $this->user_arr['package_id'];
        $companycode = $this->user_arr['agentcode'];
        $tbl = $this->sell_model->get_tbl();
        $nowtime = time();
        //二、发布出售权限
        //房源列表页地址，用于跳转的
        $url_manage = $this->sell_model->find_func_url();
        //控制发布房源的时间限制
        $session_key = $uid . '_last_sell_add_time';
        $session_value = $this->session->userdata($session_key);
        if ($session_value > 0 && $nowtime - $session_value <= 5) {
            $this->session->set_userdata(array($session_key => $nowtime));
            $this->jump($url_manage, "服务器正忙，请稍后再试");
            return;
        } else {
            $this->session->set_userdata(array($session_key => $nowtime));
        }
        $this->load->model('broker_model');
        $this->load->model('package_model');
        $package = $this->package_model->find_by_id($package_id);

        //防止模拟提交房源数据 xue 2015-06-16
        //提交验证随机码
		$post_rand = $this->broker_model->get_rand_post();
        $post_value = $this->input->post($post_rand['post_key'], true);
	
        if($post_rand['post_value']!=$post_value){
		    echo "<script>alert('参数错误！');history.go(-1);</script>";
                exit;		
		}
		
		//360全景图片
		$imageUrlArr = $this->input->post('imageUrl',true);

        //四、判断源活房源是否有否超过上限，规则：360全景图片房源等于2个普通房源
        $valid_house_num = $this->broker_model->valid_house_num();
        //$esta = $valid_house_num >= $package["package_valid_num"] ? 2 : 1;
		
		//360全景房源标签规则
		$address = $this->input->post('address', true);
		$remark = $this->input->post('remark');
		$p_sort_arr = $this->input->post('p_sort', true);

		$is360 = 0;
		$imageUrlTotal = 0;
		if(!empty($imageUrlArr))
		{
			$imageUrlTotal = count($imageUrlArr);
		}

		if($imageUrlTotal >= 3 && strlen($address) >= 20 && strlen($remark) >= 60 && !empty($p_sort_arr) && (in_array('0',$p_sort_arr) || in_array('9',$p_sort_arr)) && (in_array('1',$p_sort_arr) || in_array('10',$p_sort_arr)))
		{
			$is360 = 2;
		}
		elseif($imageUrlTotal >= 1)
		{
			$is360 = 1;
		}	
		
		if($is360 == '2')
		{
			$esta = ($valid_house_num + 2) <= $package["package_valid_num"] ? 1 : 2;
		}
		else
		{
			$esta = ($valid_house_num + 1) <= $package["package_valid_num"] ? 1 : 2;
		}

		$stock_house_num = $this->broker_model->stock_house_num();
		if ($stock_house_num >= $package["package_stock_num"])
		{
			$this->jump($url_manage, "对不起,已超过帐号房源库存量上限("
					. "上限{$package['package_stock_num']},已用$stock_house_num) 
						请到您的房源管理里删除过期房源!");
			return;
		}

        if ($esta == 1) //激活房源判断是否刷新超过上限
        {
            $this->load->model('log_refresh');
            $total_refresh_num = $this->log_refresh->findTodayNumberByBrokerId($uid);
            $esta = $total_refresh_num >= $package["package_refresh_num"] ? 2 : 1;
        }

        /*if ($esta == 2) //失效房源判断库存量和套餐库存量
        {
            $stock_house_num = $this->broker_model->stock_house_num();
            if ($stock_house_num >= $package["package_stock_num"])
            {
                $this->jump($url_manage, "对不起,已超过帐号房源库存量上限("
                        . "上限{$package['package_stock_num']},已用$stock_house_num) 
                            请到您的房源管理里删除过期房源!");
                return;
            }
        }*/

        //五、插入房源信息
        //经纪人发布房源的默认agentcode
        $agentcode = 'B000';
        $this->load->helper('common_string_helper');
        //房源参数
        $fields_values = array();
        /* 前台客户端已验证小区文本框填写的内容是否有效小区，这里根据输入框的值，
         * 来获取小区相关信息，而不是通过post方式提交
         * update 2012-5-7 xz
         */
        $blockshowname = trim($this->input->post('blockshowname', true));
        if($blockshowname != '')
        {
            $this->load->model('block_model');
            $this->block_model->set_select_fields(array('id','blockname','district','streetid','averprice','esta'));//xue modify 2016-03-14
            $block = $this->block_model->find_by_blockname($blockshowname);

            if( !empty($block))
            {
                //住宅不能发布待审核小区房源
                if( intval($this->input->post('infotype', true)) == 1 && $block['esta'] == 0 ){
                    $this->jump($url_manage, '住宅不能发布待审核小区房源，请重新输入小区！', 3000);
                    exit;
                }
                $blockid = $block['id'];
                $district = $block['district'];
                $streetid = $block['streetid'];
                $blockshowname = $block['blockname'];
                $block_averprice = $block['averprice'];//xue modify 2016-03-14
                $block_esta = $block['esta'];
            }
            else
            {
                echo "<script>alert('小区不存在，请重新输入小区名称或添加新小区后在小区列表中选择！');history.go(-1);</script>";
                exit;
            }
            $mright = $this->input->post('mright', true);
		    //住宅类判断价格上下浮动30%  xue modify 2016-03-14
			$lctype = $this->input->post('lctype', true);
			if(intval($this->input->post('infotype', true))==1&&$block_esta==2&&$mright=='产权房'&&$lctype==1){

                /*$fields_values['price'] = $this->input->post('price', true);
			    $fields_values['buildarea'] = $this->input->post('buildarea', true) 
                ? $this->input->post('buildarea', true) : 1;
			    //获取房源均价
			    $house_averprice = round(10000 * $fields_values['price'] 
                / $fields_values['buildarea'], 2);

                $min_averprice = $block_averprice*0.7;
                $max_averprice = $block_averprice*1.3;

				if($house_averprice<$min_averprice ){
				   echo "<script>alert('小区价格太离谱了，亲！');history.go(-1);</script>";
                   exit;
				 
				 }*/
			
			}







        }
        else
        {
            echo "<script>alert('请填写小区！');history.go(-1);</script>";
            exit;
        }
        /*******************基本信息开始***************************/
        $fields_values['infotype'] = intval($this->input->post('infotype', true));
        $allow_infotype = $this->sell_model->get_public_infotype_permission($package_id);
        if (!in_array($fields_values['infotype'], $allow_infotype)) 
        {
            echo "<script>alert('没有权限发布此类型房源，请重新选择');history.go(-1);</script>";
            exit;
        }
        $fields_values['agentcode'] = $agentcode;
        $fields_values['infofrom'] = get_infofrom_by_agentocde($agentcode);
        $fields_values['uid'] = $uid;
        $fields_values['esta'] = 2;
        $fields_values['district'] = str_replace('"','',$district);
        $fields_values['streetid'] = $streetid;
        $fields_values['blockid'] = $blockid;
        $fields_values['blockshowname'] = csubstr($this->input->post('blockshowname', true), 20);
        $fields_values['price'] = $this->input->post('price', true);
        $fields_values['priceterm'] = $this->input->post('priceterm', true);
        $fields_values['pricetype'] = $this->input->post('pricetype', true);
		$fields_values['taxonlytype'] = $this->input->post('taxonlytype', true);
		$fields_values['is360'] = $is360;
        $fields_values['buildarea'] = $this->input->post('buildarea', true) 
                ? $this->input->post('buildarea', true) : 1;
        if( 3 > $fields_values['buildarea'] || $fields_values['buildarea'] > 150000)
        {
            echo "<script>alert('面积必须在3-150000平米之间');history.go(-1);</script>";
            exit;
        }
        $fields_values['averprice'] = round(10000 * $fields_values['price'] 
                / $fields_values['buildarea'], 2);
        if (500 > $fields_values['averprice'] || $fields_values['averprice'] > 350000) {
            //echo "<script>alert('当前单价为：" . $fields_values['averprice'] . "元/平米，单价必须在2000-350000元/平米之间');history.go(-1);</script>";

			$this->jump($url_manage, '禁止发布', 3000);
            exit;
        }
        //2017-09-07住宅额外增加面积,单价判断判断
        if($fields_values['infotype'] == 1){
            if(15 > $fields_values['buildarea'] || $fields_values['buildarea'] > 500){
                $this->jump($url_manage, '住宅面积必须在15-500平米之间', 3000);
                exit;
            }
            if(500 > $fields_values['averprice'] || $fields_values['averprice'] > 150000){
                $this->jump($url_manage, '住宅单价必须在500-150000元/平米之间', 3000);
                exit;
            }
        }

        //住宅使用权房价格限制
        if ($fields_values['infotype'] == 1 && !empty($block_averprice)  && $block_averprice > 0 && $mright=='使用权房')
        {
            $min_averprice = $block_averprice*0.6;
            $max_averprice = $block_averprice*1.6;
            if ($min_averprice > $fields_values['averprice'] || $fields_values['averprice'] > $max_averprice)
            {
                $this->jump($url_manage, '禁止发布', 3000);
                exit;
            }
        }

        //只有物业类型 住宅 别墅 有室、厅等参数
        if ($fields_values['infotype'] == 1 || $fields_values['infotype'] == 2) 
        {
            $fields_values['room'] = $this->input->post('room', true);
            $fields_values['hall'] = $this->input->post('hall', true);
            $fields_values['toilet'] = $this->input->post('toilet', true);
            $fields_values['kitchen'] = $this->input->post('kitchen', true);
            $fields_values['balcony'] = $this->input->post('balcony', true);
        }
        else
        {
            //其它类型强制设为0
            $fields_values['room'] = '';
            $fields_values['hall'] = '';
            $fields_values['toilet'] = '';
            $fields_values['kitchen'] = '';
            $fields_values['balcony'] = '';
        }
        //物业类型为车库车位没有楼层
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['subfloor'] = '';
            $fields_values['floor'] = '';
            $fields_values['totalfloor'] = '';
            $fields_values['fitment'] = '';
            $fields_values['forward'] = '';
        }
        else
        {
            //楼层判断
            $lctype = $this->input->post('lctype', true);
            if ($lctype == 1) //单层
            { 
                $floor = $this->input->post('floor', true);
                $totalfloor = $this->input->post('totalfloor', true);
                if ($floor > $totalfloor) 
                {
                    //跳转页面
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = 0;
                $fields_values['floor'] = $floor;
                $fields_values['totalfloor'] = $totalfloor;
            }   
            if ($lctype == 2) //跃层
            { 
                $subfloor = $this->input->post('subfloor', true);
                $floor2 = $this->input->post('floor2', true);
                $totalfloor2 = $this->input->post('totalfloor2', true);
                if ($subfloor > $totalfloor2 || $floor2 > $totalfloor2) 
                {
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = $subfloor;
                $fields_values['floor'] = $floor2;
                $fields_values['totalfloor'] = $totalfloor2;
            }
            $fields_values['fitment'] = $this->input->post('fitment', true);
            $fields_values['forward'] = $this->input->post('forward', true);
        }
        $fields_values['mright'] = $this->input->post('mright', true);
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['buildyear'] = $this->input->post('buildyear1', true);
        } 
        else
        {
            $fields_values['buildyear'] = $this->input->post('buildyear', true);
        }
        $fields_values['contactor'] = $this->user_arr['truename'];
        $fields_values['telno'] = $session_info['telno'];
        $fields_values['creattime'] = time();
        $fields_values['expiretime'] = $fields_values['infotype'] == 1 ? strtotime("+60 days") : strtotime("+90 days");
        $fields_values['updatetime'] = time();
        $fields_values['lucupdatetime'] = $fields_values['updatetime'];
        $fields_values['ip'] = get_ip();
        /*******************基本信息结束***************************/
        
        /*******************补充信息开始***************************/
        if ($fields_values['infotype'] == 2) 
        {
            $housekind = $this->input->post('housekind', true);
        } 
        else if ($fields_values['infotype'] == 6)
        {
            $housekind = $this->input->post('housekindname', true);
        }
        else
        {
            $fields_values['housekind'] = '';
        }
        if (isset($housekind) && $housekind != '')
        {
            //物业类型 厂房车库代表车位属性
            //物业类型 物业类型代表别墅类型
            $fields_values['housekind'] = $housekind;
        }
        //商业分类
        $tradeclass = $this->input->post('tradeclass', true);
        if (isset($tradeclass) && $tradeclass != '')
        {
            $fields_values['tradeclass'] = $tradeclass;
        }
        //商铺分类
        $housekind = $this->input->post('housekind', true);
        if (isset($housekind) && $housekind != '')
        {
            $fields_values['housekind'] = $housekind;
        }
        //物业费
        $fee = $this->input->post('fee', true);
        if (isset($fee) && $fee != '')
        {
            $fields_values['strata_fee'] = $fee;
        }
        //基础设施
        $baseservice = $this->input->post('baseservice', true);
        if ($baseservice)
        {
            $fields_values['baseservice'] = implode(",", $baseservice);
        }
        $fields_values['ownid'] = trim($this->input->post('ownid', true));
        /*******************补充信息结束***************************/
        
        /*******************详细信息开始***************************/
        $fields_values['address'] = htmlspecialchars(csubstr(trim(
                filterSpace($this->input->post('address', true))),60));

		//敏感词过滤
		if(!empty($fields_values['address']))
		{
			$this->load->model('ajax_model');
			$sensitive_word = $this->ajax_model->check_sensitive_word($fields_values['address']);
			
			if(!empty($sensitive_word))
			{
				echo "<script>alert('含有敏感词：".$fields_values['address']."');history.go(-1);</script>";
                return;
			}
		}

        $fields_values['remark'] = check_word($this->input->post('remark'),STATIC_BADWORD_URL);
        //房源特色
        $fields_values['feature'] = '';
        $feature = $this->input->post('feature', true);
		if(count($feature)>5)
		{
			 echo "<script>alert('标签数据过多, 请重新选择!');history.go(-1);</script>";
                    return;
		}
        if(is_array($feature) && !empty($feature))
        {
            $this->load->model('house_feature');
            $feature_arr = $this->house_feature->find_feature($tbl, $fields_values['infotype']);
            foreach($feature as $val)
            {	
                $val = intval($val);
                if($feature_arr[$val] != '')
                {
                    $fields_values['feature'] .= '$'.$val;
                }
            }
            if($fields_values['feature'] != '')
            {
                $fields_values['feature'] .= '$';
            }
        }

        //目前房源发布规则，只支持住宅类型房源
        if($fields_values['infotype'] == 1 && $fields_values['mright'] == '产权房')
        {
            //检查房源发布规则
            $resultHousePublishRule = $this->checkHousePublishRule($fields_values);
            //判断是否系统拦截
            if($resultHousePublishRule['system_intercept_status'])
            {
                $fields_values['esta'] = '51';
            }
        }

       /*******************详细信息结束***************************/
        //插入房源信息，并返回房源编号
        $house_id = $this->sell_model->insert($fields_values);

        //添加发布房源价格区间限制日志信息
        if(!empty($resultHousePublishRule['suspected_sham_status2']))
        {
            $this->load->model('house_publish_rule_log_model');

            $addData = array('type' => 3, 'uid' => $uid, 'houseId' => $house_id, 'houseType' => '1', 'addTime' => time());
            $this->house_publish_rule_log_model->add($addData);
        }

        if ($house_id)
        {
            if($fields_values['infotype'] == 1)
            {
                $_sell = $fields_values;
                $_sell['id'] = $house_id;
                $IpHostAllow =explode('.',GetIp());
                $check_rs = bm('sellwarning')->checkSellPriceNew($_sell,GB_CITY,$resultHousePublishRule['suspected_sham_status']);
            }

			//室内,外景,户型图数据集合
			$pfile_name = $this->input->post('p_filename', true);

            //房源封面图
            $pic1 = $this->input->post('pic1', true);
            
			/*逻辑错误
			if($pic1 != '')
            {
                $pic1 = '';
            }
            else
            {
                $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
            }*/

			if(!empty($pic1))
            {
                $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
            }
			elseif(!empty($p_sort_arr))
			{
				arsort($p_sort_arr);

				$pic1_key = key($p_sort_arr);

				if(isset($pfile_name[$pic1_key]))
				{
					$pic1 = $pfile_name[$pic1_key];

					$pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
				}
			}
			elseif(!empty($imageUrlArr))
			{
				$pic1 = current($imageUrlArr);

				$pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
			}

            //四、处理房源图片
            $this->load->model('admin_check');
            $pics = array();
            
            if (isset($pfile_name) && $pfile_name != '') 
            {
                $pics = array(
                    'p_filename' => $pfile_name,
                    'p_sort' => $this->input->post('p_sort', true),
                    'p_title' => $this->input->post('p_title', true),
                    'infotype' => $fields_values['infotype']
                );
                $pic_check = $this->sell_model->insert_house_pic($pics,
                $tbl, $house_id, $pic1, $blockid);
                $pic_check_arr = $pic_check['pic_check'];
                //更新封面图
                $this->sell_model->update(array('pic1' => $pic_check['indexpic']), $house_id);
                //审核图片入库
                
                if(isset($pic_check_arr) && is_array($pic_check_arr) 
                        && !empty($pic_check_arr) && $uid > 0)
                {
                    foreach($pic_check_arr as $key => $val)
                    {
                        $infotype = $fields_values['infotype'];
                        $fitment = $fields_values['fitment'];
                        $pic_check_arr[$key]['uid'] = $uid;
                        $pic_check_arr[$key]['housetbl'] = $tbl;
                        $pic_check_arr[$key]['houseid'] = $house_id;
                        $pic_check_arr[$key]['fitment'] = $fitment == "简装" ? 2 : ($fitment == "毛坯" ? 3 : 1);
                        $pic_check_arr[$key]['infotype'] = $infotype == 3 ? 4 : ($infotype == 4 ? 3 : $infotype);//商铺、写字楼互换
                        $pic_check_arr[$key]['dateline'] = $nowtime;
                        //进入审核附属表待夜间JOB过滤入库
                        $this->admin_check->insert_check_pic_sub($pic_check_arr[$key]);
                        //来自设备的图片只入待审核库、不入审核库
                        if($pic_check_arr[$key]['surface'] == 0 && $pic_check_arr[$key]['from_device'] == 1)
                        {
                            unset($pic_check_arr[$key]);
                        }
                        unset($pic_check_arr[$key]['from_device']);
                        //封面图入审核表
                        $functionSwitch = $this->config->item('functionSwitch');
                        if(!empty($functionSwitch['commonImageJoinCheck']) || $pic_check_arr[$key]['surface'] == 1)
                        {
                            $this->admin_check->insert_check_pic($pic_check_arr[$key]);
                        }
                    }
                }
            }

			//兼容360全景封面图片
			if(!empty($pic1) && empty($pic_check['indexpic']))
			{
				 //更新封面图
                $this->sell_model->update(array('pic1' => $pic1), $house_id);
			}

			//360全景图片处理
			if(!empty($imageUrlArr))
			{
				//加载360全景图片业务类模块
				$this->load->model('pic_model');

				//加载360全景审核图片业务类模块
				$this->load->model('admin_check');

				//图片标题
				$imageTitle = $this->input->post('imageTitle',true);

				//图片类型
				$imageType = $this->input->post('imageType',true);
				
				//SQL语句组装
				$position = 0;
				foreach($imageUrlArr as $key => $value)
				{
					$position++;

					$title = '';
					if(isset($imageTitle[$key]))
					{
						$title = $imageTitle[$key];
					}

					$roomtype = '0';
					if(isset($imageType[$key]))
					{
						$roomtype = $imageType[$key];
					}

					$filename = '';
					if(preg_match("/\?/", $value))
					{
						$filename = substr($value, 0, strpos($value, '?'));
					}
					
					$addUpload360Data = array(
						'tbl' => '1',
						'rowid' => $house_id,
						'position' => $position,
						'filename' => $filename,
						'title' => $title,
						'sort' => '0',
						'createtime' => time(),
						'flg' => '0',
						'isfrom' => '2',
						'isinfotype' => $fields_values['infotype'],
						'roomtype' => $roomtype
					);
					
					$picId = $this->pic_model->insert_house_panorama_pic($addUpload360Data);

					//封面图入审核表
					$surface = '0';
                    if($filename == $pic1)
                    {						
						$surface = '1';
					}

					$addAdmin360PiCheckData = array(
						'uid' => $uid,
						'housetbl' => '1',
						'houseid' => $house_id,
						'fitment' => '0',
						'infotype' => $fields_values['infotype'],
						'pictbl' => 'upload360',
						'picid' => $picId,
						'picurl' => $filename,
						'sort' => '0',
						'roomtype' => $roomtype,
						'surface' => '1',
						'dateline' => time(),
						'file_md5' => ''
					);
					
					$this->admin_check->insert_360_check_pic($addAdmin360PiCheckData);
				}
			}

            //审核房源描述
            /***
            $remark = $fields_values['remark'];
            $check_remark = preg_replace("/[\s*\t\n\r&nbsp;]/", "", strip_tags($remark));
            if($check_remark != '')
            {
                $remark_check_arr['uid'] = $uid;
                $remark_check_arr['housetbl'] = $tbl;
                $remark_check_arr['houseid'] = $house_id;
                $remark_check_arr['blockname'] = $blockshowname;
                $remark_check_arr['remark'] = $check_remark;
                $remark_check_arr['dateline'] = $nowtime;
                $remark_check_arr['file_md5'] = md5($check_remark);
                $this->admin_check->insert_check_remark_sub($remark_check_arr);
            }***/
            /**
             * 对房成长值的操作
             * 每天成长值的上限；成长值操作房源条数的上限
             */
            /**
            $startTime = strtotime(date('Y-m-d',time()));//当天零点时间戳
            $growthHouseLog = new GrowthHouseLog();
            $publishHouseNum = $growthHouseLog->findCountBy($uid, $startTime);
            $expControllPackage = new GrowthExpControllPackage();                 
            $upperLimitNum = $expControllPackage->findScoreByWayAliasPackageId(
               'dayHouseNum', $package_id);
            $upperFlag = $publishHouseNum < $upperLimitNum ? 1 : 0;***/
            $gbe  = new GrowthBrokerExp(array('id' => $uid, 'groupid' => $package_id));			
            $gewp = new GrowthExpWayPackage();
            $ghl  = new GrowthHouseLog();
            //判断优质，多图 先有多图再有优质
            $fields_values['id'] = $house_id;
            $this->load->model('sell_star_model');
            $this->sell_star_model->set_houseinfo($fields_values);
            //$this->sell_star_model->set_rowid($house_id);
            $is_star_house = $this->sell_star_model->check_star_standard();
            //日志记录房源状态
            $logesta = $fields_values['esta'];
            if ($is_star_house || $is360 == '2')
            {
                $exp = $gewp->findScoreByWayAliasAndPackageId('pStarHouse', $package_id);					 
                $inExpStatus = $gbe->increase('pStarHouse','发布多图房源',$exp);
                $ghl->insertHouseGradeLog($house_id, $tbl, 2, $uid);
                $logesta = $fields_values['esta'] == 1 ? 5 : 6;
                //设置房源属性为多图
                $this->sell_star_model->set_star();
            } 
            else 
            {
                //普通房源
                $exp = $gewp->findScoreByWayAliasAndPackageId('pNoStarHouse', $package_id);					 
                $inExpStatus = $gbe->increase('pNoStarHouse','发布非多图房源',$exp); 
                $ghl->insertHouseGradeLog($house_id, $tbl, 1, $uid);
            }
            $growthMessage = '';
            if($inExpStatus['status'] == 2 ){
                //$growthMessage = "您今天的成长值已达峰值！";
            } elseif($inExpStatus['status'] == 1){
                //$growthMessage = "成长值+" . $exp;
            }
            //记录用户行为
            $this->sell_model->action_log($companycode, $uid, $tbl, $house_id, $logesta);
            if ($fields_values['esta'] == 1) {
                //刷新房源
                refresh_house($uid, $tbl, $house_id);
                $this->sell_model->action_log($companycode, $uid, $tbl, $house_id, 7);
            }
            //中间件数据提交接口
            $this->load->library('statistics');
            //加载门店类
            $this->load->model('agency_model');
            $relation_info = array();
            $relation_info = $this->agency_model->get_relation_by_agentcode($companycode);
            $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
            $parentcode = '';
            if( is_array($relation_info) && !empty($relation_info))
            {	 
                $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
            }
            else
            {	
                $parentinfo = array();
                $select_array = array('parentcode');
                $this->agency_model->set_select_fields($select_array);
                $parentinfo = $this->agency_model->get_company_info_by_code($companycode);
                $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
            }

            $this->statistics->sub_operatecount($uid,$companycode,1,$house_id,
                    '', $tbl, $domain, $parentcode);
            $page_text = "房源发布成功!" . $growthMessage;
        }
        else
        {
            $page_text = "抱歉，房源发布失败!";
        }
        $this->jump($url_manage, $page_text, 3000);
    }
    /**
     * 展示房源修改页面
     */
    public function modify($id, $tab = '') 
    {
        $uid = $this->user_arr['uid'];
        $package_id = $this->user_arr['package_id'];
        $tbl = $this->sell_model->get_tbl();

        //房源列表页地址
        $url_manage_module = $this->sell_model->find_func_url();
        if (!$id)
        {
            $this->jump($url_manage_module, '参数不合法');
            return;
        }
        //查找有无此房源记录，没有则转到列表页
        $house_detail = $this->sell_model->find_by_uid_id($uid, $id);
        if (!$house_detail)
        {
            $this->jump($url_manage_module, '没有发现您查询的记录');
            return;
        }

        $data_page = array();
        $this->load->model('block_model');
        //查找房源的板块名称、查找房源的小区地址
        $block = $this->block_model->base_info_by_id($house_detail['blockid']);

        if ($block) 
        {
            $house_detail['block'] = $block;
        } 
        else
        {

            $this->load->model('street_model');
            $street = $this->street_model->find_by_id($house_detail['streetid']);
            $house_detail['block'] = array(
                'district' => $house_detail['district'],
                'blockname' => $house_detail['blockshowname'],
                'streetid' => $house_detail['streetid'],
                'streetname' => $street['streetname'],
                'address' =>  $house_detail['address'],
                'blockid' => 0
            );
        }

		if(GB_CITY=='nj')
		{
			$data_page['area_prices'] = bm('block')->block_area_prices($house_detail['blockid'],'nj');
		}
        //房源图片
        $this->load->model('pic_model');
        //室内图 2

        $house_detail['house_pic2'] = $this->pic_model->find_house_pic_by($tbl, $id, 2);

        //外景图 1
        $house_detail['house_pic1'] = $this->pic_model->find_house_pic_by($tbl, $id, 1);
        //户型图 0
        $house_detail['house_pic0'] = $this->pic_model->find_house_pic_by($tbl, $id, 0);
        $data_page['house_detail'] = $house_detail;
        //房源模板

        $this->load->model('house_template_model');
        $data_page['url_template_add'] = $this->house_template_model->
                 find_func_url('add') . $this->_house_template_module . '/';
        $data_page['method'] = 'modify';
        $data_page['url_house_submit'] = $this->sell_model->find_func_url('update');
        //发布多图和普通房源添加成长值的分值
        $gcep = new GrowthExpWayPackage();
        $starScore = $gcep->findScoreByWayAliasAndPackageId('pStarHouse', $package_id);
        $noStarScore = $gcep->findScoreByWayAliasAndPackageId('pNoStarHouse', $package_id);
        $data_page['star_score'] = $starScore;
        $data_page['no_star_score'] = $noStarScore;
        //允许发布的房源类型
        $data_page['allow_publish_infotype'] = $this->sell_model->
                get_public_infotype_permission($package_id);
        //房源特色
        $this->load->model('house_feature');
        $data_page['feature_arr'] = $this->house_feature->find_feature($tbl, $house_detail['infotype']);
        $data_page['feature'] = $this->house_feature->
                find_house_feature($house_detail['feature'], $tbl);

        if($this->_city == 'wh'){
            $filterArr = array(12,13,15,22,64);
            foreach ($data_page['feature_arr'] as $k=>$val){
                if(in_array($k,$filterArr)){
                    unset($data_page['feature_arr'][$k]);
                }
            }

        }
        $data_page['tab'] = $tab;

        //获取经纪人星级//20160309 xue add
		$this->load->model('broker_model');
		$broker_info =$this->broker_model->get_broker_info();
		$real_status = $broker_info['real_status'];
		$data_page['broker_starlevel'] = $broker_info['starlevel'];

        //当天发布共获得多少成长值
        $growthExpDayCount = new GrowthExpDayCount();
        $publishEventArray = array('pQualityHouse','pStarHouse','pNoStarHouse');
        $exp_rank_day = $growthExpDayCount->getExpAndRank($uid, $publishEventArray);
        $data_page['growthDaySum'] = $exp_rank_day['exp'];
        //当前用的排序名次百分比
        $data_page['rankRate'] = $exp_rank_day['rate'];
        //帮助文档
        $data_page['documentation'] = $this->config->item('documentation');
        //渲染页面
        $data_page['page_title'] = '房源管理-修改出售';
		$data_page['google_analytics'] = get_ga_js_code('/房源管理/修改出售/');
		//提交验证随机码
		$this->load->model("broker_model");
		$data_page['post_rand'] = $this->broker_model->get_rand_post();

		//获取实景图
		$data_page['houseRelation360PicData'] = $this->pic_model->get_house_pic('1',$id);

		// 是否能够发全景房
		$config = $this->config->item('is_publish_360');
		if($config === false){
			$config = true;
		}else{
			if($config == 1){
				$config = true;
			}else{
				$config = false;
			}
		}
		$data_page['is_publish_360'] = $config;
		$data_page['notice360'] = $this->sell_model->get360Notice();


        $this->load->model('real_house_model');
        $data_page['p_filename_real'] = $this->real_house_model->getCreditImageByRowid(1,$id);
        //print_r($data_page['p_filename_real']);die;
        // Owner
        if ($this->config->item('isOwnerCheck')) {
            $this->load->model('Owner');
            $owner = new Owner();

            $data_page['ownerContractType'] = $owner->getContractType();
            $data_page['ownerData'] = $owner->getSellInformation($id);
        }

        $packageId = $this->user_arr['package_id'];

        $realNumLimit =$this->broker_model->get_realnum_by_packageid($packageId);
        $is_open_real_house = $this->config->item('is_open_real_house');
        $realHouseNum = $this->real_house_model->getUidRealHouseNum($uid);
	    $infotype = $house_detail['infotype'];
		$is_show_real = 0;

        if($is_open_real_house &&  $realNumLimit >0  && $realHouseNum <=$realNumLimit && in_array($infotype,array(1,2)) && $real_status){
	        $is_show_real = 1;
        }
	    $data_page['is_show_real'] = $is_show_real;
        $this->load->model('real_house_model');
        $data_page['balance']= $this->real_house_model->getBrokerRealHouseMoney($uid);//经纪人账号余额

        $this->render_publish($data_page);
    }
    
    /**
     * 更新房源 model
     */
    public function update()
    {
        //一、获取经纪人UID
		$this->load->model('broker_model');
		$session_info = $this->broker_model->get_user_session();	
        $uid = $this->user_arr['uid'];
        $tbl = $this->sell_model->get_tbl();
        $package_id = $this->user_arr['package_id'];
        $house_id = $this->input->post('id', true);
        $url_manage = $this->sell_model->find_func_url();
        //查询房源没修改之前的信息
        //$this->sell_model->set_select_fields(array('isstar', 'esta','is360'));
        $this->sell_model->set_select_fields(array('isstar','esta','is360','blockid','ownid','infofrom','agentcode','uid','district','blockshowname','mobile','creattime','updatetime','expiretime','price','is_real_house'));
        $before_info = $this->sell_model->find_by_id($house_id);

		//360全景图片
		$imageUrlArr = $this->input->post('imageUrl',true);

		//360全景房源标签规则
		$address = $this->input->post('address', true);
		$remark = $this->input->post('remark');
		$p_sort_arr = $this->input->post('p_sort', true);

		$is360 = 0;
		$imageUrlTotal = 0;
		if(!empty($imageUrlArr))
		{
			$imageUrlTotal = count($imageUrlArr);
		}

		if($imageUrlTotal >= 3 && strlen($address) >= 20 && strlen($remark) >= 60 && !empty($p_sort_arr) && (in_array('0',$p_sort_arr) || in_array('9',$p_sort_arr)) && (in_array('1',$p_sort_arr) || in_array('10',$p_sort_arr)))
		{
			$is360 = 2;
		}
		elseif($imageUrlTotal >= 1)
		{
			$is360 = 1;
		}	

		/**
		 * 记录360状态变化，修改急推标签过期时间。
		 * 非全景房源->全景房源 急推标签过期时间增加7天
		 * 全景房源->非全景房源 急推
         * 标签过期时间减去7天
		 */
		$isTagRelation360Status = '0';
		if($before_info['is360'] <= '1' && $is360 == '2')
		{
			$isTagRelation360Status = '1';
		}
		elseif($before_info['is360'] == '2' && $is360 <= '1')
		{
			$isTagRelation360Status = '2';
		}
		
		/*if($before_info['esta'] == '1' && $before_info['is360'] <= '1' && $is360 == '2')
		{
			$url_manage = $this->sell_model->find_func_url();
			
			//获取经纪人套餐
			$this->load->model('package_model');
			$package = $this->package_model->find_by_id($package_id);
		
			//获取激活房源总数
			$this->load->model('broker_model');
			$valid_house_num = $this->broker_model->valid_house_num();
			
			if($valid_house_num + 1 > $package["package_valid_num"])
			{
				$this->jump($url_manage, "对不起,360全景房源等于两个普通房源,已超过帐号房源库存量上限("
                        . "上限{$package['package_valid_num']},已用$valid_house_num) 
                            请到您的房源管理里删除过期房源!");
                return;
			}
		}*/
		
		//防止模拟提交房源数据 xue 2015-06-16
        //提交验证随机码
		$post_rand = $this->broker_model->get_rand_post();
        $post_value = $this->input->post($post_rand['post_key'], true);

        if($post_rand['post_value']!=$post_value){
		    echo "<script>alert('参数错误！');history.go(-1);</script>";
            exit;		
		}
		
        //冻结房源不允许修改
        if ($before_info['esta'] == 5) 
        {
            echo "<script>alert('冻结房源不允许修改!');history.go(-1);</script>";
            return;
        }
        //二、更新房源信息
        $this->load->helper('common_string_helper');
        //房源参数
        $fields_values = array();
        /*******************基本信息开始***************************/
        $fields_values['infotype'] = intval($this->input->post('infotype', true));
        $allow_infotype = $this->sell_model->get_public_infotype_permission($package_id);
        if (!in_array($fields_values['infotype'], $allow_infotype)) 
        {
            echo "<script>alert('没有权限发布此类型房源，请重新选择');history.go(-1);</script>";
            exit;
        }

        $fields_values['buildingnum'] = $this->input->post('buildingnum', true);
        $fields_values['unitnum'] = $this->input->post('unitnum', true);
        $fields_values['roomnum'] = $this->input->post('roomnum', true);

        /***
        $fields_values['district'] = str_replace('"','',$district);
        $fields_values['streetid'] = $streetid;
        $fields_values['blockid'] = $blockid;
        $fields_values['blockshowname'] = csubstr($this->input->post('blockshowname'), 20);***/
        $fields_values['price'] = $this->input->post('price', true);
        //------放心看房源，价格变动通知相似房源经纪人---- 开始
        if($fields_values['price'] != $before_info['price'] && $before_info['is_real_house'] == 1){
            $url = 'http://newrent.house365.com/server-task/inform-price-change?id='.$house_id;
            $this->curl_get_contents($url);
        }
        //------放心看房源，价格变动通知相似房源经纪人---- 结束 by lk 2018-9-4
        $fields_values['priceterm'] = $this->input->post('priceterm', true);
        $fields_values['taxonlytype'] = $this->input->post('taxonlytype', true);
		$fields_values['is360'] = $is360;
		$fields_values['pricetype'] = $this->input->post('pricetype', true);
        $fields_values['buildarea'] = $this->input->post('buildarea', true) 
                ? $this->input->post('buildarea', true) : 1;
        $fields_values['averprice'] = round(10000 * $fields_values['price'] 
                / $fields_values['buildarea'], 2);
        if (500 > $fields_values['averprice'] || $fields_values['averprice'] > 350000) 
		{
            //echo "<script>alert('当前单价为：" . $fields_values['averprice'] . "元/平米，单价必须在2000-350000元/平米之间');history.go(-1);</script>";

			$this->jump($url_manage, '禁止发布', 3000);
            exit;
        }
        //2017-09-07住宅额外增加面积,单价判断判断
        if($fields_values['infotype'] == 1){
            if(15 > $fields_values['buildarea'] || $fields_values['buildarea'] > 500){
                $this->jump($url_manage, '住宅面积必须在15-500平米之间', 3000);
                exit;
            }
            if(500 > $fields_values['averprice'] || $fields_values['averprice'] > 150000){
                $this->jump($url_manage, '住宅单价必须在500-150000元/平米之间', 3000);
                exit;
            }
        }
        if(3>$fields_values['buildarea'] || $fields_values['buildarea']>150000)
        {
            echo "<script>alert('面积必须在3-150000平米之间');history.go(-1);</script>";
            exit;
        }
		
	    $blockshowname = trim($this->input->post('blockshowname', true));


		if($blockshowname != ''){
			 //住宅类判断价格上下浮动30%  xue modify 2016-03-14
			$this->load->model('block_model');
			$this->block_model->set_select_fields(array('averprice','esta'));//xue modify 2016-03-14
			$block = $this->block_model->find_by_blockname($blockshowname);
            $mright = $this->input->post('mright', true);
			if( !empty($block)){
                //住宅不能发布待审核小区房源
                if( intval($this->input->post('infotype', true)) == 1 && $block['esta'] == 0 ){
                    $this->jump($url_manage, '住宅不能发布待审核小区房源，请重新输入小区！', 3000);
                    exit;
                }
				$block_averprice = $block['averprice'];//xue modify 2016-03-14	
				$block_esta = $block['esta'];//xue modify 2016-03-14	
			}
			$lctype = $this->input->post('lctype', true);
			if($fields_values['infotype']==1&&$block_esta==2&&$mright=='产权房'&&$lctype==1){
				/*$fields_values['price'] = $this->input->post('price', true);
				$fields_values['buildarea'] = $this->input->post('buildarea', true) 
				? $this->input->post('buildarea', true) : 1;

				
				//获取房源均价
				$house_averprice = round(10000 * $fields_values['price'] 
				/ $fields_values['buildarea'], 2);

				$min_averprice = $block_averprice*0.7;
				$max_averprice = $block_averprice*1.3;
               
				if($house_averprice<$min_averprice ){
				   echo "<script>alert('小区价格太离谱了，亲！');history.go(-1);</script>";
				   exit;
				 
				 }*/
			
			}
		}



        //住宅使用权房价格限制
        if ($fields_values['infotype'] == 1 && !empty($block_averprice) && $block_averprice > 0 && $mright=='使用权房')
        {
            $min_averprice = $block_averprice*0.6;
            $max_averprice = $block_averprice*1.6;
            if ($min_averprice > $fields_values['averprice'] || $fields_values['averprice'] > $max_averprice)
            {
                $this->jump($url_manage, '禁止发布', 3000);
                exit;
            }
        }

        //只有物业类型 住宅 别墅 有室、厅等参数
        if ($fields_values['infotype'] == 1 || $fields_values['infotype'] == 2) 
        {
            $fields_values['room'] = $this->input->post('room', true);
            $fields_values['hall'] = $this->input->post('hall', true);
            $fields_values['toilet'] = $this->input->post('toilet', true);
            $fields_values['kitchen'] = $this->input->post('kitchen', true);
            $fields_values['balcony'] = $this->input->post('balcony', true);
        }       
        else
        {
            //其它类型强制设为0
            $fields_values['room'] = '';
            $fields_values['hall'] = '';
            $fields_values['toilet'] = '';
            $fields_values['kitchen'] = '';
            $fields_values['balcony'] = '';
        }
        //物业类型为车库车位没有楼层
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['subfloor'] = '';
            $fields_values['floor'] = '';
            $fields_values['totalfloor'] = '';
            $fields_values['fitment'] = '';
            $fields_values['forward'] = '';
        }
        else
        {
            //楼层判断
            $lctype = $this->input->post('lctype', true);
            if ($lctype == 1) //单层
            { 
                $floor = $this->input->post('floor', true);
                $totalfloor = $this->input->post('totalfloor', true);
                if ($floor > $totalfloor) 
                {
                    //跳转页面
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = 0;
                $fields_values['floor'] = $floor;
                $fields_values['totalfloor'] = $totalfloor;
            }   
            if ($lctype == 2) //跃层
            { 
                $subfloor = $this->input->post('subfloor', true);
                $floor2 = $this->input->post('floor2', true);
                $totalfloor2 = $this->input->post('totalfloor2', true);
                if ($subfloor > $totalfloor2 || $floor2 > $totalfloor2) 
                {
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = $subfloor;
                $fields_values['floor'] = $floor2;
                $fields_values['totalfloor'] = $totalfloor2;
            }
            $fields_values['fitment'] = $this->input->post('fitment', true);
            $fields_values['forward'] = $this->input->post('forward', true);
        }


		//2016-2-25 zhou添加限制重复房源发布 -------- start ------------>
		
		$blockid =$_POST['block_id'];
		$this->load->model('block_model');

		$block_remove_limit_num = $this->block_model->get_block_remove_info_by_blockid($blockid);
		if($block_remove_limit_num)
		{
			$publish_limit_num =$block_remove_limit_num;
		}
		else
		{
			$publish_limit_num =30;
		}

		$price_start		=$fields_values['price']*0.95;
		$price_end  		=$fields_values['price']*1.05;

		$buildarea_start  =$fields_values['buildarea']-0.5;
		$buildarea_end    =$fields_values['buildarea']+0.5;
		$room		=$fields_values['room'];
		$hall		=$fields_values['hall'];
		$toilet		=$fields_values['toilet'];

		$subfloor	=$fields_values['subfloor'];
		$floor		=$fields_values['floor'];
		$totalfloor	=$fields_values['totalfloor'];

		

		//查询房源条件
        $cond_where = "uid = '".$uid."' AND esta = 1  AND infofrom = '5' and blockid ='$blockid' and subfloor='$subfloor'  and floor='$floor' and totalfloor='$totalfloor' and room='$room' and hall='$hall' and toilet='$toilet' and buildarea > '$buildarea_start' and buildarea < '$buildarea_end' and price> '$price_start' and price < '$price_end' and id != $house_id  ";

		//echo $cond_where;die;
		

        //符合条件的总行数
        $broker_publish_total_count = $this->sell_model->find_count_by($cond_where,'0');
		
		if($broker_publish_total_count>=$publish_limit_num)
		{

			$this->sell_model->set_select_fields(array('id','isstar', 'esta'));
			$broker_publish_data_info = $this->sell_model->find_all_by($cond_where);
			
			if(count($broker_publish_data_info)>$publish_limit_num)
			{
				$show_limit_num =$publish_limit_num;
			
			}
			else
			{
				$show_limit_num =count($broker_publish_data_info);
			}
			
			$str_show ="";
			for($i =0;$i<$show_limit_num;$i++)
			{
				$str_show .=$broker_publish_data_info[$i]['id'].',';
			}

			$str_show =rtrim($str_show,',');
			echo "<script>alert('此房源与房源编号 " . $str_show 
                    . "重复，禁止发布更多重复房源！');history.go(-1);</script>";
            exit;
		
		}


		//2016-2-25 zhou添加限制重复房源发布 -------- end ------------>


        $fields_values['mright'] = $this->input->post('mright', true);
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['buildyear'] = $this->input->post('buildyear1', true);
        } 
        else
        {
            $fields_values['buildyear'] = $this->input->post('buildyear', true);
        }

        $fields_values['contactor'] = $this->user_arr['truename'];
        $fields_values['telno'] = $session_info['telno'];
        $fields_values['ip'] = get_ip();


        $real_house_set =$this->input->post('real_house_set', true);
	    $infotype = $fields_values['infotype'];
        if(!in_array($infotype,array(1,2))){
	        $real_house_set = 0;
        }

        if($real_house_set>0)
        {
	        $this->load->model('real_house_model');
            $realnum_limit =$this->broker_model->get_realnum_by_packageid($package_id);
            $realHouseNum= $this->real_house_model->getUidRealHouseNumExceptId($uid,$house_id);
            if($realHouseNum>=$realnum_limit)
            {
                echo "<script>alert('放心看标签数量已达上限，请先取消已勾选标签或升级您的套餐'); history.go(-1);</script>";
                exit;
                //$this->jump($url_manage, '真房源标签数量已达上限，请先取消已勾选标签或升级您的套餐', 3000);
                //exit;
            }
        }
        $this->load->model('real_house_model');

        //$fields_values['is_real_house'] = $real_house_set;
        $isRealHouse =$this->real_house_model->getInfoByRowid($house_id);
        $isRealHouseNew =$this->real_house_model->get_real_house_sell_info($house_id);
        //print_r($isRealHouseNew[0]['is_real_house']);die;
        //操作原因

	    $this->load->model('zsb_api_model');
        if(($isRealHouseNew[0]['is_real_house']==0) && $real_house_set==1) {

	        $this->zsb_api_model->getRequrstData('setRealHouse',array('house_id'=>$house_id));
        }elseif(($isRealHouseNew[0]['is_real_house']==1) && $real_house_set==0)
        {
	        $this->zsb_api_model->getRequrstData('cancleRealHouse',array('house_id'=>$house_id));
        }

        $fields_values['buildingnum']   =$this->input->post('buildingnum', true);
        $fields_values['unitnum']       =$this->input->post('unitnum', true);
        $fields_values['roomnum']       =$this->input->post('roomnum', true);


        /*******************基本信息结束***************************/
        
        /*******************补充信息开始***************************/
        if ($fields_values['infotype'] == 2) 
        {
            $housekind = $this->input->post('housekind', true);
        } 
        else if ($fields_values['infotype'] == 6)
        {
            $housekind = $this->input->post('housekindname', true);
        }
        if (isset($housekind) && $housekind != '')
        {
            //物业类型 厂房车库代表车位属性
            //物业类型 物业类型代表别墅类型
            $fields_values['housekind'] = $housekind;
        }
        //商业分类
        $tradeclass = $this->input->post('tradeclass', true);
        if (isset($tradeclass) && $tradeclass != '')
        {
            $fields_values['tradeclass'] = $tradeclass;
        }
        //商铺分类
        $housekind = $this->input->post('housekind', true);
        if (isset($housekind) && $housekind != '')
        {
            $fields_values['housekind'] = $housekind;
        }
        //物业费
        $fee = $this->input->post('fee', true);
        if (isset($fee) && $fee != '')
        {
            $fields_values['strata_fee'] = $fee;
        }

        //基础设施
        $baseservice = $this->input->post('baseservice', true);
        if ($baseservice)
        {
            $fields_values['baseservice'] = implode(",", $baseservice);
        }
        $fields_values['ownid'] = trim($this->input->post('ownid', true));
        /*******************补充信息结束***************************/
        
        /*******************详细信息开始***************************/
        $fields_values['address'] = htmlspecialchars(csubstr(trim(
                filterSpace($this->input->post('address', true))),60));

		//敏感词过滤
		if(!empty($fields_values['address']))
		{
			$this->load->model('ajax_model');
			$sensitive_word = $this->ajax_model->check_sensitive_word($fields_values['address']);
			
			if(!empty($sensitive_word))
			{
				echo "<script>alert('含有敏感词：".$fields_values['address']."');history.go(-1);</script>";
                return;
			}
		}

        //$fields_values['remark'] = $this->input->post('remark');
		$fields_values['remark'] = check_word($this->input->post('remark'),STATIC_BADWORD_URL);

        //房源特色
        $fields_values['feature'] = '';
        $feature = $this->input->post('feature', true);
        if(is_array($feature) && !empty($feature))
        {
            $this->load->model('house_feature');
            $feature_arr = $this->house_feature->find_feature($tbl, $fields_values['infotype']);
            foreach($feature as $val)
            {	
                $val = intval($val);
                if($feature_arr[$val] != '')
                {
                    $fields_values['feature'] .= '$'.$val;
                }
            }
            if($fields_values['feature'] != '')
            {
                $fields_values['feature'] .= '$';
            }
        }
		
		//室内,外景,户型图数据集合
		$pfile_name = $this->input->post('p_filename', true);

        //房源封面图
        $pic1 = $this->input->post('pic1', true);

        /*逻辑错误
		if($pic1 == '')
        {
            $pic1 = '';
        }
        else
        {
            $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
        }*/

		if(!empty($pic1))
        {
            $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
        }
		elseif(!empty($pfile_name))
		{
			$pic1 = reset($pfile_name);
			
			$pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
			
		}
		elseif(!empty($imageUrlArr))
		{
			$pic1 = reset($imageUrlArr);

			$pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
		}else {
            // 封面 房源 360 都不存在图片 获取小区封面图 如果不存在封面图则房源封面图为空
            //查找小区的封面图
            $this->block_model->set_select_fields(array('b_img'));
            $block = $this->block_model->find_by_id($blockid);
            $pic1 = (isset($block['b_img']) && $block['b_img']) ? $block['b_img'] : '';
        }

		//加载业务模块
		$this->load->model('pic_model');
		$houseRelationPicInfo = $this->pic_model->get_house_pic('1',$house_id);

		//图片标题
		$imageTitle = $this->input->post('imageTitle',true);

		//图片类型
		$imageType = $this->input->post('imageType',true);
		
		//需要删除的图片ID
		$delPicIdArr = array();

		$houseRelationPicData = array();
		if(!empty($houseRelationPicInfo))
		{
			foreach($houseRelationPicInfo as $key => $item)
			{
				$houseRelationPicData[$item['id']] = $item;
				
				if((!empty($imageUrlArr) && !isset($imageUrlArr[$item['id']])) || empty($imageUrlArr))
				{
					$delPicIdArr[$item['id']] = $item['id'];
				}
			}
		}
		
		//加载审核图片类
		$this->load->model('admin_check');

		//获取360全景封面审核图片
		//$piCheckInfo = $this->admin_check->get_360_pic_check('1',$house_id);

		//获取360全景审核图片
		$piCheckInfo = $this->admin_check->get_all_360_pic_check('1',$house_id);

		$piCheckData = array();
		if(!empty($piCheckInfo))
		{
			foreach($piCheckInfo as $key => $item)
			{
				$piCheckData[$item['picid']] = $item;
			}
		}

		//删除图片
		if(!empty($delPicIdArr))
		{
			//删除360全景图片库存
			$this->pic_model->del_house_some_pic($delPicIdArr);
			
			//删除360全景图片审核
			foreach($delPicIdArr as $key => $value)
			{
				if(isset($piCheckData[$value]))
				{
					$this->admin_check->delete_360_check_pic($piCheckData[$value]['id']);
				}
			}

			/*if(!empty($piCheckInfo) && in_array($piCheckInfo['picid'],$delPicIdArr))
			{
				$this->admin_check_wang->delete_360_check_pic($piCheckInfo['id']);
				
				$piCheckInfo = array();
			}*/
		}
		
		//新增图片或修改图片
		$imageUrlData = array();
		if(!empty($imageUrlArr))
		{
			$numFlag = 0;
			$addPicData = array();
			$editPicData = array();
			foreach($imageUrlArr as $key => $value)
			{
				$numFlag++;

				if(isset($houseRelationPicData[$key]))
				{
					$imageUrlData[$houseRelationPicData[$key]['id']] = array(
						'action' => 'edit',
						'filename' => $houseRelationPicData[$key]['filename'],
						'roomtype' => $imageType[$key],
						'flg' => $houseRelationPicData[$key]['flg']
					);

					if($houseRelationPicData[$key]['position'] != $numFlag || $houseRelationPicData[$key]['title'] != $imageTitle[$key] || $houseRelationPicData[$key]['roomtype'] != $imageType[$key])
					{
						$editPicData[$key] = array(
							'id' => $key,
							'position' => $numFlag,
							'filename' => preg_match("/\?/", $value) ? substr($value, 0, strpos($value, '?')) : $value,
							'title' => $imageTitle[$key],
							'roomtype' => $imageType[$key]
						);
					}
				}
				else
				{
					$addPicData[$key] = array(
						'tbl' => '1',
						'rowid' => $house_id,
						'position' => $numFlag,
						'filename' => preg_match("/\?/", $value) ? substr($value, 0, strpos($value, '?')) : $value,
						'title' => $imageTitle[$key],
						'sort' => '0',
						'createtime' => time(),
						'flg' => '0',
						'isfrom' => '2',
						'isinfotype' => $fields_values['infotype'],
						'roomtype' => $imageType[$key]
					);
				}
			}	
		
			//添加全景图片
			if(!empty($addPicData))
			{
				foreach($addPicData as $key => $item)
				{
					$picId = $this->pic_model->insert_house_panorama_pic($item);

					/*$imageUrlData[$picId] = array(
						'action' => 'add',
						'filename' => $item['filename'],
						'roomtype' => $item['roomtype'],
						'flg' => '0'
					);*/
					
					$surface = '0';
					if($pic1 == $item['filename'])
					{
						$surface = '1';
					}

					$addAdmin360PiCheckData = array(
						'uid' => $uid,
						'housetbl' => '1',
						'houseid' => $house_id,
						'fitment' => '0',
						'infotype' => $fields_values['infotype'],
						'pictbl' => 'upload360',
						'picid' => $picId,
						'picurl' => $item['filename'],
						'sort' => '0',
						'roomtype' => $item['roomtype'],
						'surface' => $surface,
						'dateline' => time(),
						'file_md5' => ''
					);
					
					$this->admin_check->insert_360_check_pic($addAdmin360PiCheckData);
				}
			}

			//编辑全景图片
			if(!empty($editPicData))
			{
				foreach($editPicData as $key => $item)
				{
					$this->pic_model->update_house_panorama_pic($item);
				}
			}
		}

        //四、处理房源图片
        $pics = array();
        if (isset($pfile_name) && $pfile_name != '') 
        {
            $pics = array(
                'p_filename' => $pfile_name,
                'p_sort' => $this->input->post('p_sort', true),
                'p_title' => $this->input->post('p_title', true),
                'infotype' => $fields_values['infotype']
            );
            $pic_check = $this->sell_model->insert_house_pic($pics,
                    $tbl, $house_id, $pic1, $this->input->post('block_id', true), 1);
            $pic_check_arr = $pic_check['pic_check'];
            //更新封面图
            $fields_values['pic1'] = $pic_check['indexpic'];
        }
		else
		{
			$this->pic_model->del_house_pic_by($tbl, $house_id);
		}

		//兼容360全景封面图片
		$fields_values['pic1'] = $pic1;

		//目前房源发布规则，只支持住宅类型房源
		if($fields_values['infotype'] == 1 && $fields_values['mright'] == '产权房')
		{

            $fields_values['id'] =  $house_id;
			//$fields_values['blockid'] = $this->input->post('block_id', true);
			$fields_values['blockshowname'] = $this->input->post('blockshowname', true);

			//检查房源发布规则

			$resultHousePublishRule = $this->checkHousePublishRule($fields_values);

			if($resultHousePublishRule['system_intercept_status'])
			{
				$fields_values['esta'] = '51';
                $fields_values['is_real_house']=0;
			}
		}

        //更新房源信息
        //update sell set esta = 5 where id in(33899521, 37700775) and uid = 10000040;
        $affected_rows = $this->sell_model->update($fields_values, $house_id, $uid);

		//添加房源发布价格日志信息
        $this->load->model('house_publish_rule_log_model');
        $housePublishRuleLogData = $this->house_publish_rule_log_model->getRow($house_id,1,3,$uid);

        if(!empty($resultHousePublishRule['suspected_sham_status2']))
        {
            if (empty($housePublishRuleLogData))
            {
                $addData = array('type' => 3, 'uid' => $uid, 'houseId' => $house_id, 'houseType' => '1', 'addTime' => time());
                $this->house_publish_rule_log_model->add($addData);
            }
        }
        elseif(!empty($housePublishRuleLogData))
        {
            $this->house_publish_rule_log_model->delete($housePublishRuleLogData['id']);
        }

        //设置多图、标签、real房
        $fields_values['id'] = $house_id;
        $fields_values['uid'] =  $this->user_arr['uid'];
		
        if ($affected_rows > 0)
        {
			
            //判断房源价格是否在预警价格区间，仅对住宅类做判断
    		if ($before_info['blockid'] && $fields_values['infotype']==1){
    		    $_sell = $fields_values;
    		    $_sell['id']            = $house_id;
    		    $_sell['blockid']       = $before_info['blockid'];
    		    $_sell['ownid']         = $before_info['ownid'];
    		    $_sell['infofrom']      = $before_info['infofrom'];
    		    $_sell['agentcode']     = $before_info['agentcode'];
    		    $_sell['uid']           = $before_info['uid'];
    		    $_sell['district']      = $before_info['district'];
    		    $_sell['blockshowname'] = $before_info['blockshowname'];
    		    $_sell['mobile']        = $before_info['mobile'];
    		    $_sell['creattime']     = $before_info['creattime'];
    		    $_sell['updatetime']    = $before_info['updatetime'];
    		    $_sell['expiretime']    = $before_info['expiretime'];
                //$check_rs = bm('sellwarning')->checkSellPrice($_sell,'nj');
				//$IpHostAllow =explode('.',GetIp());
				//print_r($_sell);die;
				$check_rs = bm('sellwarning')->checkSellPriceNew($_sell,GB_CITY,$resultHousePublishRule['suspected_sham_status']);
				
				
    		}
    		
            /***
            $this->load->model('admin_check');
            $delpic = $this->input->post('delpic', true);
            //把删除的图片从审核库中删除
            if($delpic != '')
            {
                $delpicarr = explode(",", $delpic);
                if(is_array($delpicarr) && !empty($delpicarr))
                {
                    foreach($delpicarr as $val)
                    {
                        $val = intval($val);
                        if($val)
                        {
                            //貌似不太好判断入了哪个库，一起删除吧
                            $this->admin_check->delete_check_pic($tbl, $house_id, $val);
                            $this->admin_check->delete_check_pic_sub($tbl, $house_id, $val);
                        }
                    }
                }
            }***/
            $nowtime = time();
            //审核图片入库

            if(isset($pic_check_arr) && is_array($pic_check_arr) 
                    && !empty($pic_check_arr) && $uid > 0)
            {
                $this->load->model('admin_check');
                $this->admin_check->delete_check_pic_all($tbl, $house_id);
                foreach($pic_check_arr as $key => $val)
                {
                    $infotype = $fields_values['infotype'];
                    $fitment = $fields_values['fitment'];
                    $pic_check_arr[$key]['uid'] = $uid;
                    $pic_check_arr[$key]['housetbl'] = $tbl;
                    $pic_check_arr[$key]['houseid'] = $house_id;
                    $pic_check_arr[$key]['fitment'] = $fitment == "简装" ? 2 : ($fitment == "毛坯" ? 3 : 1);
                    $pic_check_arr[$key]['infotype'] = $infotype == 3 ? 4 : ($infotype == 4 ? 3 : $infotype);//商铺、写字楼互换
                    $pic_check_arr[$key]['dateline'] = $nowtime;
                    //进入审核附属表待夜间JOB过滤入库
                    $this->admin_check->insert_check_pic_sub($pic_check_arr[$key]);
                    //来自设备的图片只入待审核库、不入审核库
                    if($pic_check_arr[$key]['surface'] == 0 && $pic_check_arr[$key]['from_device'] == 1)
                    {
                        unset($pic_check_arr[$key]);
                    }
                    unset($pic_check_arr[$key]['from_device']);
                    //封面图入审核表
                    $functionSwitch = $this->config->item('functionSwitch');
                    if(!empty($functionSwitch['commonImageJoinCheck']) || $pic_check_arr[$key]['surface'] == 1)
                    {
                        $this->admin_check->insert_check_pic($pic_check_arr[$key]);
                    }
                }
            }
            //判断优质，多图 先有多图再有优质
            $this->load->model('sell_star_model');
            $this->sell_star_model->set_houseinfo($fields_values);
            $is_star_house = $this->sell_star_model->check_star_standard();

            $growthMessage = '';
            if ($is_star_house || $is360 == '2')
            {
                if ($before_info['isstar'] != 3) {
                    //房源标签的级别
                    $gradeLog = $before_info['isstar'] == 3 ? 2 : 1;
                    $ghl  = new GrowthHouseLog();
                    $houseGradeLog = $ghl->findHouseGradeLog($house_id, $tbl, $gradeLog, $uid);
                    if ($houseGradeLog['grade'] == 1)
                    {
                        $gbe  = new GrowthBrokerExp(array('id' => $uid, 'groupid' => $package_id));			
                        $gewp = new GrowthExpWayPackage();
                        $exp = $gewp->findScoreByWayAliasAndPackageId('pStarHouse', $package_id);					 
                        $inExpStatus = $gbe->increase('pStarHouse','发布多图房源',$exp);
                        $ghl->updateHouseGradeLog($house_id, $tbl, 2, $uid);
                        if($inExpStatus['status'] == 2 ){
                            //$growthMessage = "您今天的成长值已达峰值！";
                        } elseif($inExpStatus['status'] == 1){
                            //$growthMessage = "成长值+" . $exp;
                        }
                    }
					$growthMessage="";
                    //判断原来是否为图
                    if ($before_info['isstar'] != 3)
                    {
                        $this->sell_star_model->set_star();
                    }
                }

				//处理急推标签是否修改时间
				if(!empty($isTagRelation360Status))
				{
					//获取房源急推数据
					$this->load->model('sell_tag_model');
					$house_tag_info = $this->sell_tag_model->get_house_tag(array('houseId' => $house_id,'tbl' => 'sell','esta' => '1'));

					/*if(!empty($house_tag_info))
					{
						$expiretime = $house_tag_info['expiretime'];
						
						if($isTagRelation360Status == '1')
						{
							$expiretime += 604800;
						}
						elseif($isTagRelation360Status == '2')
						{
							$expiretime -= 604800;
						}
						
						//编辑房源急推数据
						$this->sell_tag_model->edit_tag_expiretime(array('id' => $house_tag_info['id'],'expiretime'  => $expiretime));
					}*/
				}
            } 
            else 
            {
                //设置房源属性为非多图房源
                $this->sell_star_model->remove_star(); 
                $this->load->model('sell_tag_model');
                $this->sell_tag_model->set_houseinfo($fields_values);
                //2011-11-30 同步设置标签失效
                //2018-5-21 增加操作标签原因：编辑房源后不满足多图条件
				$this->sell_tag_model->remove_tag(5);
                //取消REAL房
              /*  $this->load->model('sell_real_model');
                $this->sell_real_model->set_houseinfo($fields_values);
                $this->sell_real_model->remove_real();*/
                //取消新房直售
                $this->load->model('sell_nofee_model');
                $this->sell_nofee_model->set_houseinfo($fields_values);
                $this->sell_nofee_model->remove_nofee();
            }
            $page_text = '房源修改成功!' . $growthMessage;
            //房源冻结后的提醒信息
            //if ($check_rs=='freeze house'){

	        if($fields_values['infotype'] == 1 && $resultHousePublishRule['system_intercept_status'])
			{
                $page_text = '您发布的房源严重低于市场价格，已被系统自动拦截，如您需要继续发布，可在租售宝后台“系统拦截”中进行申诉，如果该房源被查出虚假，账号会被降1星。';
				//=====20160819去更改申诉表里的申诉状态，result置为0（带审核）

				$sell_appeal = DAO::instance('sell_appeal','esfpublic','sell_appeal','id');

				//$sell_appeal->edit();
				//$sql = "update esfpublic.sell_appeal set result=0 where city='nj' and id='".$house_id."'";
				//记录删除日志
				$query_struct = array(
					'where' => array(
						'city' => 'nj',
						'id'   => $house_id
					),
				);

				$appeal_info = $sell_appeal->get($query_struct);
				//print_r($appeal_info);die;
				//存log日志
				if($appeal_info['result']==10 || $appeal_info['result']==20){
				//物理删除，防止再次拦截无法申诉(只删除已审核过的房源)
					//$sql = "delete from sell_appeal where city='nj' and id='".$house_id;
					//echo $sql;die;
					//result=1表示再次进入拦截
					$sql = "update esfpublic.sell_appeal set result=1 where city='nj' and id='".$house_id."'";
					$sell_appeal->_db()->save($sql);//die('over');
				}
			//=====20160819去更改申诉表里的申诉状态，result置为0（带审核）
				
				$this->jump('/sell/manage/sysfrozen/', $page_text, 3000);
				exit;
            }
        }
        else 
        {
            $page_text = '房源修改成功!!!';
        }

        // Owner
        if ($this->config->item('isOwnerCheck')) {
            $this->load->model('Owner');
            $owner = new Owner();
            $contractType = $owner->getContractType();
            $ownerData = array();
            $ownerData['land_right_number'] = isset($_POST['owner_land_right_number']) ? $_POST['owner_land_right_number'] : '';
            $ownerData['contract_type'] = isset($_POST['owner_contract_type']) ? $_POST['owner_contract_type'] : '';
            foreach ($contractType as $key => $value) {
                if ($value == $ownerData['contract_type']) {
                    $ownerData['contract_type'] = $key;
                    break;
                }
            }
            $ownerData['contract_number'] = isset($_POST['owner_contract_number']) ? $_POST['owner_contract_number'] : '';
            $ownerData['name'] = isset($_POST['owner_name']) ? $_POST['owner_name'] : '';
            $ownerData['phone'] = isset($_POST['owner_phone']) ? $_POST['owner_phone'] : '';
            $ownerData['identity_card_number'] = isset($_POST['owner_identity_card_number']) ? $_POST['owner_identity_card_number'] : '';
            $ownerDataHouse = array();
            $ownerDataHouse['id'] = $house_id;
            $ownerDataHouse['district'] = $fields_values['district'];
            $ownerDataHouse['area'] = $fields_values['buildarea'];
            $ownerData['house'] = $ownerDataHouse;
            //print_r($ownerData);die;
            $owner->updateSell($ownerData);

            $this->load->model('real_house_model');
            $this->real_house_model->insertCreditImage(1,$house_id);
            //添加房产证图片
            if(!empty($_POST['p_filename_real'])) {


                $realHouseMoney = $this->real_house_model->insertCreditImage(1,$house_id,$_POST['p_filename_real']);
                $this->real_house_model->updateSocreNum($house_id,10);
            }else{

                $this->load->model('real_house_model');
                $this->real_house_model->updateSocreNum($house_id,0);
            }
        }

        //跳转到之前修改的页面
        $tab = $this->input->post('tab', true);
        $this->jump($this->sell_model->find_func_url() . $tab, $page_text, 3000);
    }

	   /**
     * 更新失效房源 model
     */
    public function updatedisable()
    {
        //一、获取经纪人UID
		$this->load->model('broker_model');
		$session_info = $this->broker_model->get_user_session();	
        $uid = $this->user_arr['uid'];
        $tbl = $this->sell_model->get_tbl();
        $package_id = $this->user_arr['package_id'];
        $house_id = $this->input->post('id', true);
        //查询房源没修改之前的信息
        $this->sell_model->set_select_fields(array('isstar', 'esta','is360','blockid'));
        $before_info = $this->sell_model->find_by_id($house_id);
        $url_manage = $this->sell_model->find_func_url();
		//360全景图片
		$imageUrlArr = $this->input->post('imageUrl',true);

		//360全景房源标签规则
		$address = $this->input->post('address', true);
		$remark = $this->input->post('remark');
		$p_sort_arr = $this->input->post('p_sort', true);

		$is360 = 0;
		$imageUrlTotal = 0;
		if(!empty($imageUrlArr))
		{
			$imageUrlTotal = count($imageUrlArr);
		}

		if($imageUrlTotal >= 3 && strlen($address) >= 20 && strlen($remark) >= 60 && !empty($p_sort_arr) && (in_array('0',$p_sort_arr) || in_array('9',$p_sort_arr)) && (in_array('1',$p_sort_arr) || in_array('10',$p_sort_arr)))
		{
			$is360 = 2;
		}
		elseif($imageUrlTotal >= 1)
		{
			$is360 = 1;
		}	
		
		if($before_info['is360'] <= '1' && $is360 == '2')
		{
			$url_manage = $this->sell_model->find_func_url();
			
			//获取经纪人套餐
			$this->load->model('package_model');
			$package = $this->package_model->find_by_id($package_id);
		
			//获取激活房源总数
			$this->load->model('broker_model');
			$valid_house_num = $this->broker_model->valid_house_num();
			
			if($valid_house_num + 1 > $package["package_valid_num"])
			{
				$this->jump($url_manage, "对不起,360全景房源等于两个普通房源,已超过帐号房源库存量上限("
                        . "上限{$package['package_valid_num']},已用$valid_house_num) 
                            请到您的房源管理里删除过期房源!");
                return;
			}
		}

		//防止模拟提交房源数据 xue 2015-06-16
        //提交验证随机码
		$post_rand = $this->broker_model->get_rand_post();
        $post_value = $this->input->post($post_rand['post_key'], true);

        if($post_rand['post_value']!=$post_value){
		    echo "<script>alert('参数错误！');history.go(-1);</script>";
                exit;		
		}

        //冻结房源不允许修改
        if ($before_info['esta'] == 5) 
        {
            echo "<script>alert('冻结房源不允许修改!');history.go(-1);</script>";
            return;
        }
        //二、更新房源信息
        $this->load->helper('common_string_helper');
        //房源参数
        $fields_values = array();
        /*******************基本信息开始***************************/
        $fields_values['infotype'] = intval($this->input->post('infotype', true));
        $allow_infotype = $this->sell_model->get_public_infotype_permission($package_id);
        if (!in_array($fields_values['infotype'], $allow_infotype)) 
        {
            echo "<script>alert('没有权限发布此类型房源，请重新选择');history.go(-1);</script>";
            exit;
        }
        /***
        $fields_values['district'] = str_replace('"','',$district);
        $fields_values['streetid'] = $streetid;
        $fields_values['blockid'] = $blockid;
        $fields_values['blockshowname'] = csubstr($this->input->post('blockshowname'), 20);***/
        $fields_values['price'] = $this->input->post('price', true);
        $fields_values['priceterm'] = $this->input->post('priceterm', true);
        $fields_values['taxonlytype'] = $this->input->post('taxonlytype', true);
		$fields_values['is360'] = $is360;
		$fields_values['pricetype'] = $this->input->post('pricetype', true);
        $fields_values['buildarea'] = $this->input->post('buildarea', true) 
                ? $this->input->post('buildarea', true) : 1;
        if(3>$fields_values['buildarea'] || $fields_values['buildarea']>150000)
        {
            echo "<script>alert('面积必须在3-150000平米之间');history.go(-1);</script>";
            exit;
        }
        $fields_values['averprice'] = round(10000 * $fields_values['price'] 
                / $fields_values['buildarea'], 2);
        if (500 > $fields_values['averprice'] || $fields_values['averprice'] > 350000) {
            //echo "<script>alert('当前单价为：" . $fields_values['averprice'] . "元/平米，单价必须在2000-300000元/平米之间');history.go(-1);</script>";


            $this->jump($url_manage, '禁止发布', 3000);
            exit;
        }

        $blockshowname = trim($this->input->post('blockshowname', true));


        if($blockshowname != ''){
            //住宅类判断价格上下浮动30%  xue modify 2016-03-14
            $this->load->model('block_model');
            $this->block_model->set_select_fields(array('averprice','esta'));//xue modify 2016-03-14
            $block = $this->block_model->find_by_blockname($blockshowname);
            $mright = $this->input->post('mright', true);
            if( !empty($block)){
                //住宅不能发布待审核小区房源
                if( intval($this->input->post('infotype', true)) == 1 && $block['esta'] == 0){
                    $this->jump($url_manage, '住宅不能发布待审核小区房源，请重新输入小区！', 3000);
                    exit;
                }
                $block_averprice = $block['averprice'];//xue modify 2016-03-14
                $block_esta = $block['esta'];//xue modify 2016-03-14
            }
            $lctype = $this->input->post('lctype', true);
            if($fields_values['infotype']==1&&$block_esta==2&&$mright=='产权房'&&$lctype==1){
                /*$fields_values['price'] = $this->input->post('price', true);
                $fields_values['buildarea'] = $this->input->post('buildarea', true)
                ? $this->input->post('buildarea', true) : 1;


                //获取房源均价
                $house_averprice = round(10000 * $fields_values['price']
                / $fields_values['buildarea'], 2);

                $min_averprice = $block_averprice*0.7;
                $max_averprice = $block_averprice*1.3;

                if($house_averprice<$min_averprice ){
                   echo "<script>alert('小区价格太离谱了，亲！');history.go(-1);</script>";
                   exit;

                 }*/

            }
        }
        //2017-09-07住宅额外增加面积,单价判断判断
        if($fields_values['infotype'] == 1){
            if(15 > $fields_values['buildarea'] || $fields_values['buildarea'] > 500){
                $this->jump($url_manage, '住宅面积必须在15-500平米之间', 3000);
                exit;
            }
            if(500 > $fields_values['averprice'] || $fields_values['averprice'] > 150000){
                $this->jump($url_manage, '住宅单价必须在500-150000元/平米之间', 3000);
                exit;
            }
        }

        //住宅使用权房价格限制
        $mright = $this->input->post('mright', true);
        if ($fields_values['infotype'] == 1 && !empty($block_averprice) && $block_averprice > 0 && $mright=='使用权房')
        {
            $min_averprice = $block_averprice*0.6;
            $max_averprice = $block_averprice*1.6;
            if ($min_averprice > $fields_values['averprice'] || $fields_values['averprice'] > $max_averprice)
            {
                $this->jump($url_manage, '禁止发布', 3000);
                exit;
            }
        }
        //只有物业类型 住宅 别墅 有室、厅等参数
        if ($fields_values['infotype'] == 1 || $fields_values['infotype'] == 2) 
        {
            $fields_values['room'] = $this->input->post('room', true);
            $fields_values['hall'] = $this->input->post('hall', true);
            $fields_values['toilet'] = $this->input->post('toilet', true);
            $fields_values['kitchen'] = $this->input->post('kitchen', true);
            $fields_values['balcony'] = $this->input->post('balcony', true);
        }       
        else
        {
            //其它类型强制设为0
            $fields_values['room'] = '';
            $fields_values['hall'] = '';
            $fields_values['toilet'] = '';
            $fields_values['kitchen'] = '';
            $fields_values['balcony'] = '';
        }
        //物业类型为车库车位没有楼层
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['subfloor'] = '';
            $fields_values['floor'] = '';
            $fields_values['totalfloor'] = '';
            $fields_values['fitment'] = '';
            $fields_values['forward'] = '';
        }
        else
        {
            //楼层判断
            $lctype = $this->input->post('lctype', true);
            if ($lctype == 1) //单层
            { 
                $floor = $this->input->post('floor', true);
                $totalfloor = $this->input->post('totalfloor', true);
                if ($floor > $totalfloor) 
                {
                    //跳转页面
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = 0;
                $fields_values['floor'] = $floor;
                $fields_values['totalfloor'] = $totalfloor;
            }   
            if ($lctype == 2) //跃层
            { 
                $subfloor = $this->input->post('subfloor', true);
                $floor2 = $this->input->post('floor2', true);
                $totalfloor2 = $this->input->post('totalfloor2', true);
                if ($subfloor > $totalfloor2 || $floor2 > $totalfloor2) 
                {
                    echo "<script>alert('总楼层不能小于当前楼层!');history.go(-1);</script>";
                    return;
                }
                $fields_values['subfloor'] = $subfloor;
                $fields_values['floor'] = $floor2;
                $fields_values['totalfloor'] = $totalfloor2;
            }
            $fields_values['fitment'] = $this->input->post('fitment', true);
            $fields_values['forward'] = $this->input->post('forward', true);
        }
        $fields_values['mright'] = $this->input->post('mright', true);
        if ($fields_values['infotype'] == 6)
        {
            $fields_values['buildyear'] = $this->input->post('buildyear1', true);
        } 
        else
        {
            $fields_values['buildyear'] = $this->input->post('buildyear', true);
        }
        $fields_values['contactor'] = $this->user_arr['truename'];
        $fields_values['telno'] = $session_info['telno'];
        $fields_values['ip'] = get_ip();

		$fields_values['esta'] = 2;
        /*******************基本信息结束***************************/
        
        /*******************补充信息开始***************************/
        if ($fields_values['infotype'] == 2) 
        {
            $housekind = $this->input->post('housekind', true);
        } 
        else if ($fields_values['infotype'] == 6)
        {
            $housekind = $this->input->post('housekindname', true);
        }
        if (isset($housekind) && $housekind != '')
        {
            //物业类型 厂房车库代表车位属性
            //物业类型 物业类型代表别墅类型
            $fields_values['housekind'] = $housekind;
        }
        //商业分类
        $tradeclass = $this->input->post('tradeclass', true);
        if (isset($tradeclass) && $tradeclass != '')
        {
            $fields_values['tradeclass'] = $tradeclass;
        }
        //商铺分类
        $housekind = $this->input->post('housekind', true);
        if (isset($housekind) && $housekind != '')
        {
            $fields_values['housekind'] = $housekind;
        }
        //物业费
        $fee = $this->input->post('fee', true);
        if (isset($fee) && $fee != '')
        {
            $fields_values['strata_fee'] = $fee;
        }
        //基础设施
        $baseservice = $this->input->post('baseservice', true);
        if ($baseservice)
        {
            $fields_values['baseservice'] = implode(",", $baseservice);
        }
        $fields_values['ownid'] = trim($this->input->post('ownid', true));
        /*******************补充信息结束***************************/
        
        /*******************详细信息开始***************************/
        $fields_values['address'] = htmlspecialchars(csubstr(trim(
                filterSpace($this->input->post('address', true))),60));

		//敏感词过滤
		if(!empty($fields_values['address']))
		{
			$this->load->model('ajax_model');
			$sensitive_word = $this->ajax_model->check_sensitive_word($fields_values['address']);
			
			if(!empty($sensitive_word))
			{
				echo "<script>alert('含有敏感词：".$fields_values['address']."');history.go(-1);</script>";
                return;
			}
		}

        //$fields_values['remark'] = $this->input->post('remark');
		$fields_values['remark'] = check_word($this->input->post('remark'),STATIC_BADWORD_URL);

        //房源特色
        $fields_values['feature'] = '';
        $fields_values['is_real_house'] = '0';

        $this->load->model('real_house_model');
        $isRealHouse =$this->real_house_model->getInfoByRowid($house_id);
        if($isRealHouse) {
            $this->real_house_model->insertReal_House_Set_log($uid, $house_id, 0,3);
        }

        $feature = $this->input->post('feature', true);
        if(is_array($feature) && !empty($feature))
        {
            $this->load->model('house_feature');
            $feature_arr = $this->house_feature->find_feature($tbl, $fields_values['infotype']);
            foreach($feature as $val)
            {	
                $val = intval($val);
                if($feature_arr[$val] != '')
                {
                    $fields_values['feature'] .= '$'.$val;
                }
            }
            if($fields_values['feature'] != '')
            {
                $fields_values['feature'] .= '$';
            }
        }
		
		//室内,外景,户型图数据集合
		$pfile_name = $this->input->post('p_filename', true);

        //房源封面图
        $pic1 = $this->input->post('pic1', true);

        /*逻辑错误
		if($pic1 == '')
        {
            $pic1 = '';
        }
        else
        {
            $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
        }*/

		if(!empty($pic1))
        {
            $pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
        }
		elseif(!empty($pfile_name))
		{
			$pic1 = reset($pfile_name);
			
			$pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
			
		}
		elseif(!empty($imageUrlArr))
		{
			$pic1 = reset($imageUrlArr);

			$pic1 = preg_match("#\?#", $pic1) ? substr($pic1, 0, strpos($pic1, '?')) : $pic1;
		}
		
		//加载业务模块
		$this->load->model('pic_model');
		$houseRelationPicInfo = $this->pic_model->get_house_pic('1',$house_id);

		//图片标题
		$imageTitle = $this->input->post('imageTitle',true);

		//图片类型
		$imageType = $this->input->post('imageType',true);

		//需要删除的图片ID
		$delPicIdArr = array();

		$houseRelationPicData = array();
		if(!empty($houseRelationPicInfo))
		{
			foreach($houseRelationPicInfo as $key => $item)
			{
				$houseRelationPicData[$item['id']] = $item;
				
				if((!empty($imageUrlArr) && !isset($imageUrlArr[$item['id']])) || empty($imageUrlArr))
				{
					$delPicIdArr[$item['id']] = $item['id'];
				}
			}
		}
		
		//加载审核图片类
		$this->load->model('admin_check');

		//获取360全景封面审核图片
		//$piCheckInfo = $this->admin_check->get_360_pic_check('1',$house_id);

		//获取360全景审核图片
		$piCheckInfo = $this->admin_check->get_all_360_pic_check('1',$house_id);

		$piCheckData = array();
		if(!empty($piCheckInfo))
		{
			foreach($piCheckInfo as $key => $item)
			{
				$piCheckData[$item['picid']] = $item;
			}
		}

		//删除图片
		if(!empty($delPicIdArr))
		{
			//删除360全景图片库存
			$this->pic_model->del_house_some_pic($delPicIdArr);
			
			//删除360全景图片审核
			foreach($delPicIdArr as $key => $value)
			{
				if(isset($piCheckData[$value]))
				{
					$this->admin_check->delete_360_check_pic($piCheckData[$value]['id']);
				}
			}

			/*if(!empty($piCheckInfo) && in_array($piCheckInfo['picid'],$delPicIdArr))
			{
				$this->admin_check_wang->delete_360_check_pic($piCheckInfo['id']);
				
				$piCheckInfo = array();
			}*/
		}
		
		//新增图片或修改图片
		$imageUrlData = array();
		if(!empty($imageUrlArr))
		{
			$numFlag = 0;
			$addPicData = array();
			$editPicData = array();
			foreach($imageUrlArr as $key => $value)
			{
				$numFlag++;

				if(isset($houseRelationPicData[$key]))
				{
					$imageUrlData[$houseRelationPicData[$key]['id']] = array(
						'action' => 'edit',
						'filename' => $houseRelationPicData[$key]['filename'],
						'roomtype' => $imageType[$key],
						'flg' => $houseRelationPicData[$key]['flg']
					);

					if($houseRelationPicData[$key]['position'] != $numFlag || $houseRelationPicData[$key]['title'] != $imageTitle[$key] || $houseRelationPicData[$key]['roomtype'] != $imageType[$key])
					{
						$editPicData[$key] = array(
							'id' => $key,
							'position' => $numFlag,
							'filename' => preg_match("/\?/", $value) ? substr($value, 0, strpos($value, '?')) : $value,
							'title' => $imageTitle[$key],
							'roomtype' => $imageType[$key]
						);
					}
				}
				else
				{
					$addPicData[$key] = array(
						'tbl' => '1',
						'rowid' => $house_id,
						'position' => $numFlag,
						'filename' => preg_match("/\?/", $value) ? substr($value, 0, strpos($value, '?')) : $value,
						'title' => $imageTitle[$key],
						'sort' => '0',
						'createtime' => time(),
						'flg' => '0',
						'isfrom' => '2',
						'isinfotype' => $fields_values['infotype'],
						'roomtype' => $imageType[$key]
					);
				}
			}	
		
			//添加全景图片
			if(!empty($addPicData))
			{
				foreach($addPicData as $key => $item)
				{
					$picId = $this->pic_model->insert_house_panorama_pic($item);

					/*$imageUrlData[$picId] = array(
						'action' => 'add',
						'filename' => $item['filename'],
						'roomtype' => $item['roomtype'],
						'flg' => '0'
					);*/
					
					$surface = '0';
					if($pic1 == $item['filename'])
					{
						$surface = '1';
					}

					$addAdmin360PiCheckData = array(
						'uid' => $uid,
						'housetbl' => '1',
						'houseid' => $house_id,
						'fitment' => '0',
						'infotype' => $fields_values['infotype'],
						'pictbl' => 'upload360',
						'picid' => $picId,
						'picurl' => $item['filename'],
						'sort' => '0',
						'roomtype' => $item['roomtype'],
						'surface' => $surface,
						'dateline' => time(),
						'file_md5' => ''
					);
					
					$this->admin_check->insert_360_check_pic($addAdmin360PiCheckData);
				}
			}

			//编辑全景图片
			if(!empty($editPicData))
			{
				foreach($editPicData as $key => $item)
				{
					$this->pic_model->update_house_panorama_pic($item);
				}
			}
		}
       
        //四、处理房源图片
        $pics = array();
        if (isset($pfile_name) && $pfile_name != '') 
        {
            $pics = array(
                'p_filename' => $pfile_name,
                'p_sort' => $this->input->post('p_sort', true),
                'p_title' => $this->input->post('p_title', true),
                'infotype' => $fields_values['infotype']
            );
            $pic_check = $this->sell_model->insert_house_pic($pics,
                    $tbl, $house_id, $pic1, $this->input->post('block_id', true), 1);
            $pic_check_arr = $pic_check['pic_check'];
            //更新封面图
            $fields_values['pic1'] = $pic_check['indexpic'];
        }
		else
		{
			$this->pic_model->del_house_pic_by($tbl, $house_id);
		}

		//兼容360全景封面图片
		$fields_values['pic1'] = $pic1;

        //目前房源发布规则，只支持住宅类型房源
        if($fields_values['infotype'] == 1 && $fields_values['mright'] == '产权房')
        {
            $fields_values['id'] =  $house_id;
            $fields_values['blockid'] = $this->input->post('block_id', true);
            $fields_values['blockshowname'] = $this->input->post('blockshowname', true);

            //检查房源发布规则
            $resultHousePublishRule = $this->checkHousePublishRule($fields_values);
            if($resultHousePublishRule['system_intercept_status'])
            {
                $fields_values['esta'] = '51';
            }
        }

        //更新房源信息
        //update sell set esta = 5 where id in(33899521, 37700775) and uid = 10000040;
        $affected_rows = $this->sell_model->update($fields_values, $house_id, $uid);

        //添加房源发布价格日志信息
        $this->load->model('house_publish_rule_log_model');
        $housePublishRuleLogData = $this->house_publish_rule_log_model->getRow($house_id,1,3,$uid);

        if(!empty($resultHousePublishRule['suspected_sham_status2']))
        {
            if (empty($housePublishRuleLogData))
            {
                $addData = array('type' => 3, 'uid' => $uid, 'houseId' => $house_id, 'houseType' => '1', 'addTime' => time());
                $this->house_publish_rule_log_model->add($addData);
            }
        }
        elseif(!empty($housePublishRuleLogData))
        {
            $this->house_publish_rule_log_model->delete($housePublishRuleLogData['id']);
        }

        //设置多图、标签、real房
        $fields_values['id'] = $house_id;
        $fields_values['uid'] =  $this->user_arr['uid'];
        if ($affected_rows > 0)
        {
            //判断房源价格是否在预警价格区间，仅对住宅类做判断
            if ($before_info['blockid'] && $fields_values['infotype']==1){
                $_sell = $fields_values;
                $_sell['id']            = $house_id;
                $_sell['blockid']       = $before_info['blockid'];
                $_sell['ownid']         = $before_info['ownid'];
                $_sell['infofrom']      = $before_info['infofrom'];
                $_sell['agentcode']     = $before_info['agentcode'];
                $_sell['uid']           = $before_info['uid'];
                $_sell['district']      = $before_info['district'];
                $_sell['blockshowname'] = $before_info['blockshowname'];
                $_sell['mobile']        = $before_info['mobile'];
                $_sell['creattime']     = $before_info['creattime'];
                $_sell['updatetime']    = $before_info['updatetime'];
                $_sell['expiretime']    = $before_info['expiretime'];
                //$check_rs = bm('sellwarning')->checkSellPrice($_sell,'nj');
                //$IpHostAllow =explode('.',GetIp());
                //print_r($_sell);die;
                $check_rs = bm('sellwarning')->checkSellPriceNew($_sell,GB_CITY,$resultHousePublishRule['suspected_sham_status']);


            }

            /***
            $this->load->model('admin_check');
            $delpic = $this->input->post('delpic', true);
            //把删除的图片从审核库中删除
            if($delpic != '')
            {
                $delpicarr = explode(",", $delpic);
                if(is_array($delpicarr) && !empty($delpicarr))
                {
                    foreach($delpicarr as $val)
                    {
                        $val = intval($val);
                        if($val)
                        {
                            //貌似不太好判断入了哪个库，一起删除吧
                            $this->admin_check->delete_check_pic($tbl, $house_id, $val);
                            $this->admin_check->delete_check_pic_sub($tbl, $house_id, $val);
                        }
                    }
                }
            }***/
            $nowtime = time();
            //审核图片入库
            
            if(isset($pic_check_arr) && is_array($pic_check_arr) 
                    && !empty($pic_check_arr) && $uid > 0)
            {
                $this->load->model('admin_check');
                foreach($pic_check_arr as $key => $val)
                {
                    $infotype = $fields_values['infotype'];
                    $fitment = $fields_values['fitment'];
                    $pic_check_arr[$key]['uid'] = $uid;
                    $pic_check_arr[$key]['housetbl'] = $tbl;
                    $pic_check_arr[$key]['houseid'] = $house_id;
                    $pic_check_arr[$key]['fitment'] = $fitment == "简装" ? 2 : ($fitment == "毛坯" ? 3 : 1);
                    $pic_check_arr[$key]['infotype'] = $infotype == 3 ? 4 : ($infotype == 4 ? 3 : $infotype);//商铺、写字楼互换
                    $pic_check_arr[$key]['dateline'] = $nowtime;
                    //进入审核附属表待夜间JOB过滤入库
                    $this->admin_check->insert_check_pic_sub($pic_check_arr[$key]);
                    //来自设备的图片只入待审核库、不入审核库
                    if($pic_check_arr[$key]['surface'] == 0 && $pic_check_arr[$key]['from_device'] == 1)
                    {
                        unset($pic_check_arr[$key]);
                    }
                    unset($pic_check_arr[$key]['from_device']);
                    //封面图入审核表
                    /*if($pic_check_arr[$key]['surface'] == 1)
                    {
                        $this->admin_check->insert_check_pic($pic_check_arr[$key]);
                    }*/

					$functionSwitch = $this->config->item('functionSwitch');
					if(!empty($functionSwitch['commonImageJoinCheck']) || $pic_check_arr[$key]['surface'] == 1)
					{
						$this->admin_check->insert_check_pic($pic_check_arr[$key]);
					}
                }
            }
            //判断优质，多图 先有多图再有优质
            $this->load->model('sell_star_model');
            $this->sell_star_model->set_houseinfo($fields_values);
            $is_star_house = $this->sell_star_model->check_star_standard();
            $growthMessage = '';
            if ($is_star_house || $is360 == '2')
            {
                if ($before_info['isstar'] != 3) {
                    //房源标签的级别
                    $gradeLog = $before_info['isstar'] == 3 ? 2 : 1;
                    $ghl  = new GrowthHouseLog();
                    $houseGradeLog = $ghl->findHouseGradeLog($house_id, $tbl, $gradeLog, $uid);
                    if ($houseGradeLog['grade'] == 1)
                    {
                        $gbe  = new GrowthBrokerExp(array('id' => $uid, 'groupid' => $package_id));			
                        $gewp = new GrowthExpWayPackage();
                        $exp = $gewp->findScoreByWayAliasAndPackageId('pStarHouse', $package_id);					 
                        $inExpStatus = $gbe->increase('pStarHouse','发布多图房源',$exp);
                        $ghl->updateHouseGradeLog($house_id, $tbl, 2, $uid);
                        if($inExpStatus['status'] == 2 ){
                            //$growthMessage = "您今天的成长值已达峰值！";
                        } elseif($inExpStatus['status'] == 1){
                            //$growthMessage = "成长值+" . $exp;
                        }
                    }
                    //判断原来是否为图
                    if ($before_info['isstar'] != 3)
                    {
                        $this->sell_star_model->set_star();
                    }
                }
                //急推标签改为房源状态改变
                $this->load->model('sell_tag_model');
                $this->sell_tag_model->set_houseinfo($fields_values);
                $this->sell_tag_model->remove_tag(3);
            } 
            else 
            {
                //设置房源属性为多图
                $this->sell_star_model->remove_star(); 
                $this->load->model('sell_tag_model');
                $this->sell_tag_model->set_houseinfo($fields_values);
                //2011-11-30 同步设置标签失效
				$this->sell_tag_model->remove_tag(3);
                //取消REAL房
                $this->load->model('sell_real_model');
                $this->sell_real_model->set_houseinfo($fields_values);
                $this->sell_real_model->remove_real();
                //取消新房直售
                $this->load->model('sell_nofee_model');
                $this->sell_nofee_model->set_houseinfo($fields_values);
                $this->sell_nofee_model->remove_nofee();
            }
            $page_text = '房源修改成功!' . $growthMessage;
        }
        else 
        {
            $page_text = '抱歉，修改房源信息失败!';
        }
        //跳转到之前修改的页面
        $tab = $this->input->post('tab', true);
        $this->jump($this->sell_model->find_func_url() . $tab, $page_text, 3000);
    }

    /**
     * 物理删除房源，如需更改房源状态为删除，请调用update方法
     */
    public function delete()
    {
        //delete from  sell where id = 33899521 and uid = 10000040;
        $this->sell_model->delete(33899521, 10000040);
    }
    
    
    /**
     * 房源列表页
     *
     * @access public
     * @param  string $esta 房源状态字符串
	 * @param  int $page 跳转页数(特殊跳转使用)
     * @return void
     */
    public function manage( $house_esta = 'active' , $page = 1)
    {
        $realHouse = $this->config->item('is_open_real_house');
        //VR申请按钮
        $vr_applay = $this->config->item('vr_applay');

        //post参数
        $post_param = $this->input->post( NULL , TRUE );
        
        /** 分页参数 */
        $page = isset($post_param['page']) ? intval($post_param['page']) : intval($page);
        $this->_init_pagination($page);
        
        //经纪人账号信息
        $uid = $this->user_arr['uid'];//账号
        $package_id = $this->user_arr['package_id'];//套餐

        /*** 经纪人信息 ****/
        $broker_info = array();
        $this->load->model('broker_model');
        $this->broker_model->set_uid($uid);
        $broker_info = $this->user_arr;

        // 请求接口验证是否能发布房源（合肥）
        if ( GB_CITY == 'hf' ) {
            $brokerInfo = $this->broker_model->get_broker_info_new();
            if ( !isset( $brokerInfo['license_number'] ) || empty( $brokerInfo['license_number'] ) ) {
                $this->jump( $url_manage, '根据政策要求，房地产经纪机构以及公司从业人员，需至相关部门完成实名登记后方可发布房源；' );
                return;
            }
        }

        //经纪人额外的信息
        $broker = $this->broker_model->get_broker_info_by_uid($uid);
        $real_status = empty($broker[0]['real_status'])?0:$broker[0]['real_status'];
        //客户经理
        if( isset($broker_info) && isset($broker_info['master']) && $broker_info['master'] != '')
        {
            $broker_info['accout_manager'] = $this->broker_model->get_account_manager($broker_info['master']);
        }



        //房源核心数组
        $house = $this->config->item('house');

		$house['roomcategory'] = array( 
                                '1' => '非多图' , '2' => '多图', '3' => '急推', 
                                '6'=>'全景','7'=>'放心看','8'=>'VR'
                                );
        //加载房源类
        $this->load->model('sell_model');

        //当前经纪人是否放心看经纪人
        $isreal = $this->sell_model->checkisreal($uid);


        $config = $this->config->item('house');
        $vr_show_district = $config['vr_show_district'];

        $esta_arr = array(); //房源状态数组
        $esta_arr = $this->sell_model->get_house_esta();
        /* 'active' => 1 , 'invalid' => 2 , 'delete' => 4 , 'frozen' => 5 */
        $esta = (isset($house_esta) && isset($esta_arr[$house_esta]) && $house_esta != 'delete' ) ? 
                $esta_arr[$house_esta] : 1 ;

        //查询房源条件
        if($esta==5)
        {
            $cond_where = "uid = '" . $uid . "' AND esta in ( 54, 5 )"   . "  AND infofrom = '5' ";
        }
        else {
            $cond_where = "uid = '" . $uid . "' AND esta = '" . $esta . "'  AND infofrom = '5' ";
        }
//        var_dump($uid);die;

        //表单提交参数组成的查询条件
        $cond_where_ext = $this->_get_cond_str($post_param);
        $cond_where .= $cond_where_ext;

        //排序字段
        $roomorder = isset($post_param['roomorder']) ? $post_param['roomorder'] : array();
        $order_arr = $this->_get_orderby_arr($roomorder);

        //符合条件的总行数
        $this->_total_count = $this->sell_model->find_count_by($cond_where);

        //计算总页数
        $pages  = $this->_total_count > 0 ? ceil( $this->_total_count / $this->_limit ) : 0;
        
		// 如果搜索，从第一页开始
		if(isset($_POST['search'])){
			$this->_offset = 0;
		}
        //获取数据源
        $data_info = array ();


        if($this->_total_count > 0 )
        {

                $select_fields = array('id', 'ownid', 'infotype', 'infofrom', 'agentcode', 'uid', 'esta', 'district', 'address',
                    'streetid', 'blockid', 'isreal', 'blockshowname', 'buildyear', 'buildarea',
                    'subfloor', 'floor', 'totalfloor', 'room', 'hall', 'toilet', 'kitchen', 'balcony',
                    'forward', 'price', 'averprice', 'priceterm', 'pricetype', 'fitment', 'contactor',
                    'telno', 'creattime', 'updatetime', 'expiretime', 'isstar', 'istag', 'nofee', 'is360', 'is_real_house','vr_model_id','pic1');

            $this->sell_model->set_select_fields($select_fields);
            $data_info = $this->sell_model->find_all_by( $cond_where , $this->_offset ,
                    $this->_limit , $order_arr['order_key'] , $order_arr['order_by'] );
        }

        $row_num =  count($data_info);
       
        //加载新房直售属性类
        $this->load->model('sell_nofee_model');
		//xue add 2015-06-25
        $this->load->model("house_tag_package_model");
        
        //预约方案
        $reserve_info = array();
		$publish_block = array();
        //加载二手房Real房属性类

        $this->load->model('sell_real_model');
        $broker_info['limit_apply_real_num'] = $this->sell_real_model->get_today_apply_num();

        if( $row_num > 0 )
        {   
            //加载辅助函数
            $this->load->helper('common_url');
            $this->load->helper('common_house');
			$this->load->helper('common_string');
            //昨天的日期
            $yesterday = date( 'Ymd' , time() - 86400 );
            
            //实例化经纪人统计类(原中间件提供数据统计类)
            $this->load->library( 'statistics');
            
            //加载多图属性类
            $this->load->model('sell_star_model');
            $week_array = array();
            if( $house_esta == 'active')
            {
				if(!$_SESSION['sell_token_value']){
					$_SESSION['sell_token_value'] = md5(getRandChar(10));
				}
                //加载刷新日志类
                $this->load->model('log_refresh');
				//加载房源类
                $this->load->model('sell_model');

                //加载急推属性类
                $this->load->model('sell_tag_model');

                //加载预约方案模型类
                $this->load->model('reserve_model');
                $this->reserve_model->set_uid($uid);
                //$month_tag_num = $this->sell_tag_model->get_month_tagnum_by_uid($uid , 1 , 1);
                //xue add 2015-06-25
                $this->load->model("house_tag_package_model");
		        $tag_valid_num = $this->house_tag_package_model->get_tag_valid_num($broker_info['uid'],1,1);

                //竞投期限类
                $growthBidPeriods = new GrowthBidPeriods();

                //小区专家
                $periodsBlockExpert = $growthBidPeriods->currentBidPeriods(1);

                //获取最新一期小区专家等级
                $bidBlockExpertPeriodsId = $periodsBlockExpert['id'];
                $growthBidBlockExpert = new GrowthBidBlockExpert();

                //经纪人竞投房源
                $grow_bid_house_record = new GrowthBidHouseRecordFinish();
                $bidHouseRecord = $grow_bid_house_record->getBidFinishByBorkerId($uid);


                //计算申请VR时拍摄时间，当前时间下 延后7天
                $week_array = $this->sell_real_model->getWeekVrData();

                //计算房源 vr 申请拍摄状态

                foreach ($data_info as $key=>$value){
                    $applay = $this->sell_model->vrapplay_status($value['id']);
                    $data_info[$key]['vr_status'] = $applay['shot_status'];
                    $data_info[$key]['shot_name'] = $applay['shot_name'];
                    $data_info[$key]['shot_telno'] = $applay['telno'];

                    $infotype = $value['infotype'];
	                $is_show_real = 0;
	                if($realHouse && in_array($infotype,array(1,2)) && $real_status){
		                $is_show_real = 1;
					}
	                $data_info[$key]['is_show_real'] = $is_show_real;
                }

            }

			if($house_esta == 'active' || $house_esta == 'invalid')
			{

				//我发布的小区
				$block_fields = array('blockid','blockshowname');
				$this->sell_model->set_select_fields($block_fields);
				$publish_block = $this->sell_model->find_publish_block($uid , $house_esta);
			}

            //冻结房源类
            if( $house_esta == 'frozen')
            {
                $this->load->model('sell_freeze_model');
                $house['freeze_esta'] = $this->sell_freeze_model->get_freeze_esta();
            }

            //房源信息数组
            $house_info = array();

            $cache = array();
			if($house_esta == 'active')
			{
				$memkey = GB_CITY."_gg_housel_manage_list_".$house_esta.'_'.$uid.$this->_offset;
				$cache = $this->mc->get($memkey);
			}

			$this->mc->delete($memkey);
			if (!empty($cache['data']) && $cache['isok'] == 1 && is_array($cache['data']))
			{
				$data_info = $cache['data'];
                $arr_rowid = $cache['arr_rowid'];
			}
			else
			{
                $this->load->model('pic_model');
                $nowTime = time();

                for( $i = 0 ; $i < $row_num ; $i ++ )
				{
					//房源地址
					$data_info[$i]['info_url'] =  get_sellinfo_url($data_info[$i]['id']);
					if($_COOKIE['zkg']){
						var_dump($data_info[$i]['info_url']);die;
					}
					//房源小区地址
					$data_info[$i]['block_url'] =  get_blockinfo_url($data_info[$i]['blockid']);

					//房源地址
					$data_info[$i]['address_str'] =  csubstr($data_info[$i]['address'],60);

					//面积
					$data_info[$i]['buildarea'] =  strip_end_0($data_info[$i]['buildarea']);

					//价格
					$data_info[$i]['price'] =  strip_end_0($data_info[$i]['price']);

					//楼层
					if(empty($data_info[$i]['subfloor']))
					{
						$data_info[$i]['floor_str'] = $data_info[$i]['floor'].'/'.$data_info[$i]['totalfloor'];
					}
					else
					{
						$data_info[$i]['floor_str'] = $data_info[$i]['subfloor'].'-'.$data_info[$i]['floor'].'/'.$data_info[$i]['totalfloor'];
					}

					//房源修改地址
					$data_info[$i]['modify_url'] =  $this->sell_model->get_modify_house_url($data_info[$i]['id']);

					//是否为多图房源
					$this->sell_star_model->set_houseinfo($data_info[$i]);
					$data_info[$i]['is_star_result'] = $this->sell_star_model->is_star();

					//激活房源页面数据
					if( $house_esta == 'active')
					{
						//是否为急推房源
						$this->sell_tag_model->set_houseinfo($data_info[$i]);
						$data_info[$i]['is_tag_result'] = $this->sell_tag_model->is_tag();

						//急推标准
						if($data_info[$i]['is_tag_result'] === FALSE)
						{
							$data_info[$i]['tag_standard'] = $this->sell_tag_model->check_tag_standard_list($tag_valid_num);

							$data_info[$i]['house_tag_info'] = array();
							$data_info[$i]['tag_exipire_days'] = '';
						}
						else
						{
							//急推标签剩余日期
							$data_info[$i]['house_tag_info'] = $this->sell_tag_model->get_tag_record();

							if(isset($data_info[$i]['house_tag_info']) && !empty($data_info[$i]['house_tag_info']))
							{
								$data_info[$i]['tag_exipire_days'] =
								$this->sell_tag_model->tag_exipire_days($data_info[$i]['house_tag_info']['expiretime']);
							}
						}


						//是否新房直售
						$this->sell_nofee_model->set_houseinfo($data_info[$i]);
						$data_info[$i]['is_nofee_result'] = $this->sell_nofee_model->is_nofee();

						//新房直售标准
						if($data_info[$i]['is_nofee_result'] === FALSE)
						{
							$data_info[$i]['nofee_standard'] = $this->sell_nofee_model->check_nofee_standard();
						}

						//是否Real房
						$this->sell_real_model->set_houseinfo($data_info[$i]);
						$data_info[$i]['is_real_result'] =  $this->sell_real_model->is_real();
						//REAL房标准
						if($data_info[$i]['is_real_result'] === FALSE)
						{
							$data_info[$i]['real_standard'] = $this->sell_real_model->check_real_standard_list($real_num,$real_today_num);
						}

						//刷新次数
						$data_info[$i]['refresh_num'] =
						$this->log_refresh->refresh_num_by_id( $data_info[$i]['id'],'sell', $data_info[$i]['updatetime']);


						//是否成功参加竞投
						$data_info[$i]['is_bidhouse_result'] = FALSE;
						if (is_array($bidHouseRecord) && !empty($bidHouseRecord))
						{
							foreach($bidHouseRecord as $v)
							{
								if($v['house_id'] == $data_info[$i]['id'] )
								{
									$data_info[$i]['is_bidhouse_result'] = TRUE;
								}
							}
						}

						//今天是否在竞投房源日
						$periodsHouse = $growthBidPeriods->currentBidPeriods(2);
						if ($periodsHouse['status'] == 1) //竞投日
						{
							//获取经纪人竞投的房源
							$growth_bid_house_on = GrowthBidRecordFactory::getRecordClassByTime('house', $periodsHouse['status']);
							$bid_house_on = $growth_bid_house_on->getBidHouseByBrokerId($uid, $periodsHouse['id']);
							if (isset($bid_house_on) && !empty($bid_house_on)) {
								$bid_house_on = SqlCombinHelper::changeToKeyArray($bid_house_on, 'house_id');
							} else {
								$bid_house_on = array();
							}
						}


						//房源是否在竞投中
						if (isset($bid_house_on) && !empty($bid_house_on)
							&& isset($bid_house_on[$data_info[$i]['id']]))
						{
							$data_info[$i]['is_bidon_house'] = TRUE;
						}
					}

					//到期天数
					$data_info[$i]['exipire_days'] = to_expire_day_new($data_info[$i]['expiretime']);

                    //房源点击量
                    $fid_click_count_key = GB_CITY."_statistics_get_fidclickcount_new".$yesterday."_sell_".$data_info[$i]['id'];
                    //$this->mc->delete($fid_click_count_key);
                    $fid_click_count = $this->mc->get($fid_click_count_key);

                    //print_r($fid_click_count);
                    if($fid_click_count === false)
                    {
                        $click_id_arr[$i] = $data_info[$i]['id'];
                        $house_key[$data_info[$i]['id']] = $i;
                    }else
                    {
                        $data_info[$i]['click_num_y'] = $fid_click_count;
                    }

					//var_dump($data_info[$i]['click_num_y']);exit();
					if( $house_esta == 'frozen')
					{
					    if($data_info[$i]['esta']=='54')
                        {
                            //删除信息
                            $this->load->model('sell_delete_model');
                            $house['delete_esta'] = $this->sell_delete_model->get_freeze_esta();
                            $this->sell_delete_model->set_select_fields(array('id', 'esta', 'rowid', 'reason', 'deletetime','appealtime','recovertime','thawtime'));
                            $data_info[$i]['freeze_info'] = $this->sell_delete_model->get_freeze_by_rowid($data_info[$i]['id']);

                            if($data_info[$i]['freeze_info']['esta']==1)
                            {
                                $data_info[$i]['freeze_info']['freezetime']=$data_info[$i]['freeze_info']['deletetime'];
                            }elseif ($data_info[$i]['freeze_info']['esta']==2){
                                $data_info[$i]['freeze_info']['freezetime']=$data_info[$i]['freeze_info']['appealtime'];
                            }elseif ($data_info[$i]['freeze_info']['esta']==3)
                            {
                                $data_info[$i]['freeze_info']['freezetime']=$data_info[$i]['freeze_info']['recovertime'];
                            }elseif ($data_info[$i]['freeze_info']['esta']==4)
                            {
                                $data_info[$i]['freeze_info']['freezetime']=$data_info[$i]['freeze_info']['thawtime'];
                            }
                            //print_r($data_info[$i]['freeze_info']);

                        }
                        else {

                            //冻结信息
                            $this->sell_freeze_model->set_select_fields(array('id', 'esta', 'rowid', 'reason', 'freezetime'));
                            $data_info[$i]['freeze_info'] = $this->sell_freeze_model->get_freeze_by_rowid($data_info[$i]['id']);
                        }
					}

                    // 封面图
                    $pic1 = $data_info[$i]['pic1'] ? $data_info[$i]['pic1'] : '';
                    if (!$pic1) {
                        $housePics = $this->pic_model->find_house_pic_by('sell', $data_info[$i]['id']);
                        $data_info[$i]['pic1'] = $housePics ? $housePics[0]['filename'] : STATIC_SOURCE_URL.'/zsb/images/v1.0/default.jpg';
                    }
                    // 发布天数
                    $diffTimeStamp = $nowTime - $data_info[$i]['creattime'];
                    $publishDays = ceil($diffTimeStamp / 86400);
                    $data_info[$i]['publish_days'] = $publishDays;
                    $publishDays = $publishDays < 1 ? 1 : $publishDays;

                    switch ($publishDays) {
                        case $publishDays <= 30:
                            $data_info[$i]['publish_days_color'] = 'green';
                            break;
                        case $publishDays >=30 && $publishDays <=89:
                            $data_info[$i]['publish_days_color'] = '#F57C39';
                            break;
                        case $publishDays >= 90:
                            $data_info[$i]['publish_days_color'] = 'red';
                    }

					$arr_rowid[] = $data_info[$i]['id'];
				}

				if($house_esta == 'active')
				{
                    $this->mc->add($memkey, array('isok'=>1,'data'=>$data_info,'arr_rowid'=>$arr_rowid),  3);
				}
			}

            //批量查询房源预约方案
            if( $house_esta == 'active')
            {
                $reserve_info = $this->reserve_model->get_project_by_rowids('sell' , $arr_rowid);
            }
        }



        //获取房源昨日点击量
        if(is_array($click_id_arr)&&!empty($click_id_arr)){

            foreach($click_id_arr as $key=>$value){
                $fids .= $value.",";
            }
            $fids = rtrim($fids,",");

            $click_data_arr = $this->statistics->getfidsclickcountnew( $yesterday , $fids , 'sell');

            foreach($click_data_arr as $value){
                $click_house_id= trim($value['fid']);
                $click_house_num= trim($value['count']);
                //房源在数据的编号

                $iid = $house_key[$click_house_id];

                if($iid>=0){
                    $data_info[$iid]['click_num_y'] = $click_house_num;
                }

                $fid_click_count_key = GB_CITY."_statistics_get_fidclickcount_new".$yesterday."_sell_".$click_house_id;

                $this->mc->set($fid_click_count_key,$click_house_num,7200);
            }

        }

        //是否显示分页
        $pagination = NULL;
        if( $this->_total_count > $this->_limit)
        {
            $pagination = helper_pagination( $this->_current_page , $pages , $this->_total_count );
        }

        /*** 经纪人今日使用统计 ***/
        $statistic_data = array();
        $this->load->model('statistics_model' ,'stat');
        $this->load->model('broker_package_model','broker_package');
        //套餐房源个数
        $package_id = $this->user_arr['package_id'];
        $this->load->model('package_model');
        $package = $this->package_model->find_by_id($package_id);
        $post_limit = $package['package_valid_num'];
        //激活出售
        $statistic_data['sell_count'] = $this->stat->sellCount($uid);
        //激活出租
        $statistic_data['rent_count'] = $this->stat->rentCount($uid);
        $house_count = $statistic_data['sell_count'] + $statistic_data['rent_count'];

		//激活全景图房源总量
		$statistic_data['sell360Count'] = $this->stat->sell360Count($uid);
        $statistic_data['rent360Count'] = 0;

		//当前激活多图总量
        $statistic_data['sellCountStar'] = $this->stat->sellCountStar($uid);
        $statistic_data['rentCountStar'] = $this->stat->rentCountStar($uid);

        //放心看
        $package_id     =$this->user_arr['package_id'];

        $realnum_limit =$this->broker_model->get_realnum_by_packageid($package_id);
        $this->load->model('real_house_model');

        $real_status =$this->real_house_model->getBrokerRealStatus($uid);
        if($real_status){
            $statistic_data['realHouseSetCount'] = $this->real_house_model->getUidRealHouseNum($uid);;
            $statistic_data['realHouseRemainCount'] = $realnum_limit - $statistic_data['realHouseSetCount'];
        }

        else
        {
            $statistic_data['realHouseSetCount'] = 0;
            $statistic_data['realHouseRemainCount'] = 0;
        }
		//增加判断，如果经纪人放心看账户余额为0，那么剩余放心看数量应该为0 TODO
        $res = $this->real_house_model->getbrokermoney($uid);

       /* if($res['real_house_money'] < 1){
            $statistic_data['realHouseRemainCount'] = 0;
        }*/



        //剩余套餐数
        $statistic_data['package_valid_num_limit'] = $post_limit > $house_count ?
                $post_limit - $house_count : 0;
        $package_info = array();
        $package_info = $this->broker_package->find_by_id($package_id);

		$broker_info['package_info'] = $package_info;
        //库存量总量
        $statistic_data['package_stock_num'] = $package_info['package_stock_num'];
        //当前库存房源量
        $statistic_data['stock_house_num'] = $this->broker_model->stock_house_num();
        //剩余库存量
        $statistic_data['package_stock_num_limit'] =
        $statistic_data['package_stock_num'] >=  $statistic_data['stock_house_num']?
        $statistic_data['package_stock_num'] - $statistic_data['stock_house_num'] : 0;


        //当日刷新
        $statistic_data['refresh_limit'] = $this->stat->refreshNumber($package_id);
        $statistic_data['refresh_today'] = $this->stat->refreshNumberToday($uid);
        $this->load->model('reserve_model');
        $this->reserve_model->set_uid($uid);

        //预约未执行个数
        $statistic_data['refresh_not_do'] = $this->reserve_model->get_reserve_remain_num();
        if ($statistic_data['refresh_not_do'] >= $statistic_data['refresh_limit'])
        {
            $statistic_data['refresh_not_do'] = $statistic_data['refresh_limit'] - $statistic_data['refresh_today'];
        }
        //此处逻辑是为了让预约未执行与已执行之和等于刷新总量
        $need2reserveRefreshNum = $statistic_data['refresh_limit'] - $statistic_data['refresh_today'];
        $statistic_data['refresh_not_do'] = $statistic_data['refresh_not_do'] >= $need2reserveRefreshNum ? $need2reserveRefreshNum : $statistic_data['refresh_not_do'];
        $statistic_data['refresh_remain'] = $statistic_data['refresh_limit'] - $statistic_data['refresh_today'] - $statistic_data['refresh_not_do'];
        $statistic_data['refresh_remain'] = $statistic_data['refresh_remain'] > 0 ? $statistic_data['refresh_remain'] : 0;

        //急推标签使用情况
        if($package_info['package_tag_num'] > 0)
        {
		    $statistic_data['tag_remain'] = $this->house_tag_package_model->get_tag_valid_num($uid,1);
            $statistic_data['tag_count_today'] = $this->stat->jtLabelCount($uid);
            if($_GET['zkg']){
                var_dump($statistic_data);die;
            }
        }
        else
        {
            $statistic_data['tag_limit'] = '--';
            $statistic_data['tag_count_today'] = '--';
            $statistic_data['tag_remain'] = '--';
        }


        //新房直售
        if($broker_info['nofee_num'] > 0)
        {
            $statistic_data['nofee_limit'] = $this->sell_nofee_model->get_nofee_num_limit($uid);
            $statistic_data['nofee_today'] = $this->sell_nofee_model->get_nofee_num_by_uid($uid);
            $statistic_data['nofee_limit'] = $statistic_data['nofee_limit'] > $statistic_data['nofee_today'] ?
            $statistic_data['nofee_limit'] - $statistic_data['nofee_today'] : 0;
        }
        else
        {
            $statistic_data['nofee_limit'] = '--';
            $statistic_data['nofee_today'] = '--';
            $statistic_data['nofee_limit'] = '--';
        }

        //Real房
        if($broker_info['real_limit'] > 0)
        {
            $statistic_data['real_limit'] = $this->stat->real_num_limit($uid);
            $statistic_data['real_today'] = $this->stat->real_num_today($uid);
            $statistic_data['real_remain'] = $statistic_data['real_today'] <= $statistic_data['real_limit'] ?
            $statistic_data['real_limit'] - $statistic_data['real_today'] : 0 ;
        }
        else
        {
            $statistic_data['real_limit'] = '--';
            $statistic_data['real_today'] = '--';
            $statistic_data['real_remain'] = '--';
        }

		//冻结房源个数
		$cond_where_forzen = "uid = '".$uid."' AND esta in (5,54)  AND infofrom = '5'";
		$statistic_data['forzen_house_num'] = $this->sell_model->find_count_by($cond_where_forzen);
        /*** 经纪人今日使用统计结束 ***/

        //经纪人今日刷新成长值
        $growthExpDayCount = new GrowthExpDayCount();
        $refreshEventArray = array('refreshHouse');
        $exp_rank_day = $growthExpDayCount->getExpAndRank($uid, $refreshEventArray);
        $statistic_data['growthDaySum'] = $exp_rank_day['exp'];
        //当前用的排序名次百分比
        $statistic_data['rankRate'] = $exp_rank_day['rate'];

        /** 页面初始化 */
        $data['week_array'] = $week_array;
        $data['page_title'] = '房源管理-管理出售';
        $data['css'] = load_css('zsb/css/v1.0/style1.css'); //需要加载的css
        $data['js'] = load_js('zsb/js/v1.0/js2.js,zsb/js/v1.0/cp.js,common/js/swf/swfupload.js,'
                . 'zsb/js/v1.0/upload_real.js');   //需要加载的JS
        $data['house']  = $house;
        $data['post_param']  = $post_param;
		$data['publish_block']  = $publish_block;
        $data['data_info']  = $data_info;
        $data['reserve_info']  = $reserve_info;
        $data['broker_info']  = $broker_info;
        $data['statistic_data']  = $statistic_data;//今日使用统计
        $data['upload_pic_url'] = $this->config->item('base_url') . 'pic/common/';
        $data['documentation'] = $this->config->item('documentation');//帮助文档
        $data['page']  = $this->_current_page;
        $data['pagination'] = $pagination;
        $data['total_count'] = $this->_total_count;
        $data['vr_applay'] = $vr_applay;
		switch ($house_esta){
			case 'active' :
				$ga_title = '激活房源';
				break;
			case 'invalid' :
				$ga_title = '失效房源';
				break;
			case 'frozen' :
				$ga_title = '违规房源';
				break;
			case 'sysfrozen' :
				$ga_title = '系统拦截';
				break;
		}
		$data['google_analytics'] = get_ga_js_code('/房源管理/管理出售/'.$ga_title.'/');
        //引导
        $this->load->library('guide');
        $data['guide_show'] = $this->guide->check_guide($uid, 'zsb_refresh');
        // 2016-1-15 添加星级数据 -----------start -------->
		$uid = $this->user_arr['uid'];
		$data['broker_new_info'] =$this->broker_model->get_broker_info_by_uid($uid);

        $this->load->model('real_house_model');
        $balance = $this->real_house_model->getBrokerRealHouseMoney($uid);

        $data['balance']    =$balance; //经纪人账户余额
        $data['realHouse']  =$realHouse; //是否开启真房源功能

        $data['realHouseMoney'] = $this->config->item('realHouseMoney'); //真房源默认价格
        //var_dump($data);die;


		// 2016-1-15 添加星级数据 -----------end -------->
		// 2016-2-15 获取360引导页数据 -----------start -------->

		$data['broker_remind_set'] =$this->broker_model->get_broker_remind_set_by_uid($uid);

		// 2016-2-15 获取360引导页数据 -----------end -------->

		// 数据过滤
		if($house_esta == 'frozen'){
			if(!empty($data_info)){
				$this->load->model('house_freeze_base_model');
				$IpHostAllow =explode('.',GetIp());
				if($IpHostAllow['0']=='192' || $IpHostAllow['0']=='127')
				{

					$databaseSellWarning = mysql_connect('172.17.1.50', 'root', 'idontcare');
				}
				else
				{
					$databaseSellWarning = mysql_connect('172.17.1.153', 'root', 'idontcare');
				}

				mysql_query('set names gbk',$databaseSellWarning);
				mysql_select_db('esfpublic',$databaseSellWarning);

				foreach($data_info as $key => $value){
					$databaseFreezeBase = $this->house_freeze_base_model->database();
					$databaseFreezeBase->select(array('rowid', 'remark', 'freezetime', 'appealtime', 'thawtime'));
					$databaseFreezeBase->where('rowid', $value['id']);
					$resultFreezeBase = $databaseFreezeBase->get('house_freeze')->row_array();
					// 违规处理

					//$data_info[$key]['freeze_info']['esta'] = $value['esta'];
					// 违规原因

					if(empty($value['freeze_info']['reason'])){
						$data_info[$key]['freeze_info']['reason'] = '房源违规';
						// 如果违规处理是删除，展示删除的原因
						if(intval($value['esta']) == 4){
							if(!empty($resultFreezeBase)){
								$data_info[$key]['freeze_info']['reason'] = $resultFreezeBase['remark'];
							}
						}
						// 如果违规处理是冻结
						if(intval($value['esta']) == 5){
							// 查找疑似价格虚假房源库有没有，有就展示“价格虚假”
							$row = null;
							$sql1 = sprintf('select * from sell_price_warning where id=%s', $value['id']);
							$result1 = mysql_query($sql1, $databaseSellWarning);
							$row1 = mysql_fetch_array($result1,$databaseSellWarning);
							if($row1){
								$row = $row1;
							}
							$sql2 = sprintf('select * from sell_price_warning_pass where id=%s', $value['id']);
							$result2 = mysql_query($sql2, $databaseSellWarning);
							$row2 = mysql_fetch_array($result2,$databaseSellWarning);
							if($row2){
								$row = $row2;
							}
							$sql3 = sprintf('select * from sell_price_warning_refuse where id=%s', $value['id']);
							$result3 = mysql_query($sql3, $databaseSellWarning);
							$row3 = mysql_fetch_array($result3,$databaseSellWarning);
							if($row3){
								$row = $row3;
							}
							if($row){
								$data_info[$key]['freeze_info']['reason'] = '价格虚假';
							}
						}
					}
					// 处理时间
					$time = array();
					array_push($time, intval($value['updatetime']));
					array_push($time, intval($value['freeze_info']['freezetime']));
					if($resultFreezeBase){
						array_push($time, intval($resultFreezeBase['freezetime']));
						array_push($time, intval($resultFreezeBase['appealtime']));
						array_push($time, intval($resultFreezeBase['thawtime']));
					}
					$pos = array_search(max($time), $time);
					$data_info[$key]['freeze_info']['freezetime'] = $time[$pos];
				}

                mysql_close($databaseSellWarning);

				// Order By Time
				/*$array = array();
				foreach($data_info as $value){
					if(!empty($value['freeze_info']['freezetime'])){
						$array[intval($value['freeze_info']['freezetime'])] = $value;
					}
				}
				foreach($data_info as $value){
					if(empty($value['freeze_info']['freezetime'])){
						array_push($array, $value);
					}
				}
				krsort($array);
				$data_info = $array;*/
			}
		}
		$data['data_info'] = $data_info;

		// 是否能够发全景房
		$config = $this->config->item('is_publish_360');
		if($config === false){
			$config = true;
		}else{
			if($config == 1){
				$config = true;
			}else{
				$config = false;
			}
		}
		$data['is_publish_360'] = $config;

		// 去掉全景筛选
		if(!$data['is_publish_360']){
			foreach($data['house']['roomcategory'] as $key => $value) {
				if($value == '全景'){
					unset($data['house']['roomcategory'][$key]);
				}
			}
		}

		//中秋节期间提示语

        $data['tishi'] = $this->guojie();

        $data['isreal'] = $isreal;
        //加载模板

        $template_name = $esta == 1 ? 'sell_manage' : 'sell_manage_'.$house_esta;
        $this->view( 'house_manage' , $template_name , $data);
    }


    public function guojie(){
        $time = time();
        $zqs = strtotime('2018-10-1');
        $zqe = strtotime('2018-10-8');
        if($time >= $zqs && $time<= $zqe){
            return true;
        }
        return false;
    }


    /* 列表页房源操作入口
     * @param   string $actiontype 操作类型
     * @param   string $rowid_str 操作房源编号
     * @param   int $page 操作页数
     * @param   string $referer 操作后跳转的页面
    */
    public function do_action()
    {
        //操作类型
        $actiontype = $this->input->post( 'actiontype' , TRUE );

        //房源编号
        $rowid_str = $this->input->post( 'actionid' , TRUE );
        $rowid = $this->input->post( 'rowid' , TRUE );

        //当前页数
        $page = $this->input->post( 'pg' , TRUE );

        //跳转地址
        $referer = $this->input->post( 'referer' , TRUE );
        $referer = (isset($referer) && $referer != '')  ? $referer : $_SERVER['HTTP_REFERER'];

        //房源编号字符串转化为数组
        $arr_id = explode( ',' , $rowid_str );

        //经纪人账号uid
        $uid = $this->user_arr['uid'];
        //门店账号
        $agentcode = $this->user_arr['agentcode'];

        $package_id =  $this->user_arr['package_id'];


        //房源类型
        $tbl = 'sell';

        //分发处理
        switch ($actiontype)
        {
            case 'invalid_house':
                $invalid_num = 0;

                //初始化房源操作类
                $this->load->model('sell_operate_model');

                /*** 1、失效房源 ***/
                $invalid_num = $this->sell_operate_model->invalid_house($arr_id);
                if( $invalid_num > 0 )
                {

                    //加载中间件统计类
                    $this->load->library('statistics');

                    //加载房源急推属性类
                    $this->load->model('sell_tag_model');

                    //加载Real房属性类
                    $this->load->model('sell_real_model');

                    //加载门店类
                    $this->load->model('agency_model');
                    $relation_info = array();
                    $relation_info = $this->agency_model->get_relation_by_agentcode($agentcode);
                    $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
                    $parentcode = '';
                    if( is_array($relation_info) && !empty($relation_info))
                    {
                        $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
                    }
                    else
                    {
                        $parentinfo = array();
                        $select_array = array('parentcode');
                        $this->agency_model->set_select_fields($select_array);
                        $parentinfo = $this->agency_model->get_company_info_by_code($agentcode);
                        $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
                    }

                    foreach( $arr_id as $rowid )
                    {



	                    $this->load->model('real_house_model');
	                    $isRealHouse =$this->real_house_model->getInfoByRowid($rowid);
	                    if($isRealHouse) {

		                    //下架放心看
		                    $this->load->model('zsb_api_model');
		                    $re = $this->zsb_api_model->getRequrstData('cancleRealHouse',array('house_id'=>$rowid,'reason'=>3));
		                   /* $this->real_house_model->insertReal_House_Set_log($uid, $rowid_str, 0, 3);
		                    $this->real_house_model->updateRealHouse($rowid_str);*/
	                    }

                        /*** 2、失效标签、Real房 ****/
                        $house_info = array('id'=> $rowid);
                        $this->sell_tag_model->set_houseinfo($house_info);
                        $this->sell_tag_model->remove_tag(3);

                        $this->sell_real_model->set_houseinfo($house_info);
                        $this->sell_real_model->remove_real();

                        /*** 3、取消预约刷新 ***/
                        $this->load->model('reserve_model');
                        $result = $this->reserve_model->delete_projecthouse($uid , $tbl , $rowid);

                        /*** 4、通过接口提交操作日志给中间件，operatetype 1:新增 2刷新 3删除 4失效 5再发布 ***/
                        $msg = 4;
                        $this->statistics->sub_operatecount( $uid , $agentcode , $msg , $rowid , '' , $tbl , $domain , $parentcode );

                        /*** 5、提交房源操作日志给MYSQL(经纪人日志查询),[$msg:4-失效房源] ***/
                        $this->sell_model->action_log( $agentcode , $uid , $tbl , $rowid , $msg);


                    }
                    $page_text = '操作成功，共失效了'.$invalid_num.'条房源';
                }
                else
                {
                    $page_text = '失效房源失败';
                }
                break;
            case 'multi_delete_house':
                $delete_num = 0;

                //初始化房源操作类
                $this->load->model('sell_operate_model');

                /*** 1、删除房源 ***/
                $delete_num = $this->sell_operate_model->delete_house($arr_id);
                if( $delete_num > 0 )
                {
                    //加载中间件统计类
                    $this->load->library('statistics');

                    //加载门店类
                    $this->load->model('agency_model');
                    $relation_info = array();
                    $relation_info = $this->agency_model->get_relation_by_agentcode($agentcode);
                    $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
                    $parentcode = '';
                    if( is_array($relation_info) && !empty($relation_info))
                    {
                        $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
                    }
                    else
                    {
                        $parentinfo = array();
                        $select_array = array('parentcode');
                        $this->agency_model->set_select_fields($select_array);
                        $parentinfo = $this->agency_model->get_company_info_by_code($agentcode);
                        $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
                    }

                    foreach( $arr_id as $rowid )
                    {

                        $this->load->model('real_house_model');
                        $isRealHouse =$this->real_house_model->getInfoByRowid($rowid);
                        if($isRealHouse) {
                            //下架放心看
                            $this->load->model('zsb_api_model');
                            $re = $this->zsb_api_model->getRequrstData('cancleRealHouse',array('house_id'=>$rowid,'reason'=>3));
                        }

                        $tbl = 'sell';
                        /*** 4、通过接口提交操作日志给中间件，operatetype 1:新增 2刷新 3删除 4失效 5再发布 ***/
                        $this->statistics->sub_operatecount( $uid , $agentcode , 3 , $rowid , '' , $tbl , $domain , $parentcode );

                        /*** 5、提交房源操作日志给MYSQL(经纪人日志查询),[$msg:4-失效房源] ***/
                        $this->sell_model->action_log( $agentcode , $uid , $tbl , $rowid , 0);
                    }
                    $page_text = '操作成功，共删除了'.$delete_num.'条房源';
                }
                else
                {
                    $page_text = '删除了房源失败。';
                }
                break;
            case 'refresh':
                if(is_array($arr_id) && !empty($arr_id) )
                {
                    $token_sell = $this->input->post( 'sell_token' , TRUE );


					if($uid==850507){
					//	VAR_DUMP($_SESSION['sell_token_value']);
					//	var_dump($_POST);EXIT();
					 //  var_dump($token_sell);exit();
					}
				    if($token_sell!=$_SESSION['sell_token_value']){
					    $this->jump($url_manage, "服务器正忙，请稍后再试");
                        return;
					}
                    $errornum = 0;

                    //加载刷新函数文件
                    $this->load->helper('common_house');

                    //套餐ID
                    $package_id = $this->user_arr['package_id'];

                    //刷新总量限制
                    $package_info = array();
                    $this->load->model('package_base_model');
                    $this->package_base_model->set_select_fields(array('package_refresh_num'));
					$package_info = $this->package_base_model->find_by_id($package_id);
                    $refresh_limit =  intval($package_info['package_refresh_num']);

                    //今日已刷新数量
                    $this->load->model("log_refresh");
                    $refreshnum = $this->log_refresh->findTodayNumberByBrokerId($uid);



                    //单条刷新  xue modify 2015-04-10
					if(count($arr_id)==1){
					    $cb = refresh_house( $uid ,$tbl , $arr_id[0]);
                        if( trim($cb) == 'error')
                        {
                            $errornum ++ ;
                            unset( $arr_id[0] );
                        }
                        else
                        {
                            $msg = 7;/*** 提交房源操作日志给MYSQL(经纪人日志查询),[$msg:7-刷新房源] ***/
                            $this->sell_model->action_log( $agentcode , $uid , $tbl , $arr_id[0] , $msg);
                        }
					}else{
                        //批量刷新
						foreach( $arr_id as $key => $value ){
							$house_ids .= $value.",";

						}
                        $house_ids = rtrim($house_ids,",");

                        $cb = refresh_house_s($uid,$tbl,$house_ids);
						$cb = json_decode($cb,true);
						if(is_array($cb['data'])&&!empty($cb['data'])){
							foreach($cb['data'] as $key=>$val){
							   if( $val['status'] == -1){
									$errornum ++ ;
									unset( $arr_id[$key] );
								}
								else
								{
									$msg = 7;/*** 提交房源操作日志给MYSQL(经纪人日志查询),[$msg:7-刷新房源] ***/
									$this->sell_model->action_log( $agentcode , $uid , $tbl , $val['hid'] , $msg);
								}
							}


						}

					}

					//modify xue end


                    $errornum = intval($errornum);
                    $sum = count($arr_id);

                    //经纪人成长体系
                    if( $sum > 0 )
                    {
                        $arrBroker = array(
                            'id' => $uid,
                            'groupid' => $package_id,
                        );

                        $ctime = date('Y-m-d');
						//成长值
                        $gbe  = new GrowthBrokerExp($arrBroker);
                        $gewp = new GrowthExpWayPackage();
						$exp = 0;
                        $exp = $gewp->findScoreByWayAliasAndPackageId('refreshHouse',$package_id);

                        if( $sum > 1)
                        {
							$log_tip = '批量刷新房源';
							$exp = $exp * $sum;
                        }
                        else
                        {
							$log_tip = '刷新单条房源';
                        }
                        $inExpStatus = $gbe->increase('refreshHouse' , $log_tip ,$exp);

                        /*if($inExpStatus['status'] == 2)
                        {
                            $growthMessage = "<div style='text-align:center;margin:0px 10px;'>"
                                    . "您今天的成长值已达峰值！</div>";
                        }
                        else if($inExpStatus['status'] == 1)
                        {
                            $growthMessage = "<div style='text-align:center;margin:0px 10px;'>"
                                    . "成长值+".$exp."</div>";
                        }*/

                        //清除今日刷新总量
                        $this->load->model('log_refresh');
                        $this->log_refresh->findTodayNumberByBrokerId( $uid , 1);
                    }

                    //今日剩余刷新量
                    $refresh_left = 0;
                    $refresh_left = intval($refresh_limit) - intval($refreshnum) - intval($sum) ;
                    if( $sum > 0 && $errornum == 0)
                    {
                        $page_text = '操作成功，共刷新了'.$sum.'条房源';
                        $page_text .= "，今日剩余刷新".$refresh_left."次。";
                        //$page_text .= $growthMessage;
                    }
                    else if($sum > 0 && $errornum > 0)
                    {
                        $page_text = '您成功刷新了'.$sum.'条房源，';
                        $page_text .= "今日剩余刷新".$refresh_left."次。";
                        //$page_text .= $growthMessage;
                    }
                    else if ($sum == 0 && $errornum > 0 && $refresh_left > 0)
                    {
                        $page_text = "对不起，您选定的房源今日刷新次数已经达到上限。";
                    }
                    else if($sum == 0 && $errornum > 0)
                    {
                        $page_text = '对不起，刷新超限';
                    }
                    else
                    {
                        $page_text = '刷新失败';
                    }
                }
                break;
            case 'multi_active_house':
                //房源编号
                $result = array(
                    'code' => 0,
                    'msg' => '执行成功！',
                    'msgs' => array()
                );

                //初始化房源操作类
                $this->load->model('sell_model');
                $this->load->model('block_model');
                $this->load->model('broker_model');
                $this->load->model('package_model');
                $this->load->model('sell_operate_model');
                $this->load->model('agency_model');
                $this->load->library('My_DB','','mydbback');
                $this->dbback = $this->mydbback->get_db_obj('dbback');
                $package = $this->package_model->find_by_id($package_id);
                $countSuccess = 0;


                //统一查询出房源信息
                $houseInfos = $this->dbback->where_in('id',$arr_id)->get('sell')->result_array();
                $houseInfos_new = array();
                foreach ($houseInfos as $key =>$val){
                    $houseInfos_new[$val['id']] = $val;
                }

                foreach ($arr_id as $key) {
                    $rowid = $key;
                    if (intval($rowid) > 0) {
                        $houseinfo = $houseInfos_new[$rowid];
                        if(!$houseinfo) {
                            $result['msgs'][$key] = '无此房源！';
                            continue;
                        }

                        //限制剩余时间大于0
//                        if(strtotime(date('Y-m-d')) - $houseinfo['expiretime'] >=0 ){
//                            $result['msgs'][$key] = '已过期！';
//                            continue;
//                        }

                        $re_houseinfo = $houseinfo;
                        $blockid = $re_houseinfo['blockid'];
                        $block_remove_limit_num = $this->block_model->get_block_remove_info_by_blockid($blockid);
                        if ($block_remove_limit_num) {
                            $publish_limit_num = $block_remove_limit_num;
                        } else {
                            $publish_limit_num = 10;
                        }

                        $price_start = $re_houseinfo['price'] * 0.95;
                        $price_end = $re_houseinfo['price'] * 1.05;

                        $buildarea_start = $re_houseinfo['buildarea'] - 0.5;
                        $buildarea_end = $re_houseinfo['buildarea'] + 0.5;
                        $room = $re_houseinfo['room'];
                        $hall = $re_houseinfo['hall'];
                        $toilet = $re_houseinfo['toilet'];

                        $subfloor = $re_houseinfo['subfloor'];
                        $floor = $re_houseinfo['floor'];
                        $totalfloor = $re_houseinfo['totalfloor'];

                        //查询房源条件
                        $cond_where = "uid = '" . $uid . "' AND esta = 1  AND infofrom = '5' and blockid ='$blockid' and subfloor='$subfloor'  and floor='$floor' and totalfloor='$totalfloor' and room='$room' and hall='$hall' and toilet='$toilet' and buildarea > '$buildarea_start' and buildarea < '$buildarea_end' and price> '$price_start' and price < '$price_end' ";

                        //符合条件的总行数
                        $broker_publish_total_count = $this->sell_model->find_count_by($cond_where, '0');

                        //添加限制重复房源发布
                        if ($broker_publish_total_count >= $publish_limit_num) {
                            $result['msgs'][$key] = '房源编号' . $key . '重复过多，禁止发布更多重复房源！';
                            continue;
                        }

                        //判断源活房源是否有否超过上限
                        $valid_house_num = $this->broker_model->valid_house_num();

                        //普通房源加1
                        $valid_house_num += 1;

                        if ($valid_house_num <= $package["package_valid_num"]) {
                            if (is_array($houseinfo) && !empty($houseinfo)) {
                                //加载房源急推属性类
                                $set_result = $this->sell_operate_model->active_house($rowid);

                                if ($set_result) {
                                    $relation_info = array();
                                    $relation_info = $this->agency_model->get_relation_by_agentcode($agentcode);
                                    $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
                                    $parentcode = '';
                                    if (is_array($relation_info) && !empty($relation_info)) {
                                        $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
                                    } else {
                                        $parentinfo = array();
                                        $select_array = array('parentcode');
                                        $this->agency_model->set_select_fields($select_array);
                                        $parentinfo = $this->agency_model->get_company_info_by_code($agentcode);
                                        $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
                                    }

                                    $tbl = 'sell';
                                    /***提交房源操作日志给MYSQL(经纪人日志查询),[$msg:3-房源再发布] ***/
                                    $this->sell_model->action_log($agentcode, $uid, $tbl, $rowid, 3);

                                    //加载中间件统计类
                                    $this->load->library('statistics');
                                    /***通过接口提交操作日志给中间件，operatetype 1:新增 2刷新 3删除 4失效 5再发布 ***/
                                    $this->statistics->sub_operatecount($uid, $agentcode, 5, $rowid, '', $tbl, $domain, $parentcode);

                                    $countSuccess++;
                                    $result['msgs'][$key] = '激活房源成功';
                                } else {
                                    $result['msgs'][$key] = '激活房源失败';
                                }
                            } else {
                                $result['msgs'][$key] = '房源信息不存在';
                            }
                        } else {
                            $result['msgs'][$key] = '有效房源已满';
                            break;
                        }
                    } else {
                        $result['msgs'][$key] = '参数错误';
                    }
                }
                $page_text = '操作成功！共成功激活：'.$countSuccess.'条房源！';
                if($_COOKIE['debug_xzk'] == 1){
                    echo '<pre>';
                    var_dump($result);
                    var_dump($countSuccess);
                    var_dump($houseInfos);
                    die;
                }
                break;
            }

            $this->jump( $referer , $page_text , 1000);
    }


    /**
     * 设置急推房源
     */
    public function house_tag_set()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();

        //验证房源编号和提交验证码
        if( intval($rowid) > 0 && md5('HOUSE365_TAG_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $houseinfo = $this->sell_model->find_by_id($rowid);

            if( is_array( $houseinfo ) && !empty($houseinfo)    )
            {
                //加载房源急推属性类
                $this->load->model('sell_tag_model');
                $this->sell_tag_model->set_houseinfo($houseinfo);

                //检查此房源是否符合设置急推房源的标准
                $result = $this->sell_tag_model->check_tag_standard();

                if( isset($result) && $result['is_ok'] == 1 )
                {
                    $set_result = $this->sell_tag_model->set_tag();

                    if($set_result)
                    {
                        $result['is_ok'] = 1;
                        $result['msg'] = '标签设置成功';

                        //清理已用标签个数缓存
                        $this->load->model('statistics_model');
                        $this->statistics_model->jtLabelCount( $uid , 1);
					    //清到期缓存 xue add 2015-04-25
						$this->load->model("house_tag_package_model");
						$this->house_tag_package_model->get_tag_valid($uid,1);
						$this->house_tag_package_model->get_tag_valid_num($uid,1);
                    }
                    else
                    {
                        $result['is_ok'] = 0;
                        $result['msg'] = '标签设置失败';
                    }
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 设置新房直售
     */
    public function house_nofee_set()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();

        //验证房源编号和提交验证码
        if( intval($rowid) > 0 && md5('HOUSE365_NOFEE_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $houseinfo = $this->sell_model->find_by_id($rowid);

            if( is_array( $houseinfo ) && !empty($houseinfo))
            {
                //加载房源急推属性类
                $this->load->model('sell_nofee_model');
                $this->sell_nofee_model->set_houseinfo($houseinfo);

                //检查此房源是否符合设置急推房源的标准
                $result = $this->sell_nofee_model->check_nofee_standard();

                if( isset($result) && $result['is_ok'] == 1 )
                {
                    $set_result = $this->sell_nofee_model->set_nofee();

                    if($set_result)
                    {
                        $result['is_ok'] = 1;
                        $result['msg'] = '新房直售标签设置成功';
                    }
                    else
                    {
                        $result['is_ok'] = 0;
                        $result['msg'] = '新房直售标签设置失败';
                    }
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 设置真房源房
     */
    public function house_real_set()
    {

        //房源编号
        $rowid = $this->input->post( 'rowid' , TRUE );
        $secret_key = $this->input->post( 'secret_key' , TRUE );
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0 && md5('HOUSE365_REAL_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];
            $this->load->model('real_house_model');
            $this->load->model('broker_model');



            $balance = $this->real_house_model->getBrokerRealHouseMoney($uid);//经纪人账号余额

            $realHouse      =$this->config->item('realHouse');  //是否开启真房源功能
            $realHouseMoney = $this->config->item('realHouseMoney'); //真房源价格

            $broker_info = $this->broker_model->get_broker_info_by_uid($uid);

            if(array_key_exists('real_status',$broker_info[0])){
                if($broker_info[0]['real_status']){
                    $realHouse = 1;
                }
            }
            if($realHouse!=1)
            {
                $result['is_ok'] = 0;
                $result['msg'] = '未开启放心看功能';
            }/*elseif($realHouseMoney!=$balance)
            {
                $result['is_ok'] = 0;
                $result['msg'] = '经纪人余额不足';
            }*/
            else
            {
                $package_id     =$this->user_arr['package_id'];
                $realnum_limit =$this->broker_model->get_realnum_by_packageid($package_id);
                if($realnum_limit==0)
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '套餐放心看暂未设置,请联系管理员';
                }else {

                    //保障金是否在冻结期内
                    $this->load->model('sell_model');
                    $isforzen = $this->sell_model->broker_real_frozen();
                    if(!$isforzen['code']){
                        $result['is_ok'] = 0;
                        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $isforzen['msg'] );
                        print_r(json_encode($result));
                        exit;
                    }


                    $this->load->model('real_house_model');
                    $realHouseNum= $this->real_house_model->getUidRealHouseNum($uid);

                    if($realHouseNum>=$realnum_limit)
                    {
                        $result['is_ok'] = 0;
                        $result['msg'] = '放心看标签数量已达上限，请先取消已勾选标签或升级您的套餐';
                    }else
                    {

                        $num_set  =$this->real_house_model->getUidRealHouseInfo($rowid);

                        if($num_set)
                        {
                            $result['is_ok'] = 0;
                            $result['msg'] = '已设置类似信息房源，请勿重复添加';
                        }else {

                            /*
                            $arr   =$this->real_house_model->getHousebuildingnum($rowid);

                            if(empty($arr[0]['buildingnum']) || empty($arr[0]['unitnum'])  || empty($arr[0]['roomnum']) )
                            {
                                $result['is_ok'] = 2;
                                $result['msg'] = $rowid;
                                $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
                                print_r(json_encode($result));
                                exit;
                            }*/
                            //操作原因是添加

                            //$realHouseNum = $this->real_house_model->insertReal_House_Set_log($uid, $rowid, 1, 1);
                            $result['url'] = $_SERVER['HTTP_ORIGIN']."/sell/modify/{$rowid}/";
                            $result['is_ok'] = 1;
                            $result['msg'] = '放心看设置成功';

                        }
                    }

                }
            }


        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 设置急推房源
     */
    public function house_tag_cancel()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_TAG_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $this->sell_model->set_select_fields(array('id','uid','esta','istag'));
            $houseinfo = $this->sell_model->find_by_id($rowid);

            if( is_array( $houseinfo ) && !empty($houseinfo)    )
            {
                //加载房源急推属性类
                $this->load->model('sell_tag_model');
                $this->sell_tag_model->set_houseinfo($houseinfo);
                $set_result = $this->sell_tag_model->remove_tag();

                if($set_result)
                {
                    $result['is_ok'] = 1;
                    $result['msg'] = '取消标签成功';
                }
                else
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '取消标签失败';
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 取消急推房源
     */
    public function house_nofee_cancel()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_NOFEE_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $this->sell_model->set_select_fields(array('id','uid','esta','istag'));
            $houseinfo = $this->sell_model->find_by_id($rowid);

            if( is_array( $houseinfo ) && !empty($houseinfo)    )
            {
                //加载房源急推属性类
                $this->load->model('sell_nofee_model');
                $this->sell_nofee_model->set_houseinfo($houseinfo);
                $set_result = $this->sell_nofee_model->remove_nofee();

                if($set_result)
                {
                    $result['is_ok'] = 1;
                    $result['msg'] = '取消新房直售标签成功';
                }
                else
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '取消新房直售标签失败';
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }

    /**
     * 设置真房源
     */
    public function ajax_rest_assured(){
        //房源编号
        $rowid = $this->input->post( 'rowid' , TRUE );
        $secret_key = $this->input->post( 'secret_key' , TRUE );

        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_REAL_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $this->sell_model->set_select_fields(array('id','uid','esta','istag'));
            $houseinfo = $this->sell_model->find_by_id($rowid);



            if( is_array( $houseinfo ) && !empty($houseinfo))
            {
                $this->load->model('real_house_model');
                $set_result =$this->real_house_model->insertReal_House_Set_log($uid, $rowid,1,1);
                $result['is_ok'] = 1;
                $result['msg'] = '设置放心看成功';
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 取消真房源
     */
    public function house_real_cancel()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );

        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_REAL_SET_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $this->sell_model->set_select_fields(array('id','uid','esta','istag'));
            $houseinfo = $this->sell_model->find_by_id($rowid);

            if( is_array( $houseinfo ) && !empty($houseinfo))
            {
                $this->load->model('real_house_model');
                $set_result =$this->real_house_model->insertReal_House_Set_log($uid, $rowid,0,2);
                $result['is_ok'] = 1;
                $result['msg'] = '取消放心看成功';
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }

    /**
     * 激活房源
     */
    public function active_house()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_ACTIVE_HOUSE_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];
            $package_id = $this->user_arr['package_id'];
			$agentcode = $this->user_arr['agentcode'];

			//初始化房源操作类
			$this->load->model('sell_model');
			$houseinfo = array();
			//$this->sell_model->set_select_fields(array('id','esta','is360'));
			$houseinfo = $this->sell_model->find_by_id($rowid);

            $this->load->model('broker_model');
            $this->load->model('package_model');
            $package = $this->package_model->find_by_id($package_id);


			//2016-2-25 zhou添加限制重复房源发布 -------- start ------------>
			$re_houseinfo = $this->sell_model->find_by_id($rowid);

			$blockid =$re_houseinfo['blockid'];
			$this->load->model('block_model');

			$block_remove_limit_num = $this->block_model->get_block_remove_info_by_blockid($blockid);
			if($block_remove_limit_num)
			{
				$publish_limit_num =$block_remove_limit_num;
			}
			else
			{
				$publish_limit_num =10;
			}

			$price_start		=$re_houseinfo['price']*0.95;
			$price_end  		=$re_houseinfo['price']*1.05;

			$buildarea_start	=$re_houseinfo['buildarea']-0.5;
			$buildarea_end		=$re_houseinfo['buildarea']+0.5;
			$room				=$re_houseinfo['room'];
			$hall				=$re_houseinfo['hall'];
			$toilet				=$re_houseinfo['toilet'];

			$subfloor			=$re_houseinfo['subfloor'];
			$floor				=$re_houseinfo['floor'];
			$totalfloor			=$re_houseinfo['totalfloor'];



			//查询房源条件
			$cond_where = "uid = '".$uid."' AND esta = 1  AND infofrom = '5' and blockid ='$blockid' and subfloor='$subfloor'  and floor='$floor' and totalfloor='$totalfloor' and room='$room' and hall='$hall' and toilet='$toilet' and buildarea > '$buildarea_start' and buildarea < '$buildarea_end' and price> '$price_start' and price < '$price_end' ";




			//符合条件的总行数
			$broker_publish_total_count = $this->sell_model->find_count_by($cond_where,'0');
			//echo $publish_limit_num."<br/>";
			//echo $broker_publish_total_count;die;
			if($broker_publish_total_count>=$publish_limit_num)
			{


				$broker_publish_data_info = $this->sell_model->find_all_by($cond_where);

				if(count($broker_publish_data_info)>$publish_limit_num)
				{
					$show_limit_num =$publish_limit_num;

				}
				else
				{
					$show_limit_num =count($broker_publish_data_info);
				}
				$str_show ="";
				for($i =0;$i<$show_limit_num;$i++)
				{
					$str_show .=$broker_publish_data_info[$i]['id'].',';
				}

				$str_show =rtrim($str_show,',');
				$result['is_ok'] = 5;
                $result['msg'] = '此房源与房源编号 '.$str_show . '重复，禁止发布更多重复房源！';
				$result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
				print_r(json_encode($result));

				exit;

			}


			//2016-2-25 zhou添加限制重复房源发布 -------- end ------------>

            //判断源活房源是否有否超过上限
            $valid_house_num = $this->broker_model->valid_house_num();

			//普通房源加1
			$valid_house_num += 1;

			//判断是否是360全景房源，360全景房源 = 2条普通房源
			/*if(!empty($houseinfo) && $houseinfo['is360'] == '2')
			{
				$valid_house_num += 1;
			}*/

            if($valid_house_num <= $package["package_valid_num"])
            {
                //初始化房源操作类
                //$this->load->model('sell_model');
                //$houseinfo = array();
                //$this->sell_model->set_select_fields(array('id','esta'));
                //$houseinfo = $this->sell_model->find_by_id($rowid);

                if( is_array( $houseinfo ) && !empty($houseinfo)    )
                {
                    //加载房源急推属性类
                    $this->load->model('sell_operate_model');
                    $set_result = $this->sell_operate_model->active_house($rowid);

                    if($set_result)
                    {
                        //加载门店类
                        $this->load->model('agency_model');
                        $relation_info = array();
                        $relation_info = $this->agency_model->get_relation_by_agentcode($agentcode);
                        $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
                        $parentcode = '';
                        if( is_array($relation_info) && !empty($relation_info))
                        {
                            $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
                        }
                        else
                        {
                            $parentinfo = array();
                            $select_array = array('parentcode');
                            $this->agency_model->set_select_fields($select_array);
                            $parentinfo = $this->agency_model->get_company_info_by_code($agentcode);
                            $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
                        }

                        $tbl = 'sell';
						/***提交房源操作日志给MYSQL(经纪人日志查询),[$msg:3-房源再发布] ***/
						$this->sell_model->action_log( $agentcode , $uid , $tbl , $rowid , 3);

                        //加载中间件统计类
                        $this->load->library('statistics');
                        /***通过接口提交操作日志给中间件，operatetype 1:新增 2刷新 3删除 4失效 5再发布 ***/
                        $this->statistics->sub_operatecount( $uid , $agentcode , 5 , $rowid , '' , $tbl , $domain , $parentcode );

                        $result['is_ok'] = 1;
                        $result['msg'] = '激活房源成功';
                    }
                    else
                    {
                        $result['is_ok'] = 0;
                        $result['msg'] = '激活房源失败';
                    }
                }
                else
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '房源信息不存在';
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '有效房源已满';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 删除房源
     */
    public function delete_house()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();

        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_DELETE_HOUSE_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

			//门店账号
			$agentcode = $this->user_arr['agentcode'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = array();
            $this->sell_model->set_select_fields(array('id','esta'));
            $houseinfo = $this->sell_model->find_by_id($rowid);

            if( is_array( $houseinfo ) && !empty($houseinfo)    )
            {
                //加载房源急推属性类
                $this->load->model('sell_operate_model');
                $set_result = $this->sell_operate_model->delete_house($rowid);

                if($set_result)
                {
                    //加载门店类
                    $this->load->model('agency_model');
                    $relation_info = array();
                    $relation_info = $this->agency_model->get_relation_by_agentcode($agentcode);
                    $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
                    $parentcode = '';
                    if( is_array($relation_info) && !empty($relation_info))
                    {
                        $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
                    }
                    else
                    {
                        $parentinfo = array();
                        $select_array = array('parentcode');
                        $this->agency_model->set_select_fields($select_array);
                        $parentinfo = $this->agency_model->get_company_info_by_code($agentcode);
                        $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
                    }

                    $tbl = 'sell';
                    //加载中间件统计类
                    $this->load->library('statistics');
                    /***通过接口提交操作日志给中间件，operatetype 1:新增 2刷新 3删除 4失效 5再发布 ***/
                    $this->statistics->sub_operatecount( $uid , $agentcode , 3 , $rowid , '' , $tbl , $domain , $parentcode );

                    /***提交房源操作日志给MYSQL(经纪人日志查询),[$msg:0-删除房源] ***/
                    $this->sell_model->action_log( $agentcode , $uid , $tbl , $rowid , 0);

                    $result['is_ok'] = 1;
                    $result['msg'] = '删除房源成功';
                }
                else
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '删除房源失败';
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '房源信息不存在';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }


    /**
     * 删除房源申诉
     */
    function house_appeal_delete()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $reason = $this->input->get( 'reason' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );

        $p_filenames = $this->input->get( 'p_filenames' , TRUE );
        $pics_arr =explode(',',substr($p_filenames,0,strlen($p_filenames)-1));
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_SELL_APPEAL_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            if ( $reason != "" )
            {
                $data_info = array();
                $reason = urldecode($reason);
                $data_info['appeal'] = iconv( "UTF-8" , "GBK" , $reason);
                $data_info['appealtime'] = time();
                $data_info['esta'] = 2;
                $data_pic_info['pics_arr']= $pics_arr;
                $this->load->model('sell_delete_model');
                $app_result = FALSE;
                $app_result = $this->sell_delete_model->house_appeal ( $rowid , $data_info);

                if(is_array($pics_arr) &&  $pics_arr[0])
                {
                    $pic_result = FALSE;
                    $pic_result = $this->sell_delete_model->house_pic_insert ( 'sell',$rowid , $data_pic_info);
                }
                else
                {
                    $pic_result = $this->sell_delete_model->house_pic_delete ('sell',$rowid);
                    $pic_result = TRUE;
                }
                if($app_result && $pic_result)
                {
                    houseOptions($uid,$rowid,4);

                    $result['is_ok'] = 1;
                    $result['msg'] = '申诉提交成功，工作人员会第一时间处理您的申诉';
                }
                else
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '提交失败，请致电客服热线';
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '请填写申诉理由';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }

    /**
     * 冻结房源申诉
     */
    function house_appeal()
    {
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $reason = $this->input->get( 'reason' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );

        $p_filenames = $this->input->get( 'p_filenames' , TRUE );
        $pics_arr =explode(',',substr($p_filenames,0,strlen($p_filenames)-1));
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_SELL_APPEAL_'.$rowid) == $secret_key )
        {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            if ( $reason != "" )
            {
                $data_info = array();
                $reason = urldecode($reason);
                $data_info['appeal'] = iconv( "UTF-8" , "GBK" , $reason);
                $data_info['appealtime'] = time();
                $data_info['esta'] = 2;
                $data_pic_info['pics_arr']= $pics_arr;
                $this->load->model('sell_freeze_model');
                $app_result = FALSE;
                $app_result = $this->sell_freeze_model->house_appeal ( $rowid , $data_info);
                if(is_array($pics_arr) &&  $pics_arr[0])
                {
                    $pic_result = FALSE;
                    $pic_result = $this->sell_freeze_model->house_pic_insert ( 'sell',$rowid , $data_pic_info);
                }
                else
                {
                    $pic_result = $this->sell_freeze_model->house_pic_delete ('sell',$rowid);
                    $pic_result = TRUE;
                }
                if($app_result && $pic_result)
                {

                    houseOptions($uid,$rowid,4);

                    $result['is_ok'] = 1;
                    $result['msg'] = '申诉提交成功，工作人员会第一时间处理您的申诉';
                }
                else
                {
                    $result['is_ok'] = 0;
                    $result['msg'] = '提交失败，请致电客服热线';
                }
            }
            else
            {
                $result['is_ok'] = 0;
                $result['msg'] = '请填写申诉理由';
            }
        }
        else
        {
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }




        /**
     * 房源申诉
     */
    function house_sys_appeal()
    {
        $date_time = date('Y-m-d H:i:s');
        //房源编号
        $rowid = $this->input->get( 'rowid' , TRUE );
        $reason = $this->input->get( 'reason' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );

		$p_filenames = $this->input->get( 'p_filenames' , TRUE );
		$pics_arr =explode(',',substr($p_filenames,0,strlen($p_filenames)-1));
		$p_filenames = implode(',',$pics_arr);
        $result = array();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0  &&  md5('HOUSE365_SELL_APPEAL_'.$rowid) == $secret_key )
        {
            if ( $reason != "" ) {
                $content = urldecode($reason);
                $content = iconv( "UTF-8" , "GBK" , $content);

                $appeal = array(
                    'city' => 'nj',
                    'id' => $rowid,
                    'content' => $content,
                    'attach' => $p_filenames,
                    'add_time' => $date_time,
                    'upd_time' => $date_time,
                );
                //print_r($appeal);die();
                //DAO::instance('sell_appeal')->add($appeal);//隐掉，20160822
                //print_r(db::$sqls);die();
				//====================20160822=================
				$sell_appeal = DAO::instance('sell_appeal','esfpublic','sell_appeal','id');
				$query_struct = array(
					'where' => array(
						'city' => 'nj',
						'id'   => $rowid
					),
				);

				$appeal_info = $sell_appeal->get($query_struct);
				if($appeal_info){
					$appeal['result'] = 0;
					unset($appeal['city']);
					unset($appeal['id']);
					//$sell_appeal->edit($appeal);
					$sql = update_sql('sell_appeal',$appeal,"where city='nj' and id=".$rowid);
					$sell_appeal->_db()->save($sql);
				}else{
					$this->sell_model->set_select_fields(array('uid'));
					$houseInfo = $this->sell_model->find_by_id($rowid);

					$appeal['uid'] = '0';
					if(!empty($houseInfo))
					{
						$appeal['uid'] = $houseInfo['uid'];
					}

					$sell_appeal->add($appeal);
				}
				//====================20160822=================

                $result['is_ok'] = 1;
                $result['msg'] = '申诉提交成功，工作人员会第一时间处理您的申诉';
				//$result['msg'] = $sql;
            }else{
                $result['is_ok'] = 0;
                $result['msg'] = '请填写申诉理由';
            }
        }else{
            $result['is_ok'] = 0;
            $result['msg'] = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $result['msg'] );
        print_r(json_encode($result));
        exit;
    }

    /**
     * 根据表单提交参数，获取查询条件
     */
    private function _get_cond_str( $form_param )
    {
        $cond_where = '';

        //房源类型
        if( isset($form_param['infotype']) && !empty($form_param['infotype']) )
        {
           $cond_where .= " AND infotype = '".intval($form_param['infotype'])."'";
        }

        //房源价格参数
        if ( isset($form_param["price_sell"]) && !empty($form_param["price_sell"]) )
        {
            switch($form_param["price_sell"])
            {
                case 1:
                    $cond_where .= " AND price <= '40' ";
                    break;
                case 2:
                    $cond_where .= " AND price > '40' and price <= '60' ";
                    break;
                case 3:
                    $cond_where .= " AND price > '60' and price <= '90' ";
                    break;
                case 4:
                    $cond_where .= " AND price > '90' and price <= '120' ";
                    break;
                case 5:
                    $cond_where .= " AND price > '120' and price <= '150' ";
                    break;
                case 6:
                    $cond_where .= " AND price > '150' and price <= '200' ";
                    break;
                case 7:
                    $cond_where .= " AND price > '200' and price <= '300' ";
                    break;
                case 8:
                    $cond_where .= " AND price > '300' and price <= '500' ";
                    break;
                case 9:
                    $cond_where .= " AND price > '500'";
                    break;
            }
        }

        //面积条件
        if (isset($form_param["buildarea"]) && !empty($form_param["buildarea"]))
        {
            switch($form_param["buildarea"])
            {
                case 1:
                    $cond_where .= " AND buildarea <= '40' ";
                    break;
                case 2:
                    $cond_where .= " AND buildarea > '40' AND buildarea <= '60' ";
                    break;
                case 3:
                    $cond_where .= " AND buildarea > '60' AND buildarea <= '80' ";
                    break;
                case 4:
                    $cond_where .= " AND buildarea > '80' AND buildarea <= '100' ";
                    break;
                case 5:
                    $cond_where .= " AND buildarea > '100' AND buildarea <= '120' ";
                    break;
                case 6:
                    $cond_where .= " AND buildarea > '120' AND buildarea <= '144' ";
                    break;
                case 7:
                    $cond_where .= " AND buildarea > '144'  AND  buildarea <= '200' ";
                    break;
                case 8:
                    $cond_where .= " AND buildarea > '200'  AND  buildarea <= '400' ";
                    break;
                case 9:
                    $cond_where .= " AND buildarea > '400' ";
                    break;
            }
        }

        //房型条件
        if (isset($form_param['roomtype']) && !empty($form_param['roomtype']))
        {
            switch ($form_param['roomtype'])
            {
              case 1:
                    $cond_where .= " AND  room = '1'";
                    break;
              case 2:
                    $cond_where .= " AND   room = '2' ";
                    break;
              case 3:
                    $cond_where .= " AND  room = '3' ";
                    break;
              case 4:
                    $cond_where .= " AND  room = '4' ";
                    break;
              case 5:
                    $cond_where .= " AND  room = '5' ";
                    break;
			case 6:
                    $cond_where .= " AND  room > '5' ";
                    break;
            }
        }

        //关键词条件
        if (isset($form_param['keywords']) && !empty($form_param['keywords']) && $form_param['k_id'])
        {
            $keyword = trim(strip_tags($form_param['keywords']));
            switch ($form_param['k_id'])
            {
                case 1:
                    $cond_where .= " AND blockshowname LIKE '%".$keyword."%'";
                    break;
                case 2:
                    $cond_where .= " AND id = '".$keyword."'";
                    break;
                case 3:
                    $cond_where .= " AND ownid = '".$keyword."'";
                    break;
            }
        }

		//小区编号
		if (isset($form_param['blockid']) && !empty($form_param['blockid']) && $form_param['blockid'] > 0)
        {
			$blockid = intval($form_param['blockid']);
			$cond_where .= " AND blockid = '".$blockid."'";
		}

        //全部房源条件
        if ( isset($form_param['roomcategory']) && !empty($form_param['roomcategory']) )
        {
            switch ($form_param['roomcategory'])
            {
                case 1:
                    $cond_where .= ' AND  isstar = 0 ';
                    break;
                case 2:
                    $cond_where .= ' AND  isstar = 3 ';
                    break;
                case 3:
                    $cond_where .= ' AND  istag = 1 ';
                    break;
                case 4:
                    $cond_where .= ' AND  isreal = 1 ';
                    break;
                case 5: //新房直售
                    $cond_where .= ' AND  nofee = 1 ';
                    break;
				case 6: //全景房
                    $cond_where .= ' AND  is360 = 2 ';
                    break;
                case 7: //放心看
                    $cond_where .= ' AND  is_real_house = 1 ';
                    break;
                case 8: //VR
                    $cond_where .= ' AND  is_real_house = 1 AND vr_model_id !="" AND vr_model_id !="vr_id_empty" ';
                    break;
            }
        }
        return $cond_where;
    }


    //获取排序字符串
    private function _get_orderby_arr( $order_val )
    {
        $arr_order = array();

        switch ($order_val)
        {
            case 1:
                $arr_order['order_key'] = 'updatetime' ;
                $arr_order['order_by'] = 'DESC';
                break;
            case 2:
                $arr_order['order_key'] = 'updatetime' ;
                $arr_order['order_by'] = 'ASC';
                break;
            case 3:
                $arr_order['order_key'] = 'creattime' ;
                $arr_order['order_by'] = 'DESC';
                break;
            case 4:
                $arr_order['order_key'] = 'creattime' ;
                $arr_order['order_by'] = 'ASC';
                break;
            case 5:
                $arr_order['order_key'] = 'price' ;
                $arr_order['order_by'] = 'ASC';
                break;
            case 6:
                $arr_order['order_key'] = 'price' ;
                $arr_order['order_by'] = 'DESC';
                break;
            case 7:
                $arr_order['order_key'] = 'buildarea' ;
                $arr_order['order_by'] = 'ASC';
                break;
            case 8:
                $arr_order['order_key'] = 'buildarea' ;
                $arr_order['order_by'] = 'DESC';
                break;
            default:
                $arr_order['order_key'] = 'updatetime' ;
                $arr_order['order_by'] = 'DESC';
        }

        return $arr_order;
    }


    /**
     * 加载swfupload上传文件组件
     */
    public function swf_upload()
    {
        $this->load->view('pic_inc');
    }

	/**
     *	AJAX获取微信二维码信息
	 *
	 *
	 */
	public function get_ajax_wechat_image()
	{
		$this->load->model('wechat_model');
		$result = $this->wechat_model->get_wechat_info($this->_city);

		$result['status'] = 200;
		$result['wechat_cache_key'] = iconv('GBK','UTF-8',$result['wechat_cache_key']);

		exit(json_encode($result));
	}

	/**
     * 获取查房价
	 *
	 */
	public function getHousePrice()
	{
		$result = array('status' => 0,'data' => '','msg' => '');


		if(empty($_GET['blockId']))
		{
			$result['msg'] = iconv('gbk','utf-8','blockId参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['blockName']))
		{
			$result['msg'] = iconv('gbk','utf-8','blockName参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['buildArea']))
		{
			$result['msg'] = iconv('gbk','utf-8','buildArea参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['floor']))
		{
			$result['msg'] = iconv('gbk','utf-8','floor参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['forward']))
		{
			$result['msg'] = iconv('gbk','utf-8','forward参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['livingRoom']))
		{
			$result['msg'] = iconv('gbk','utf-8','livingRoom参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['room']))
		{
			$result['msg'] = iconv('gbk','utf-8','room参数不正确');
			exit(json_encode($result));
		}

		if(empty($_GET['totalFloor']))
		{
			$result['msg'] = iconv('gbk','utf-8','totalFloor参数不正确');
			exit(json_encode($result));
		}


		$argumentData = array(
			'blockId' => intval($_GET['blockId']),
			'blockName' => iconv('utf-8','gbk',$_GET['blockName']),
			'buildArea' => intval($_GET['buildArea']),
			'city' => GB_CITY,
			'floor' => intval($_GET['floor']),
			'totalFloor' => intval($_GET['totalFloor']),
			'forward' => iconv('utf-8','gbk',$_GET['forward']),
			'livingRoom' => intval($_GET['livingRoom']),
			'room' => intval($_GET['room'])
		);
		$this->load->model('house_publish_rule_model');
		$data = $this->house_publish_rule_model->getHousePrice($argumentData);
		if(!empty($data))
		{
			$data = json_decode($data,true);
			$result['status'] = '200';
			$result['data'] = $data;
		}

		exit(json_encode($result));
	}

	/**
	 * 检查发布房源过滤规则
	 *
	 */
	public function checkHousePublishRule($fields_values = array(), $is_change_price=0)
	{
		$result = array(
			'suspected_sham_status' => false,    //疑似虚假状态
            'suspected_sham_status2' => false,   //疑似虚假状态2
			'system_intercept_status' => false   //系统拦截状态
		);

		//跳转地址
		$url = '/sell/manage/active/';

		//房源类型发布规则
		$this->load->model('house_publish_rule_model');

		$houseRuleData = $this->house_publish_rule_model->getHouseRuleOneData(array("type" => "type='1'"));

		//正常发布范围
		$publish_range = array();
		if(!empty($houseRuleData['publish_range']))
		{
			$publish_range = unserialize($houseRuleData['publish_range']);
		}

		//系统拦截范围
		$system_intercept_range = array();
		if(!empty($houseRuleData['system_intercept_range']))
		{
			$system_intercept_range = unserialize($houseRuleData['system_intercept_range']);
		}

		//疑似虚假价格范围
		$suspected_sham_range = array();
		if(!empty($houseRuleData['suspected_sham_range']))
		{
			$suspected_sham_range = unserialize($houseRuleData['suspected_sham_range']);
		}

        //疑似虚假价格范围
        $suspected_sham_range2 = array();
        if(!empty($houseRuleData['suspected_sham_range2']))
        {
            $suspected_sham_range2 = unserialize($houseRuleData['suspected_sham_range2']);
        }

		//禁止发布范围
		$ban_publish_range = array();
		if(!empty($houseRuleData['ban_publish_range']))
		{
			$ban_publish_range = unserialize($houseRuleData['ban_publish_range']);
		}

		//房源类型发布规则
		$this->load->model('house_publish_rule_model');

		//获取小区查房价
		$blockHousePriceData = $this->house_publish_rule_model->getHousePrice(array(
			'blockId' => $fields_values['blockid'],
			'blockName' => $fields_values['blockshowname'],
			'buildArea' => $fields_values['buildarea'],
			'city' => GB_CITY,
			'floor' => $fields_values['floor'],
			'forward' => $fields_values['forward'],
			'livingRoom' => $fields_values['room'],
			'room' => $fields_values['hall'],
			'totalFloor' => $fields_values['totalfloor']
		));

		$blockHouseAverprice = 0;
		if(!empty($blockHousePriceData))
		{
			$blockHousePriceData = json_decode($blockHousePriceData,true);

			$blockHouseAverprice = $blockHousePriceData['averprice'];
		}

		//$averprice = round((($fields_values['price'])/$fields_values['buildarea']),1)*10000;

		$averprice = ($fields_values['price']/$fields_values['buildarea'])*10000;

		if(!empty($blockHouseAverprice))
		{
			//$priceRatio = round(($averprice - $blockHouseAverprice)/$blockHouseAverprice,1);

			$priceRatio = ($averprice - $blockHouseAverprice)/$blockHouseAverprice;

			//判断是否疑似虚假房源
			if(!empty($suspected_sham_range))
			{
				if(($suspected_sham_range[0]['min']/100) <= $priceRatio && ($suspected_sham_range[0]['max']/100) > $priceRatio)
				{
					$result['suspected_sham_status'] = true;
				}

				if(($suspected_sham_range[1]['min']/100) < $priceRatio && ($suspected_sham_range[1]['max']/100) >= $priceRatio)
				{
					$result['suspected_sham_status'] = true;
				}
			}

            //判断是否疑似虚假房源2
			if(!empty($suspected_sham_range2))
            {
                if(($suspected_sham_range2[0]['min']/100) <= $priceRatio && ($suspected_sham_range2[0]['max']/100) > $priceRatio)
                {
                    $result['suspected_sham_status'] = true;
                    $result['suspected_sham_status2'] = true;
                }
                elseif(($suspected_sham_range2[1]['min']/100) < $priceRatio && ($suspected_sham_range2[1]['max']/100) >= $priceRatio)
                {
                    $result['suspected_sham_status'] = true;
                    $result['suspected_sham_status2'] = true;
                }

                //判断房源占比
                if(!empty($result['suspected_sham_status2']) && empty($is_change_price) )
                {
                    if(!empty($fields_values['id']))
                    {
                        $uid = $this->user_arr['uid'];
                        $this->load->model('house_publish_rule_log_model');
                        $housePublishRuleLogData = $this->house_publish_rule_log_model->getRow($fields_values['id'], 1) ;

                        if(empty($housePublishRuleLogData))
                        {
                            $total = $this->house_publish_rule_log_model->getBrokerHousePublishRuleTotal($uid, 3) + 1;
                            if (!empty($houseRuleData['house_ratio']) && ($total / $this->user_arr['postlimit']) > ($houseRuleData['house_ratio']/100))
                            {
                                $this->jump($url, "禁止发布房源", 3000);
                                exit;
                            }
                        }
                    }
                    else
                    {
                        $uid = $this->user_arr['uid'];
                        $this->load->model('house_publish_rule_log_model');
                        $total = $this->house_publish_rule_log_model->getBrokerHousePublishRuleTotal($uid, 3) + 1;

                        if (!empty($houseRuleData['house_ratio']) && ($total / $this->user_arr['postlimit']) > ($houseRuleData['house_ratio']/100))
                        {
                            $this->jump($url, "禁止发布房源", 3000);
                            exit;
                        }
                    }
                }
            }

			//判断系统拦截房源
			if(!empty($system_intercept_range))
			{
				if(($system_intercept_range[0]['min']/100) <= $priceRatio && ($system_intercept_range[0]['max']/100) > $priceRatio)
				{
					$result['system_intercept_status'] = true;
				}

				if(($system_intercept_range[1]['min']/100) < $priceRatio && ($system_intercept_range[1]['max']/100) >= $priceRatio)
				{
					$result['system_intercept_status'] = true;
				}
			}

			//判断禁止发布房源
			if(!empty($ban_publish_range))
			{
				if(($ban_publish_range[0]['max']/100) > $priceRatio || ($ban_publish_range[1]['min']/100) < $priceRatio)
				{
                    if( empty($is_change_price) ){
                        $this->jump($url, "禁止发布房源", 3000);
                        exit;
                    }else{
                        $result['system_intercept_status'] = true;
                    }
				}
			}
		}
		elseif((!empty($suspected_sham_range) || !empty($suspected_sham_range2)) && $fields_values['averprice'] >= 500 && $fields_values['averprice'] <= 350000)
		{
			$result['suspected_sham_status'] = true;
		}

		//判断是否系统拦截
		/*if($system_intercept_status)
		{
			$fields_values['esta'] = '51';
		}*/

		return $result;
	}

	//判断是否全景图片上传权限
	private function getPanoramaStatus()
	{
		$result = true;

		$functionSwitch = $this->config->item('functionSwitch');
		if(!empty($functionSwitch['panorama']))
		{
			//全景图片上传权限
			$this->load->model('panorama_pic_violation_total_model');

			return $this->panorama_pic_violation_total_model->getPanoramaStatus($this->user_arr['uid']);
		}

		return $result;
	}

	/**
     * 获取经纪人的有效房源
     *
     */
	public function getValidHouseTotal()
    {
        $result = array();

        $uid = $this->user_arr['uid'];
        $result['postlimit'] = $this->user_arr['postlimit'];

        $this->load->model('house_publish_rule_log_model');

        if(!empty($_GET['id']))
        {
            $housePublishRuleLogData = $this->house_publish_rule_log_model->getRow($_GET['id'], 1) ;

            if(empty($housePublishRuleLogData))
            {
                $result['total'] = $this->house_publish_rule_log_model->getBrokerHousePublishRuleTotal($uid, 3) + 1;
            }
        }
        else
        {
            $result['total'] = $this->house_publish_rule_log_model->getBrokerHousePublishRuleTotal($uid, 3) + 1;
        }

        exit(json_encode($result));
    }

    public function getHouseInfo(){
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );
        $result = array();

        //验证房源编号和提交验证码
        if( intval($rowid) > 0 ) {
            //经纪人账号uid
            $uid = $this->user_arr['uid'];

            //初始化房源操作类
            $this->load->model('sell_model');
            $houseinfo = $this->sell_model->getHouseInfo($rowid);

            if($houseinfo){
                $houseinfo = $this->gbk2utf8($houseinfo);
                $result['code'] = 1;
                $result['msg'] = '获取成功';
                $result['houseInfo'] = $houseinfo;

            }else{
                $result['code'] = 0;
                $result['msg'] = '无效房源';
            }

        }else{
            $result['code'] = 0;
            $result['msg'] = '参数错误';
        }
        echo json_encode($result);
        die;
    }

    function vrapplay(){
        $rowid = $this->input->post( 'hid' , TRUE );
        $data = $this->input->post();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0 ) {
            //初始化房源操作类
            $this->load->model('vr_model');
            $vra = $this->vr_model->vr_applay($data);
            echo json_encode($vra);
            die;

        }
        $result['result'] = 0;
        $result['msg'] = '参数错误';
        echo json_encode($result);
        die;
    }

    /**
     * 取消vr预约
     */
    public function cancle_vr(){
        $rowid = $this->input->post( 'hid' , TRUE );
        $data = $this->input->post();
        if( intval($rowid) > 0 ) {
            //初始化房源操作类
            $this->load->model('vr_model');
            $vra = $this->vr_model->cancle_vr($data);
            echo json_encode($vra);
            die;
        }
        $result['result'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->gbk2utf8($result);

        echo json_encode($result);
        die;
    }


    public function check_vr(){
        $rowid = $this->input->post( 'rowid' , TRUE );
        if( intval($rowid) > 0 ) {
            $post = $this->input->post();
            //初始化房源操作类
            $this->load->model('sell_model');
            $vra = $this->sell_model->check_vr($post);
            $vra = $this->gbk2utf8($vra);
            echo json_encode($vra);
            die;

        }
        $result['result'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->gbk2utf8($result);

        echo json_encode($result);
        die;
    }

    public function check_bind(){
        $rowid = $this->input->post( 'rowid' , TRUE );
        if( intval($rowid) > 0 ) {
            $post = $this->input->post();
            //初始化房源操作类
            $this->load->model('sell_model');
            $vra = $this->sell_model->check_bind($post);
            $vra = $this->gbk2utf8($vra);
            echo json_encode($vra);
            die;

        }
        $result['code'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->gbk2utf8($result);

        echo json_encode($result);
        die;
    }

    /*
     * vr绑定前验证
     */
    public function check_vr_new(){
        $rowid = $this->input->post( 'hid' , TRUE );
        if( intval($rowid) > 0 ) {
            $post = $this->input->post();
            //初始化房源操作类
            $this->load->model('vr_model');
            $vra = $this->vr_model->check_vr_new($post);
            echo json_encode($vra);
            die;

        }
        $result['result'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->gbk2utf8($result);

        echo json_encode($result);
        die;
    }
    /**
     * 中文 转码
     * @param $data
     * @return array|string
     */
    function gbk2utf8($data){

        foreach ($data as $k=>$v){
            $data[$k] = iconv('gbk','utf-8',$v);
        }
        return $data;
    }

    function curl_get_contents($str, $t_url='', $proxy='') {
        $ch = curl_init();
        $t_url = $t_url ? $t_url : 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        if ($proxy) curl_setopt($ch, CURLOPT_PROXY, $proxy);
        curl_setopt($ch, CURLOPT_URL, $str);
        curl_setopt($ch, CURLOPT_REFERER, $t_url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

        $str = curl_exec($ch);
        curl_close($ch);
        return $str;
    }

    //快速调价
    public function change_price()
    {
        $hid   = $this->input->get('hid', true);
        $price = $this->input->get('price', true);

        $this->load->model('broker_model');
        $this->broker_model->get_user_session();
        $uid = $this->user_arr['uid'];

        if(empty($hid) || empty($price)){
            echo json_encode(array('result'=>0, 'msg'=>iconv('gb2312','utf-8','调价失败') ));
            exit();
        }
        //查找有无此房源记录，没有则转到列表页
        $house = $this->sell_model->find_by_uid_id($uid, $hid);
        if (!$house) {
            echo json_encode(array('result'=>0, 'msg'=>iconv('gb2312','utf-8','房源不存在')));
            exit();
        }

        $old_price = $house['price'];
        $new_price = $old_price+$price;
        if($new_price<0){
            echo json_encode(array('result'=>0, 'msg'=>iconv('gb2312','utf-8','调整后价格不能低于0') ));
            exit();
        }

        $house['price'] = $new_price;
        $checkRule = $this->checkHousePublishRule($house,1);
        if($checkRule['system_intercept_status'] || $checkRule['suspected_sham_status'] || $checkRule['suspected_sham_status2']) {
            echo json_encode(array('result'=>0, 'msg'=>iconv('gb2312','utf-8','您的价格过高或过低，调价失败')));
            exit();
        }
        $averprice = round(10000 * $new_price / $house['buildarea'], 2);
        $this->sell_model->update(array('price'=>$new_price,'averprice'=>$averprice), $hid, $uid);
        echo json_encode(array('result'=>1, 'msg'=>iconv('gb2312','utf-8','调价成功')));
    }


	/*
	 * 设置放心看
	 */
    public function setRealHouse(){

    	$house_id = $this->input->post('house_id');
    	$this->load->model('zsb_api_model');
    	$re = $this->zsb_api_model->getRequrstData('setRealHouse',array('house_id'=>$house_id));
	    echo json_encode($re);die;
    }

	/*
	 * 取消放心看
	 */
    public function cancleRealHouse(){
	    $house_id = $this->input->post('house_id');
	    $this->load->model('zsb_api_model');
	    $re = $this->zsb_api_model->getRequrstData('cancleRealHouse',array('house_id'=>$house_id));
	    echo json_encode($re);die;
    }

    //冻结房源删除
    public function house_frozen_del()
    {
        $rowid = $this->input->get( 'rowid' , TRUE );
        $secret_key = $this->input->get( 'secret_key' , TRUE );

        if( intval($rowid) > 0  &&  md5('HOUSE365_SELL_APPEAL_'.$rowid) == $secret_key )
        {
            $uid = $this->user_arr['uid'];
            $agentcode = $this->user_arr['agentcode'];

            /*** 1、删除房源 ***/
            $delete_num = 0;
            $this->load->model('sell_operate_model');
            $delete_num = $this->sell_operate_model->delete_house($rowid);
            if( $delete_num > 0 )
            {
                //加载中间件统计类
                $this->load->library('statistics');

                //加载门店类
                $this->load->model('agency_model');
                $relation_info = array();
                $relation_info = $this->agency_model->get_relation_by_agentcode($agentcode);
                $domain = isset($relation_info['cat_id']) ? $relation_info['cat_id'] : 0;
                $parentcode = '';
                if( is_array($relation_info) && !empty($relation_info)) {
                    $parentcode = isset($relation_info['parentcode']) ? $relation_info['parentcode'] : '';
                }else{
                    $parentinfo = array();
                    $select_array = array('parentcode');
                    $this->agency_model->set_select_fields($select_array);
                    $parentinfo = $this->agency_model->get_company_info_by_code($agentcode);
                    $parentcode = isset($parentinfo['parentcode']) ? $parentinfo['parentcode'] : '';
                }
                /*** 4、通过接口提交操作日志给中间件，operatetype 1:新增 2刷新 3删除 4失效 5再发布 ***/
                $this->statistics->sub_operatecount( $uid , $agentcode , 3 , $rowid , '' , 'sell' , $domain , $parentcode );
                /*** 5、提交房源操作日志给MYSQL(经纪人日志查询),[$msg:4-失效房源] ***/
                $this->sell_model->action_log( $agentcode , $uid , 'sell' , $rowid , 0);

                $result['is_ok'] = 1;
                $msg = '操作成功';
            }else{
                $result['is_ok'] = 0;
                $msg = '删除房源失败。';
            }
            /** 删除结束 **/

        } else {
            $result['is_ok'] = 0;
            $msg = '参数错误';
        }

        $result['msg'] = iconv( 'gb2312' , 'utf-8',  $msg );
        echo json_encode($result);
        exit;
    }

}
/* End of file sell.php */
/* Location: ./application/zsb/controllers/sell.php */