function comments() { import("ORG.Util.Page"); $items_mod = D('items'); $user_comments_mod = D('user_comments'); $user_history_mod = D('user_history'); $act = $_REQUEST['act']; $type = $_REQUEST['type']; $pid = empty($_REQUEST['pid']) ? 0 : intval($_REQUEST['pid']); if ($act == 'add') { if (empty($_SESSION['user_id'])) { exit; } //更新评论 $data = $user_comments_mod->create(); $data['add_time'] = time(); $data['info'] = trim(strip_tags($_REQUEST['info'])); if ($data['info'] == "") { $data['info'] = "非法字符,系统自动屏蔽!"; $data['status'] = "0"; } $data['uid'] = $_SESSION['user_id']; $user_comments_mod->add($data); if ($type == 'item') { $arr = array('comments' => $this->user_comments_mod->where("pid=" . $pid . " and type='item' and status='1'")->count()); $items_mod->where('id=' . $pid)->save($arr); } //更新动态 $data = $user_history_mod->create(); $data['add_time'] = time(); $data['uid'] = $_SESSION['user_id']; $user_history_mod->add($data); return; } $where = "status='1' and type='" . $_REQUEST['type'] . "' and pid={$pid}"; $count = $user_comments_mod->where($where)->count(); $p = new Page($count, 8); $list = $user_comments_mod->relation('user')->where($where)->order("id desc")->limit($p->firstRow . ',' . $p->listRows)->select(); $this->assign('comments', array('list' => $list, 'page' => $p->show_comments(), 'count' => $count)); if ($this->isAjax()) { $this->ajaxReturn(array('list' => $this->fetch('comments_list'), 'count' => $count)); } }