init
This commit is contained in:
122
app/admin/controller/ActionLog.php
Executable file
122
app/admin/controller/ActionLog.php
Executable file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Config;
|
||||
|
||||
class ActionLog extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$this->redirect('/admin/action_log/lists');
|
||||
}
|
||||
|
||||
public function lists() {
|
||||
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
||||
$arg_where = array('al.stat' => 0);
|
||||
$arg_order = array('al.id' => 'desc');
|
||||
$arg_field = array('al.id' => 'id', 'al.title' => 'title', 'al.content' => 'content', 'al.ip' => 'ip', 'al.addtime' => 'addtime', 'u.username' => 'username', 'al.stat' => 'stat');
|
||||
if (!empty($skeyword)) {
|
||||
$skeyword = trim($skeyword);
|
||||
$arg_where['title|ip|content'] = ['like', '%' . $skeyword . '%'];
|
||||
$search['skeyword'] = $skeyword;
|
||||
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
||||
} else {
|
||||
$search['skeyword'] = '';
|
||||
}
|
||||
$dataObject = Loader::model('ActionLog')->getPageLists($arg_where, $arg_order, $arg_field);
|
||||
$value = [
|
||||
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
||||
'page' => $dataObject->render(),
|
||||
//'page_previous' => $dataObject->getUrl($dataObject->currentPage() - 1),
|
||||
//'page_next' => $dataObject->getUrl($dataObject->currentPage() + 1),
|
||||
'search' => $search,
|
||||
];
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function edit($id = 0) {
|
||||
$value = array();
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$action_log = Loader::model('ActionLog')->getRow($id);
|
||||
if (empty($action_log)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$value['action_log'] = $action_log;
|
||||
}
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function update() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (empty($data) || !is_array($data)) {
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
$validaterule = ['title' => 'require'];
|
||||
$validatemsg = ['title.require' => 'title ' . Lang::get('can not be empty')];
|
||||
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
||||
if (true !== $valid_result) {
|
||||
// 验证失败 输出错误信息
|
||||
return $this->error($valid_result);
|
||||
}
|
||||
$model = Loader::model('ActionLog')->updateRow($data);
|
||||
if ($model && $model->getData('id')) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/action_log/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function delete($id = 0) {
|
||||
$id = intval($id);
|
||||
if ($id > 0) {
|
||||
$result = Loader::model('ActionLog')->deleteRow($id);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/action_log/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function deletes() {
|
||||
$ids = $this->request->post('ids');
|
||||
if ($this->request->isPost() && $ids) {
|
||||
$result = Loader::model('ActionLog')->deleteRows($ids);
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), url('/admin/action_log/lists'));
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
return $this->error(Lang::get('incorrect operation'));
|
||||
}
|
||||
|
||||
public function clear_log() {
|
||||
$tableName = Loader::model('ActionLog')->getTable();
|
||||
$result = Loader::model('ActionLog')->execute("TRUNCATE TABLE {$tableName};");
|
||||
if ($result == 0) {
|
||||
return $this->success(Lang::get('operation successed'), null, $result);
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'), null, $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function clear_log3() {
|
||||
$result = Loader::model('ActionLog')->where(['addtime' => ['lt', strtotime('-3 month')]])->delete();
|
||||
if ($result) {
|
||||
return $this->success(Lang::get('operation successed'), null, $result);
|
||||
} else {
|
||||
return $this->error(Lang::get('operation failed'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user