<?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_frozen
 *
 * @author Administrator
 */
class house_frozen extends MY_Model {

    /**
     * 冻结
     */
    const STATUS_FROZEN = 4;
    /**
     * 申诉
     */
    const STATUS_APPEAL = 2;
    /**
     * 拒绝解冻
     */
    const STATUS_REFUSE = 3;
    /**
     * 已解冻
     */
    const STATUS_UNFROZEN = 1;
    /**
     * 图片违规冻结房源
     */
    const STATUS_PICV = 5; 
    
    /**
     * 表名
     * @var type 表名
     */
    private $table;

    public function __construct() {
        parent::__construct(0,1,0);
        $this->table = 'house_freeze';
    }

    public function findBy($conf,$start,$limit) {
        $cond = " WHERE agentcode  = 'B000' AND uid = " . $uid;
        $cond .= ' AND freezetime BETWEEN ' . $start_time . ' AND ' . $end_time;
        $order_cond = ' ORDER BY id DESC ';

        $sql = "SELECT tbl,rowid,reason,freezetime AS optime,esta FROM house_freeze "
                . " $cond  $order_cond LIMIT " . $limit . "";
        $violation_info = $dbback->GetAll($sql);
    }
    
    /**
     * 根据经纪人id，开始时间，结束时间等查违规记录
     * @param type $uid
     * @param type $startTime
     * @param type $endTime
     * @param type $start
     * @param type $number
     * @return type
     */
    public function findByUidTime($uid,$startTime,$endTime,$start,$number) {
        $startTime = strtotime($startTime);
        $endTime = strtotime($endTime);
        $this->dbback->select("tbl,rowid,reason,freezetime AS optime,esta")
                ->from($this->table)
                ->where("agentcode = 'B000' AND uid = $uid AND freezetime >= '$startTime' AND freezetime <= '$endTime'")
                ->order_by("id desc")->limit($number,$start);
        $query = $this->dbback->get();
        return $query->result_array();
    }
    
    public function findCountByUidTime($uid,$startTime,$endTime) {
        $startTime = strtotime($startTime);
        $endTime = strtotime($endTime);
        $this->dbback->select("rowid")
                ->from($this->table)
                ->where("agentcode = 'B000' AND uid = $uid AND freezetime >= '$startTime' AND freezetime <= '$endTime'")
                ;
        return $this->dbback->count_all_results();
    }

    /**
     * 根据状态码返回对应的文字说明
     * @param type $status
     * @return string|boolean
     */
    public static function getStatusText($status) {
        $deal_arr = array(
            house_frozen::STATUS_UNFROZEN => '已解冻', 
            house_frozen::STATUS_APPEAL => '申诉', 
            house_frozen::STATUS_REFUSE => '拒绝解冻', 
            house_frozen::STATUS_FROZEN => '冻结', 
            house_frozen::STATUS_PICV => '图片违规冻结房源'
            );
        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 '';
        }
    }
}
?>