<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * zsb
 *
 * 房源基础类
 *
 * @package         zsb
 * @author          EllisLab Dev Team
 * @copyright      Copyright (c) 2006 - 2014, HOUSE365, Inc.
 * @link            http://nj.sell.house.com
 * @since           Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Sell_operate_model CLASS
 *
 * 房源操作类，封装房源操作(失效、冻结、删除、再发布……)方法
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          xz
 */
class Sell_operate_model extends MY_Model {
    
    /**
     * 房源状态数组
     * @var string 
     */
    private $_house_esta = array();
    
    //构造函数
    public function __construct() 
    {   
        parent::__construct(1,1,1);
        //加载房源类
        $this->load->model('sell_base_model');
        $this->_house_esta = $this->sell_base_model->get_house_esta();
    }
    
    /**
     * 失效房源
     *
     * @access  public
     * @param   mixed $rowids 房源编号（单个房源编号为整数，多个为数组格式）
     * @return  int   影响行数
     */
    public function invalid_house($rowids)
    {
        $invalid_num = 0;
        
        if( !empty($rowids) )
        {   
            if(is_array($this->_house_esta) && isset($this->_house_esta['invalid']))
            {    
                //更新字段
                $update_data  = array();
                $update_data['esta'] =  $this->_house_esta['invalid'];
                //失效房源
                $invalid_num = $this->sell_base_model->update( $update_data , $rowids );
            }
        }
        
       return $invalid_num;
    }
    
    
    /**
     * 删除房源
     *
     * @access  protected
     * @param   mixed $rowids 房源编号（单个房源编号为整数，多个为数组格式）
     * @return  boolean  删除是否成功
     */
    public function delete_house($rowids)
    {   
        if( !empty($rowids) )
        {
            $result_delete = 0;
            if(is_array($this->_house_esta) && isset($this->_house_esta['delete']))
            {    
                //更新字段
                $update_data  = array();
                $update_data['esta'] =  $this->_house_esta['delete'];

                //失效房源
                $result_delete = $this->sell_base_model->update( $update_data , $rowids );
            }
        }
        
       return $result_delete;
    }
    
    
    /**
     * 冻结房源
     *
     * @access  protected
     * @param   mixed $rowids 房源编号（单个房源编号为整数，多个为数组格式）
     * @return  boolean  删除是否成功
     */
    public function freeze_house($rowids)
    {   
        $result = FALSE;
        
        if( !empty($rowids) )
        {
            $result_invalid = 0;
            if(is_array($this->_house_esta) && isset($this->_house_esta['frozen']))
            {    
                //更新字段
                $update_data  = array();
                $update_data['esta'] =  $this->_house_esta['frozen'];

                //失效房源
                $result_invalid = $this->sell_base_model->update( $update_data , $rowids );
            }

            $result = $result_invalid > 0 ? TRUE : FALSE;
        }
        
       return $result;
    }
    
    
    /**
     * 激活房源
     *
     * @access  protected
     * @param   mixed $rowids 房源编号（单个房源编号为整数，多个为数组格式）
     * @return  boolean  删除是否成功
     */
    public function active_house($rowids)
    {   
        $result = FALSE;
        
        if( !empty($rowids) )
        {
            $result_invalid = 0;
            if(is_array($this->_house_esta) && isset($this->_house_esta['active']))
            {    
                //更新字段
                $update_data  = array();
                $update_data['esta'] =  $this->_house_esta['active'];
                $update_data['istop'] =  0;//防止推荐房源失效后再激活后推荐房源超限制

                //失效房源
                $result_invalid = $this->sell_base_model->update( $update_data , $rowids );
            }

            $result = $result_invalid > 0 ? TRUE : FALSE;
        }
        
       return $result;
    }
}
/* End of file sell_operate_model.php */
/* Location: ./application/models/sell_operate_model.php */