<?php
/**
 * Created by 娄凯.
 * Description:
 * Date: 2018\5\17 0017
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class real_house_set_log extends MY_Model{
    /**
     * 表名
     * @var type 表名
     */
    private $table;

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

    /**
     * 根据用户id，时间等查房源标签总数
     * @param $uid
     * @param $startTime
     * @param $endTime
     * @param int $houseid
     * @return int
     */
    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 ctime >= '$startTime' AND ctime <= '$endTime'";
            if($houseid){
                $where .= " and rowid =". $houseid;
            }
            $this->dbback->where($where);
            $tag_num = $this->dbback->count_all_results($this->table);
        }

        return $tag_num;
    }

    /**
     *  根据用户id，时间等查房源标签列表
     * @param $uid
     * @param $startTime
     * @param $endTime
     * @param $start
     * @param $number
     * @param $houseid
     * @return array
     */
    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 ctime >= '$startTime' AND ctime <= '$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;
    }
}
?>