<?php

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

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
//        $this->connect();
    }

    /**
     * 取城市酒店点评 api comment_json.php
     * @param <int> $cityid     
     */
    public function comment_info($cityid)
    {
        $cfg_apiurl = Tmac::config('configcache.config.cfg_apiurl', APP_NAME, '.inc.php');

        $nofind_comment = '';
        $pages = $this->P('Pages_Ajax');
        $page = $pages->getNowPage();        
        $url = array('comment',$cityid);
        $xml_url = $cfg_apiurl . "comment_json.php?cityid=$cityid&pg={$page}";        
        $xml_root = VAR_ROOT . "json/comment/{$cityid}/";        
        $xml_name = "comment_{$cityid}_{$page}.json";
        $this->M('hotelLeft')->createXML($xml_url, $xml_root, $xml_name, 604800);
        $xmlstring = $xml_root . $xml_name;

        $page = '';
        $comment_ary = array();
        $lable_result = json_decode(file_get_contents($xmlstring), true);
        if ($lable_result['retmsg'] == 'ok') {
            $totalput = $lable_result['retHeader']['totalput'];
            $pages->setTotal($totalput);
            $pages->setUrl($url);
            $pages->setPrepage(10);
            $pages->getSqlLimit();
            $page = $pages->show();
            if (count($lable_result['reqdata']) > 0) {
                foreach ($lable_result['reqdata'] as $k => $basexml) {                    
                    $comment_ary[$k]['yonghu'] = $basexml['username'];
                    $comment_ary[$k]['addtime'] = date('Y-m-d H:i:s', $basexml['time']);
                    $comment_ary[$k]['hotel_id'] = $basexml['hid'];
                    $comment_ary[$k]['hotelname'] = $basexml['hotelname'];
                    $comment_ary[$k]['cityid'] = $basexml['cityid'];
                    $comment_ary[$k]['content'] = $basexml['content'];                    
                }
            } else {
                $nofind_comment = '此酒店暂无客人评价!';
            }
        } else {
            $nofind_comment = '接口读取失败，请重试！';
        }
        $result['nofind'] = $nofind_comment;
        $result['page'] = $page;
        $result['rs'] = $comment_ary;
        return $result;
    }

}