<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

//留言
class MessageModel extends MultiLangModel  {
	/**
	 * 查询留言分页
	 */
	public function getMessageList($rec_module='Message',$rec_id=0,$page=1)
	{
		$condition['rec_module'] = $rec_module;
		$condition['rec_id'] = $rec_id;
		$condition['pid'] = 0;
		$condition['reply_type'] = 0;
		$condition['status'] = 1;
		
		$limit = ($page-1)*C("PAGE_LISTROWS").",".C("PAGE_LISTROWS");
		$list = $this->where($condition)->order('is_top desc,create_time desc')->limit($limit)->findAll();
		
		foreach($list as $k=>$v)
		{
			$user_reply = $this->where("pid=".$v['id']." and reply_type=1 and status=1")->order('is_top desc,create_time desc')->findAll();
			foreach($user_reply as $kk=>$vv)
			{
				$user_reply[$kk]['create_time_format'] = toDate($vv['create_time']);
				$user_reply[$kk]['update_time_format'] = toDate($vv['update_time']);
			}
			$admin_reply = $this->where("pid=".$v['id']." and reply_type=2 and status=1")->find();
			if($admin_reply)
			{
				$admin_reply['create_time_format'] = toDate($admin_reply['create_time']);
				$admin_reply['update_time_format'] = toDate($admin_reply['update_time']);			
			}
			$list[$k]['user_reply'] = $user_reply;
			$list[$k]['admin_reply'] = $admin_reply;
			$list[$k]['create_time_format'] = toDate($v['create_time']);
			$list[$k]['update_time_format'] = toDate($v['update_time']);
		}
		$result['message_list'] = $list;
		$result['message_total'] = $this->where($condition)->count();
		return $result;
	}
}
?>