+---------------------------------------------------------------------- | TickyPHP [ This is a freeware ] +---------------------------------------------------------------------- | Copyright (c) 2015 All rights reserved.
+----------------------------------------------------------------------
| Author: 罗敏贵 e-mail:minguiluo@163.com
comment |
<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2015 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: Comment.php 16298 2019-01-28 14:12:48 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:对应的表名:tky_comment 评论
* +----------------------------------------------------------------------
*/
namespace application\comment\controller;
use application\admin\controller\auth as auth;
use ticky\request;
use ticky\response;
class comment extends auth {
// 首页
public function index() {
$search = $this->search_frm();
$ret = $this->db->page('comment', $search['sql'], 'id', $this->p);
$this->assign('page', $ret['page']);
$this->assign('items', $ret['items']);
$this->assign('search', $search['arr']);
$this->display('comment/index');
}
// 添加记录
public function add() {
if (request::isPost()) {
$data = $this->post_frm();
db('comment')->add($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '添加成功']);
} else {
showmsg('添加成功', '/comment/comment');
}
} else {
$this->assign('postUrl', '/comment/comment/add');
$this->assign('action', '添加');
$this->display('comment/manage');
}
}
// 更新记录
public function update() {
if (request::isPost()) {
$data = $this->post_frm();
$id = request::post('cid', 0);
db('comment')->where(['cid' => $id])->update($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('修改成功', '/comment/comment');
}
} else {
$cid = request::get('id', 0);
$item = db('comment')->where(['cid' => $cid])->find();
$this->assign('postUrl', '/comment/comment/update');
$this->assign('action', '修改');
$this->assign('item', $item);
}
}
// 删除记录
public function delete() {
$id = request::post('id', 0);
$result = $this->db->table('comment')->where(['cid' => $id])->delete();
if (request::isAjax()) {
if ($result) {
response::ajax(['code' => 200, 'msg' => '删除成功!']);
} else {
response::ajax(['code' => 403, 'msg' => '删除失败! id=' . $id]);
}
} else {
showmsg('删除成功', '/comment/comment');
}
}
// 批量删除
public function batchremove() {
$optype = request::post('optype', 'del');
$ids = request::post('ids', []);
if ($optype == "del") {
for ($i = 0; $i < count($ids); $i++) {
$id = $ids[$i];
$this->db->table('comment')->where(['cid' => $id])->delete();
}
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('删除成功', '/comment/comment');
}
}
}
//查询条件
private function search_frm() {
$search = request::get('search', []);
$where = '1=1 ';
if ($cid = trim($search['cid'])) {
$where .= "and cid = '{$cid}' ";
}
if ($upid = trim($search['upid'])) {
$where .= "and upid = '{$upid}' ";
}
if ($uid = trim($search['uid'])) {
$where .= "and uid = '{$uid}' ";
}
if ($idtype = trim($search['idtype'])) {
$where .= "and idtype = '{$idtype}' ";
}
if ($id = trim($search['id'])) {
$where .= "and id = '{$id}' ";
}
if ($message = trim($search['message'])) {
$where .= "and message = '{$message}' ";
}
if ($ip = trim($search['ip'])) {
$where .= "and ip = '{$ip}' ";
}
if ($status = trim($search['status'])) {
$where .= "and status = '{$status}' ";
}
if ($dateline = trim($search['dateline'])) {
$where .= "and dateline = '{$dateline}' ";
}
return [
'arr' => $search,
'sql' => $where
];
}
//表单数据
private function post_frm() {
$arr = array();
$arr['upid'] = request::post('upid', '');
$arr['uid'] = request::post('uid', '');
$arr['idtype'] = request::post('idtype', '');
$arr['id'] = request::post('id', '');
$arr['message'] = request::post('message', '');
$arr['ip'] = request::post('ip', '');
$arr['status'] = request::post('status', '');
$arr['dateline'] = time();
return $arr;
}
}