<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Sell_star_base_model CLASS
 *
 * 出售多图管理类
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          xz
 */

//加载父类
load_m("sell_attr_model");

class Sell_star_base_model extends Sell_attr_model {
    
    /**
     * 多图标识对应值
     * @var const
     */
    const  ISSTAR_VALUE = 3;
    
    /**
     * 类初始化
     */
    public function __construct() 
    {
        parent::__construct();
    }
    
    /**
     * 返回多图标志值
     */
    public function get_isstar_value()
    {
        return self::ISSTAR_VALUE;
    }
    
    
    /**
     * 判断房源是否为多图房源
     *
     * @access	public
     * @return	boolean   是否为多图房源
     */
    public function is_star()
    {   
        $is_star = FALSE;
        
        $house_info = $this->init_houseinfo();
        
        if( is_array( $house_info ) && !empty( $house_info ) )
        {
            $is_star = self::ISSTAR_VALUE == $house_info['isstar'] 
                    ? TRUE : FALSE;
        }
        
        return $is_star;
    }
    
    
    /**
     * 设置多图房源
     *
     * @access  protected
     * @return  boolean  是否设置成功
     */
    public function set_star()
    {   
        $result = FALSE;
        
        $house_info = $this->init_houseinfo();
        $row_id = intval($house_info['id']);
        
        if( $row_id > 0 )
        {   
            $update_info = array();
            
            //需要设置的房源属性值
            $update_info['isstar'] = self::ISSTAR_VALUE;
            
            //设置多图房源
            $result = $this->update_house_atrr_val( $update_info , $row_id );
        }
        
        return $result;
    }
    
    
    /**
     * 去除多图房源属性
     *
     * @access  public
     * @return  boolean  是否设置成功
     */
    public function remove_star()
    {   
        $result = FALSE;
        
        $house_info = $this->init_houseinfo();
        $rowid = intval($house_info['id']);
        
        if( $rowid > 0 )
        {   
            $update_info = array();
            
            //需要设置的房源属性值
            $update_info['isstar'] = 0;
            
            //设置多图房源
            $result = $this->update_house_atrr_val( $update_info , $rowid );
        }
        
        return $result;
    }
    
    
    /**
     * 检测是房源是否符合多图房源标准
     *
     * @access  protected
     * @return  boolean  是否符合多图房源标准
     */
    public function check_star_standard()
    {   
        $tbl = 'sell';
        $is_star = FALSE;
      
        $houseinfo = $this->init_houseinfo();
        
        //1、必须是收费经纪人并且有经纪人头像
        $this->load->model('broker_model');
        
        $this->broker_model->set_uid($houseinfo['uid']);
        $broker_info = $this->broker_model->get_broker_info();
        
        if($broker_info['smallphoto'] == '')
        {
            return $is_star;
        }
         
        //2、房源标题20字及以上
        if( strlen( $houseinfo['address'] ) < 20)
        {
            return $is_star;
        }
        
        //3、房源描述字数限制
        if( strlen( $houseinfo['remark'] ) < 60 )
        {
            return $is_star;
        }

        //4、张以上房源图片个数限制
        $pic_info = array();
        $this->load->model('pic_model');
        $pic_info = $this->pic_model->find_house_pic_by($tbl , $houseinfo['id']);
        
        //室内图
        $pic_indoor = 0;
        //外景图
        $pic_outdoor = 0;
        //户型图
        $pic_layout = 0;
        
        if( is_array( $pic_info ) && isset( $pic_info ) )
        {   
            $pic_num = count( $pic_info );
            
            for($i = 0 ; $i < $pic_num ; $i ++ )
            {   
                if( $pic_info[$i]['sort'] == 2 )//室内
                {
                    $pic_indoor ++ ;
                }  
                else if ( $pic_info[$i]['sort'] == 1 )//外景图
                {
                    $pic_outdoor ++;
                }
                else if( $pic_info[$i]['sort'] == 0 )//户型图
                {
                    $pic_layout ++;
                }
            }
        }
        
        if( $houseinfo['infotype'] == 1)
        {
			if(GB_CITY=='nj')
			{
				$pic_indoor_limit = 5;
			}
			else
			{
				$pic_indoor_limit = 3;
			}
			$pic_outdoor_limit = 1;
			$pic_layout_limit = 1;
        }
        else
        {
            $pic_indoor_limit = 3;
			$pic_outdoor_limit = 0;
			$pic_layout_limit = 0;
        }
        //配置文件通用化，便于建站
        $cityArr = array('nj','hf','wx','wlmq');
        /*
		if(GB_CITY=='wh'  || GB_CITY=='mianyang' || GB_CITY=='dz' || GB_CITY=='jx' || GB_CITY=='ph' || GB_CITY=='tx')
		{
        */
        if(!in_array(GB_CITY,$cityArr)){
			$pic_indoor_limit = 3;
			$pic_outdoor_limit = 0;
			$pic_layout_limit = 0;
		}
        
        if( $pic_indoor >= $pic_indoor_limit && $pic_outdoor >= $pic_outdoor_limit && $pic_layout >= $pic_layout_limit)
        {
            $is_star = TRUE;
        }
        
        return $is_star;
    }
}
/* End of file sell_attr_base_model.php */
/* Location: ./applications/models/sell_attr_base_model.php */