<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of house_tag
 *
 * @author Administrator
 */
class house_tag extends MY_Model {
    const STATUS_VALID = 1;//有效
    const STATUS_INVALID = 2;//无效

    /**
     * 表名
     * @var type 表名
     */
    private $table;

    public function __construct() {
        parent::__construct(0,1,0);
        $this->table = 'house_tag';
    }
    
    /**
     * 根据用户id，时间等查房源标签
     * @param type $uid
     * @param type $startTime
     * @param type $endTime
     * @param type $start
     * @param type $number
     * @param type $houseid 房源id
     * @return type
     */
    public function findByUidTime($uid, $startTime, $endTime, $start, $number, $houseid)
	{	
		$tag_info = array();

		if($uid > 0 && isset($startTime) && isset($endTime) )
		{
			$startTime = strtotime($startTime);
			$endTime = strtotime($endTime) + 86399;
			$where = "uid = $uid AND operatetime >= '$startTime' AND operatetime <= '$endTime'";
			if($houseid){
			    $where .= " and rowid =". $houseid;
			}
			$this->dbback->where($where);
			$this->dbback->order_by("id desc");
			$this->dbback->limit($number, $start);
			$tag_info = $this->dbback->get($this->table)->result_array();
		}

        return $tag_info;
    }

    /**
     * 根据用户id，时间等查房源标签总数
     * @param type $uid
     * @param type $startTime
     * @param type $endTime
     * @param type $houseid 房源id
     * @return type
     */
    public function findCountByUidTime($uid, $startTime, $endTime, $houseid=0)
	{	
		$tag_num = 0;
		if($uid > 0 && isset($startTime) && isset($endTime) )
		{
			$startTime = strtotime($startTime);
			$endTime = strtotime($endTime) + 86399;
			$where = "uid = $uid AND addtime >= '$startTime' AND addtime <= '$endTime'";
			if($houseid){
			    $where .= " and rowid =". $houseid;
			}
			$this->dbback->where($where);
			$tag_num = $this->dbback->count_all_results($this->table);
		}
		
		return $tag_num;
    }
    
    public static function getReasonText($type,$reason=3){
        if(!$reason){
            $reason = 3;
        }
        $config['jitui_operation_status'] = array(
            1           => '添加',
            2       => '手动失效',
            3        => '房源状态改变',
            4       => '到期',
            5 => '非多图编辑',
            6 => '标签到期'
        );
        $config['realhouse_operation_status'] = array(
            1      => '添加',
            2   => '手动失效',
            3    => '房源状态改变',
            4      => '项目退出',
            5  => '到期'
        );
        if($type==1){
            $reasontext = $config['realhouse_operation_status'][$reason];
        }else{
            $reasontext = $config['jitui_operation_status'][$reason];
        }

        return $reasontext;
    }
    /**
     * 根据状态码返回对应的文字说明
     * @param type $status
     * @return string|boolean
     */
    public static function getStatusText($status) {
        $deal_arr = array(
            house_tag::STATUS_VALID => '有效',
            house_tag::STATUS_INVALID => '无效'
        );
        if (array_key_exists($status, $deal_arr)) {
            return $deal_arr[$status];
        } else {
            return false;
        }
    }
    
    public static function getTblText($tbl) {
        $array = array('sell' => '出售', 'rent' => '出租');
        if (array_key_exists($tbl, $array)) {
            return $array[$tbl];
        } else {
            return '';
        }
    }
}
?>