117 lines
3.5 KiB
PHP
Executable File
117 lines
3.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\admin\controller\Base;
|
|
use \think\Request;
|
|
use think\facade\View;
|
|
use app\common\model\Danye as DanyeModel;
|
|
|
|
class Danye extends Base
|
|
{
|
|
public $page = '50';
|
|
public function index()
|
|
{
|
|
$whe = [];
|
|
$whe[] = ['id', '>', 0];
|
|
$whe[] = ['status', '=', 0];
|
|
$field = '*';
|
|
$order = 'id asc';
|
|
$data = DanyeModel::getList($whe, $field, $order, $this->page);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
View::assign('data', $data['list']);
|
|
return View::fetch('Danye/index');
|
|
}
|
|
|
|
// 编辑
|
|
public function edit()
|
|
{
|
|
if (!request()->isPost()) {
|
|
$id = request()->param('id', '');
|
|
$info = DanyeModel::getInfo(['id' => $id], '*');
|
|
if (!$info) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
// if ($id == 1) {
|
|
// return $this->renderError('请求参数错误1');
|
|
// }
|
|
$info['content'] = htmlspecialchars_decode($info['content']);
|
|
View::assign('info', $info);
|
|
return View::fetch('Danye/edit');
|
|
} else {
|
|
$data = input('post.');
|
|
if (empty($data['id'])) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
$info = DanyeModel::getInfo(['id' => $data['id']], '*');
|
|
if (!$info) {
|
|
return $this->renderError('请求参数错误1');
|
|
}
|
|
if ($info['id'] != 1 && $info['id'] < 21) {
|
|
unset($data['title']);
|
|
}
|
|
$data['update_time'] = time();
|
|
unset($data['id']);
|
|
$result = DanyeModel::where(['id' => $info['id']])->update($data);
|
|
if ($result) {
|
|
return $this->renderSuccess('编辑成功');
|
|
} else {
|
|
return $this->renderError('编辑失败');
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// 编辑
|
|
public function gonggao()
|
|
{
|
|
if (!request()->isPost()) {
|
|
$info = DanyeModel::getInfo(['id' => 1], '*');
|
|
if (!$info) {
|
|
return $this->renderError('请求参数错误');
|
|
}
|
|
$info['content'] = htmlspecialchars_decode($info['content']);
|
|
View::assign('info', $info);
|
|
return View::fetch('Danye/gonggao');
|
|
} else {
|
|
$data = input('post.');
|
|
$data['update_time'] = time();
|
|
unset($data['id']);
|
|
$result = DanyeModel::where(['id' => 1])->update($data);
|
|
if ($result) {
|
|
return $this->renderSuccess('编辑成功');
|
|
} else {
|
|
return $this->renderError('编辑失败');
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更改图片优化状态
|
|
* @return \think\response\Json
|
|
*/
|
|
public function change_image_optimizer()
|
|
{
|
|
$id = input('post.id/d', 0);
|
|
$status = input('post.status/d', 0);
|
|
|
|
if (empty($id)) {
|
|
return $this->renderError('参数错误');
|
|
}
|
|
|
|
$info = DanyeModel::getInfo(['id' => $id], 'id');
|
|
if (!$info) {
|
|
return $this->renderError('数据不存在');
|
|
}
|
|
|
|
$result = DanyeModel::where(['id' => $id])->update(['is_image_optimizer' => $status, 'update_time' => time()]);
|
|
if ($result) {
|
|
return $this->renderSuccess('操作成功');
|
|
} else {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
}
|