manghe/app/admin/controller/Danye.php
2025-03-21 19:25:07 +08:00

90 lines
2.7 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 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) {
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('编辑失败');
}
}
}
}