<?php

/**
 * 前台 酒店点评 模块 Model
 * ============================================================================
 * zhuna_php 住哪网酒店分销联盟程序php版　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: liansuo.class.php 50 2011-12-05 02:56:32Z zhangwentao $
 * http://un.zhuna.cn；
 */
class liansuo extends Model
{

    private $db;
    private $chain_table;
    private $chainnum_table;

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
        $this->db = $this->connect();
        $this->chain_table = DB_PREFIX . 'chain';
        $this->chainnum_table = DB_PREFIX . 'chainnum';
    }

    /**
     * 取连锁酒店总数
     */
    public function getChainCount()
    {
        $sql = "SELECT COUNT(*) AS count FROM $this->chain_table";
        $count = $this->db->cacheGetOne($sql, 604800);
        return $count;
    }

    /**
     * 连锁酒店 涵盖的城市
     */
    public function getChainCityCount()
    {
        $sql = "SELECT DISTINCT cityid FROM $this->chainnum_table ";
        $rs = $this->db->cacheGetAll($sql, 604800);
        $count = count($rs);
        return $count;
    }

    /**
     * 取连锁酒店Array
     * @param <type> $cityid
     * @param <type> $limit     
     * @param <type> $jibie
     * @return <type> array
     */
    public function getchain($cityid = 0, $limit, $jibie = 0)
    {
        $sql_city = '';
        if ($cityid <> 0)
            $sql_city = " AND chain_id IN(SELECT chain_id FROM $this->chainnum_table WHERE cityid={$cityid})";
        $sql = "SELECT chain_id, chain_name, picture, hotelnum FROM $this->chain_table WHERE jibie = {$jibie}{$sql_city} ORDER BY hotelnum DESC ";
        $sql .= "LIMIT 0,{$limit}";
        $rs = $this->db->cacheGetAll($sql, 604800);
        return $rs;
    }

}