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

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

/**
 * Rent_match_base_model CLASS
 *
 * 求租匹配类
 *
 * @package         zsb
 * @subpackage      Models
 * @category        Models
 * @author          xz
 */

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

class Rent_match_base_model extends House_match_base_model{
       
    public function __construct() 
    {
        parent::__construct();
        
        $this->set_tbl_match('rentwanted_match');
    }
    
    
   /**
    * 根据匹配用户的账号编号获取已匹配的需求信息
    *
    * @access   public
    * @param	string  $demand_tbl 需求信息表
    * @param	int  $infofrom 匹配信息来源 1 个人、5中介
    * @param	int     $offset 偏移数,默认值为0
    * @param	int     $limit 每次取的条数，默认值为10
    * @param	string  $order_key 排序字段，默认值
    * @param	string  $order_by  升序、降序，默认降序排序
    * @param	int  $starttime  开始统计时间戳时间点
    * @return   array  匹配信息详情
    */
    public function get_rowid_by_matchuid( $infofrom = 5 )
    {
        $data_info = array();
        
        //需求编号
        $want_id = $this->get_want_id();
        
        //匹配账号编号
        $match_uid = $this->get_match_uid();
        
        //匹配表
        $tbl_match = $this->get_tbl_match();
        
        if( $want_id > 0 && $match_uid > 0 && $tbl_match != '' 
                && in_array($tbl_match, $this->_tbl_arr)  )
        {
            $cond_where = "want_id = '".$want_id."' AND infofrom = '".$infofrom."' "
            . "AND match_uid = '".$match_uid."' ";

            $this->dbback->where($cond_where);

            $data_info = $this->dbback->get($tbl_match)->row_array();
        }

        return $data_info;
    }
    
    
    /**
    * 根据匹配用户的账号编号获取已匹配的需求信息
    *
    * @access   public
    * @param    string  $demand_tbl 需求信息表
    * @param    int     $infofrom 匹配信息来源 1 个人、5中介
    * @param    int     $offset 偏移数,默认值为0
    * @param    int     $limit 每次取的条数，默认值为10
    * @param    string  $order_key 排序字段，默认值
    * @param    string  $order_by  升序、降序，默认降序排序
    * @param    int     $starttime  开始统计时间戳时间点
    * @return   array   匹配信息详情
    */
    public function get_demandlist_by_matchuid( $demand_tbl , $infofrom = 5 , $offset = 0 , $limit = 10 
                    , $order_key = 'creattime' , $order_by = 'DESC' , $starttime = 0 )
    {   
        $data_info = array();
        
        $tbl_match = $this->get_tbl_match();
        
        $match_uid = $this->get_match_uid();
        
        if( $match_uid > 0 && $demand_tbl != '' && $tbl_match != '' 
                && in_array($tbl_match, $this->_tbl_arr))
        {
            //需要查询的房源需求信息字段
            $select_fields = $this->get_search_fields();
            $select_fields_str = '';
            if( isset( $select_fields ) && !empty( $select_fields ) )
            {   
                //查询字段
                foreach ($select_fields as $key => $value)
                {
                    $select_fields_str .= $select_fields_str != '' 
                            ?  ','.$demand_tbl. '.'.$value : $demand_tbl. '.'.$value;
                }
                $this->dbback->select( $select_fields_str );
            }

            $this->dbback->from( $demand_tbl );
            $this->dbback->join( $tbl_match , $demand_tbl.".id = ".$tbl_match . '.want_id' , 'left');
            
            $cond_where = $tbl_match.".infofrom = '".$infofrom."'";

            $cond_where .= " AND ".$tbl_match.".match_uid = '".$match_uid."' ";
            
            if( $starttime == 0)
            {
                $start_time = time() - 86400 * 30;
            }
            
            $cond_where .= " AND ".$tbl_match.".creattime >= '".$start_time."' ";
            
            $this->dbback->where( $cond_where );

            //排序条件
            $this->dbback->order_by( $tbl_match.'.'.$order_key , $order_by );
            $this->dbback->limit( $limit , $offset );
            
            $data_info = $this->dbback->get()->result_array();
        }
        return $data_info;
    }
}
/* End of file rent_match_base_model.php */
/* Location: ./application/models/rent_match_base_model.php */