236 lines
8.2 KiB
PHP
Executable File
236 lines
8.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: ORICO
|
|
* Date: 2019-01-15
|
|
* Time: 11:01
|
|
*/
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Lang;
|
|
use think\Loader;
|
|
use think\Config;
|
|
|
|
class Blog extends BaseController
|
|
{
|
|
|
|
|
|
private function init_search(&$search){
|
|
$search['name'] = '';
|
|
$search['timebegin'] = '';
|
|
$search['timeend'] = '';
|
|
}
|
|
public function lists(){
|
|
$agent = Db('blog');
|
|
|
|
$data = $this->request->param();
|
|
$arg_where = ['siteid' => $this->siteid,'stat' => ['in', '0,1'], 'country_code' => $this->country_code];
|
|
|
|
$search = [];
|
|
$this->init_search($search);
|
|
if (isset($data['name']) && $data['name'] != ''){
|
|
$arg_where['title'] = ['like', "%$data[name]%"];
|
|
$search['title'] = $data['name'];
|
|
}
|
|
|
|
|
|
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
|
|
// 时间有一个不为空就初始化
|
|
$arg_where['public_time'] = [];
|
|
if (isset($data['timebegin']) && $data['timebegin'] != '')
|
|
{
|
|
$time = $data['timebegin'];
|
|
array_push($arg_where['public_time'], ['>=', $time]);
|
|
$search['timebegin'] = $data['timebegin'];
|
|
}
|
|
else{
|
|
array_push($arg_where['public_time'], ['>=', "0000-00-00"]);
|
|
}
|
|
|
|
if (isset($data['timeend']) && $data['timeend'] != '')
|
|
{
|
|
$time = $data['timeend'];
|
|
array_push($arg_where['public_time'], ['<=', $time]);
|
|
$search['timeend'] = $data['timeend'];
|
|
}
|
|
else{
|
|
//echo "_________";
|
|
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
|
|
array_push($arg_where['public_time'], ['<=', $time]);
|
|
}
|
|
}
|
|
// echo "<pre>";print_r($arg_where);die;
|
|
|
|
//$where = ['stat'=>0];
|
|
//$where = [];
|
|
$list = $agent->where($arg_where)->select();
|
|
//echo "<pre>==".$agent->getlastsql();die;
|
|
$count = count($list);
|
|
$list = $agent->where($arg_where)->paginate(20,$count);
|
|
$page = $list->render();
|
|
$this->assign('search',$search);
|
|
$this->assign('page',$page);
|
|
$this->assign('list',$list);;
|
|
return $this->fetch();
|
|
|
|
}
|
|
public function add(){
|
|
|
|
return $this->fetch();
|
|
}
|
|
public function creat(){
|
|
$data = $_POST;
|
|
$data['stat'] = 0;
|
|
$data['siteid'] = $this->siteid;
|
|
$data['country_code'] = $this->country_code;
|
|
if($data['public_time'] == '') {
|
|
$data['public_time'] = date("Y-m-d H:i:s");
|
|
}
|
|
$data['add_time'] = date("Y-m-d H:i:s");
|
|
|
|
$validaterule = ['title' => 'require', 'visit_count' => 'number|between:0,2147483647',];
|
|
$validatemsg = ['title.require' => '名称不能为空', 'visit_count.between' => '浏览量不能为空',];
|
|
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
|
if (true !== $valid_result) {
|
|
// 验证失败 输出错误信息
|
|
return $this->error($valid_result);
|
|
}
|
|
|
|
|
|
$adent = Db('blog');
|
|
$inster = $adent->insert($data);
|
|
if($inster){
|
|
return $this->success('添加成功');
|
|
}else{
|
|
return $this->error('添加失败');
|
|
}
|
|
}
|
|
public function edit($id = 0) {
|
|
$id = intval($id);
|
|
|
|
$where = ['id '=>$id];
|
|
$agent = Db('blog');
|
|
$data = $agent->where($where)->find();
|
|
$this->assign('data',$data);
|
|
return $this->fetch();
|
|
}
|
|
public function save(){
|
|
$data = $_POST;
|
|
$adent = Db('blog');
|
|
$data['siteid'] = $this->siteid;
|
|
$data['country_code'] = $this->country_code;
|
|
|
|
$inster = $adent->insert($data);
|
|
if($inster){
|
|
return $this->success('修改成功');
|
|
}else{
|
|
return $this->error('修改失败');
|
|
}
|
|
}
|
|
|
|
//2021-05-29 申邵 控制blog更新保存
|
|
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' => '名称不能为空'];
|
|
$valid_result = $this->validate($data, $validaterule, $validatemsg);
|
|
if (true !== $valid_result) {
|
|
// 验证失败 输出错误信息
|
|
return $this->error($valid_result);
|
|
}
|
|
|
|
|
|
$update_data = [
|
|
'id' => $data['id'],
|
|
'title' => $data['title'],
|
|
'content' => $data['content'],
|
|
'icon' => $data['icon'],
|
|
'h5_icon' => $data['h5_icon'],
|
|
'visit_count' => $data['visit_count'],
|
|
'is_top' => $data['is_top'],
|
|
'public_time' => $data['public_time'],
|
|
'seo_title' => $data['seo_title'],
|
|
'seo_description' => $data['seo_description'],
|
|
'seo_keyword' => $data['seo_keyword']
|
|
|
|
];
|
|
//echo "<pre>=="; print_r($data);die;
|
|
$blog = Db('blog');
|
|
$model = $blog->update($update_data);
|
|
//$model = model('blog')->updateRow($update_data);
|
|
|
|
|
|
|
|
return $this->redirect(url('/admin/blog/lists'));
|
|
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
//2021-05-29 申邵 控制blog删除
|
|
public function delete($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$result = model('blog')->deleteRow($id);
|
|
//echo "<pre>====="; print_r($result);die;
|
|
if ($result) {
|
|
//echo $id."<pre>=+++++++++"; print_r($result);die;
|
|
return $this->success(Lang::get('operation successed'), url('/admin/blog/lists'));
|
|
} else {
|
|
//echo "<pre>====="; print_r($result);die;
|
|
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 = model('blog')->deleteRows($ids);
|
|
if ($result) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/article/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
//2021-05-29 申邵 控制置顶是否启用
|
|
public function toggletop() {
|
|
$id = $this->request->param('id', 0);
|
|
$flag = $this->request->param('flag', 0);
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = model('blog')->updateRow(['id' => $id, 'is_top' => $flag]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/blog/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
|
|
//2021-05-29 申邵 控制状态是否启用
|
|
public function toggleshow() {
|
|
$id = $this->request->param('id', 0);
|
|
$flag = $this->request->param('flag', 0);
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$model = model('blog')->updateRow(['id' => $id, 'stat' => $flag]);
|
|
if ($model && $model->getData('id')) {
|
|
return $this->success(Lang::get('operation successed'), url('/admin/blog/lists'));
|
|
} else {
|
|
return $this->error(Lang::get('operation failed'));
|
|
}
|
|
}
|
|
return $this->error(Lang::get('incorrect operation'));
|
|
}
|
|
} |