<?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
 */

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

/**
 * 租售宝系统模型层
 *
 * 经纪人套餐类
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          xz
 * @link
 */
class Package_base_model extends MY_Model 
{   
    /**
     * 套餐表
     * @var string 
     */
    private $_package_tbl = 'broker_package';
    
    /**
     * 查询字段
     * @var string 
     */
    public $select_fields = '';
    
    /**
     * 缓存key
     * @var string 
     */ 
    private $_mem_key = 'nj_package_base_model';
    
    /**
     * 设置需要查询的字段
     * @param array $select_fields
     */
    public function set_select_fields($select_fields)
    {
        $select_fields_str = '';
        if(isset( $select_fields ) && !empty($select_fields))
        {   
            $select_fields_str = implode( ',', $select_fields) ;
        }
        $this->select_fields = $select_fields;
    }
    
    /**
     * 获取需要查询的字段
     * @return string
     */
    public function get_select_fields()
    {
        return $this->select_fields;
    }
    
    /**
     * 类初始化
     */
    public function __construct()
    {
        parent::__construct(1,1,3);
    }
    
    /**
     * 根据套餐编号获取详细记录
     * @param int $id 套餐编号
     * @return array 返回一条套餐的记录
     */ 
    public function find_by_id ($id) 
    {	
        $package_info = array ();
        
        if( $id > 0)
        {	
            $mem_key = GB_CITY.$this->_mem_key.'_find_by_id6_'.$id;
			//$this->mc->delete($mem_key);
            $cache = $this->mc->get($mem_key);

            if(isset($cache['is_ok']) && $cache['is_ok'] == 1 )
            {   
                $package_info = $cache['data'];
            }
            else
            {   
                //查询字段
                if ($this->get_select_fields())
                {
                    //$this->dbback->select($this->get_select_fields());
                }
                $this->dbback->select("package_id,package_name,package_valid_num,package_stock_num,package_refresh_num,package_sell_purview,package_rent_purview,package_tag_num,isstar_credit_upper_limit,credit_upper_limit,allow_infotype,exp_status,credit_status");
                
                $this->dbback->where("package_id = '$id'");
                $this->dbback->limit(1,0);
                $package_info = $this->dbback->get($this->_package_tbl)->row_array();

                $this->mc->add( $mem_key , array('is_ok'=>1 , 'data'=>$package_info) , 600);
            }
        }
        return $package_info;
    }
    
    /**
     * 根据条件查询套餐记录
     * @param string $where 查询条件
     * @return array 满足条件的套餐数组
     */
    public function find_by($where = '')
    {
        //查询字段
        if ($this->get_select_fields())
        {
            $this->dbback->select($this->get_select_fields());
        }
        //查询条件
        $this->dbback->where($where);
        return $this->dbback->get($this->_package_tbl)->result_array();
    }
}

/* End of file Package_model.php */
/* Location: ./zsb/model/Package_model.php */
