119 lines
3.0 KiB
PHP
119 lines
3.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\adminapi\controller;
|
||
|
|
|
||
|
|
use app\admin\model\AdminLog;
|
||
|
|
use app\common\controller\adminApi;
|
||
|
|
use think\Config;
|
||
|
|
use think\Db;
|
||
|
|
use think\Hook;
|
||
|
|
use think\Session;
|
||
|
|
use think\Validate;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 单页
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
class Page extends adminApi
|
||
|
|
{
|
||
|
|
|
||
|
|
protected $noNeedLogin = [];
|
||
|
|
protected $noNeedRight = [];
|
||
|
|
|
||
|
|
protected $table = 'vs_page';
|
||
|
|
|
||
|
|
public function _initialize()
|
||
|
|
{
|
||
|
|
parent::_initialize();
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 列表
|
||
|
|
*/
|
||
|
|
public function page_lists(){
|
||
|
|
$page = input('page', 1);
|
||
|
|
$page_limit = input('page_limit', 30);
|
||
|
|
$title = input('title', '');
|
||
|
|
$where = [];
|
||
|
|
$where['delete_time'] = 0;
|
||
|
|
if($title){
|
||
|
|
$where['title'] = ['like', "%$title%"];
|
||
|
|
}
|
||
|
|
$count = db::name($this->table)->where($where)->count();
|
||
|
|
$lists = db::name($this->table)->where($where)->order('aid desc')->page($page, $page_limit)->select();
|
||
|
|
foreach ($lists as &$v){
|
||
|
|
$v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
||
|
|
$v['admin'] = db::name('admin')->where(['id'=>$v['admin_id']])->value('nickname')??"--";
|
||
|
|
}
|
||
|
|
$return_data = [
|
||
|
|
'page' =>$page,
|
||
|
|
'page_limit' => $page_limit,
|
||
|
|
'count' => $count,
|
||
|
|
'lists' => $lists
|
||
|
|
];
|
||
|
|
return V(1,"成功", $return_data);
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 添加
|
||
|
|
*/
|
||
|
|
public function page_add(){
|
||
|
|
$admin_id = Session::get('admin_id');
|
||
|
|
$title = input('title', '');
|
||
|
|
$url= input('url', '');
|
||
|
|
// $content = input('content', '');
|
||
|
|
$content =$_POST['content']??"";
|
||
|
|
if(empty($title) || empty($content)){
|
||
|
|
return V(0, "参数错误");
|
||
|
|
}
|
||
|
|
$data = [
|
||
|
|
'title' => $title,
|
||
|
|
'url' => $url,
|
||
|
|
'content' => $content,
|
||
|
|
'admin_id' => $admin_id,
|
||
|
|
'createtime' => time()
|
||
|
|
];
|
||
|
|
$res = db::name($this->table)->insert($data);
|
||
|
|
if(!$res){
|
||
|
|
return V(0, "添加失败");
|
||
|
|
}
|
||
|
|
return V(1, "添加成功");
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 修改
|
||
|
|
*/
|
||
|
|
public function page_edit(){
|
||
|
|
$title = input('title', '');
|
||
|
|
$url= input('url', '');
|
||
|
|
// $content = input('content', '');
|
||
|
|
$content =$_POST['content']??"";
|
||
|
|
$id = input('id', '');
|
||
|
|
if($title){
|
||
|
|
$data['title'] = $title;
|
||
|
|
}
|
||
|
|
if($url){
|
||
|
|
$data['url'] = $url;
|
||
|
|
}
|
||
|
|
if($content){
|
||
|
|
$data['content'] = $content;
|
||
|
|
}
|
||
|
|
$data['updatetime'] = time();
|
||
|
|
$res = db::name($this->table)->where(['aid'=>$id])->update($data);
|
||
|
|
if(!$res){
|
||
|
|
return V(0, "修改失败");
|
||
|
|
}
|
||
|
|
return V(1, "修改成功");
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 删除
|
||
|
|
*/
|
||
|
|
public function page_del(){
|
||
|
|
$id = input('id', '');
|
||
|
|
$res = db::name($this->table)->where(['aid'=>$id])->update(['delete_time'=>time()]);
|
||
|
|
if(!$res){
|
||
|
|
return V(0, "删除失败");
|
||
|
|
}
|
||
|
|
return V(1, "删除成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|