推送更新

This commit is contained in:
2025-05-29 17:33:17 +08:00
parent 46e5333864
commit 47cfb7dcaf
5 changed files with 517 additions and 0 deletions
@@ -9,6 +9,7 @@ use app\admin\model\AdminSysMenu;
use app\admin\model\AdminUserGroup;
use app\admin\model\AdminUser;
use app\admin\model\Banner;
use app\admin\model\ContentPush;
class YunzeradminController extends Base
@@ -451,4 +452,147 @@ class YunzeradminController extends Base
}
return json(['code' => 1, 'msg' => '请求方法无效']);
}
//内容推送
public function contentpush()
{
return View::fetch();
}
// 内容推送列表
public function contentpushlist()
{
if (Request::isGet()) {
$page = intval(input('post.page', 1));
$limit = intval(input('post.limit', 10));
$query = ContentPush::where('delete_time', null)
->field('id, title, type, status, sort, create_time, update_time');
// 获取总记录数
$count = $query->count();
// 获取分页数据
$lists = $query->order(['sort DESC', 'id DESC'])
->page($page, $limit)
->select()
->toArray();
// 处理数据
foreach ($lists as &$item) {
$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
$item['update_time'] = is_numeric($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : $item['update_time'];
}
return json([
'code' => 0,
'msg' => '',
'count' => $count,
'data' => $lists
]);
}
return json(['code' => 1, 'msg' => '请求方法无效']);
}
// 添加内容推送
public function contentpushadd()
{
if (Request::isPost()) {
$data = [
'title' => input('post.title'),
'content' => input('post.content'),
'image' => input('post.image'),
'url' => input('post.url'),
'type' => input('post.type', 1),
'status' => input('post.status', 1),
'sort' => input('post.sort', 0),
'create_time' => time()
];
$res = ContentPush::insert($data);
if (!$res) {
Log::record('添加内容推送', 0, '添加内容推送失败', '内容推送管理');
return json(['code' => 1, 'msg' => '添加内容推送失败']);
}
Log::record('添加内容推送', 1, '', '内容推送管理');
return json(['code' => 0, 'msg' => '添加成功']);
}
return json(['code' => 1, 'msg' => '请求方法无效']);
}
// 编辑内容推送
public function contentpushedit()
{
if (Request::isPost()) {
$id = input('post.id');
if (empty($id)) {
Log::record('编辑内容推送', 0, 'ID不能为空', '内容推送管理');
return json(['code' => 1, 'msg' => 'ID不能为空']);
}
$data = [
'title' => input('post.title'),
'content' => input('post.content'),
'image' => input('post.image'),
'url' => input('post.url'),
'type' => input('post.type', 1),
'status' => input('post.status', 1),
'sort' => input('post.sort', 0),
'update_time' => time()
];
$res = ContentPush::where('id', $id)->update($data);
if ($res === false) {
Log::record('编辑内容推送', 0, '更新内容推送失败', '内容推送管理');
return json(['code' => 1, 'msg' => '更新内容推送失败']);
}
Log::record('编辑内容推送', 1, '', '内容推送管理');
return json(['code' => 0, 'msg' => '更新成功']);
}
return json(['code' => 1, 'msg' => '请求方法无效']);
}
// 删除内容推送
public function contentpushdel()
{
if (Request::isPost()) {
$id = input('post.id');
if (empty($id)) {
Log::record('删除内容推送', 0, 'ID不能为空', '内容推送管理');
return json(['code' => 1, 'msg' => 'ID不能为空']);
}
$res = ContentPush::where('id', $id)->update(['delete_time' => time()]);
if (!$res) {
Log::record('删除内容推送', 0, '删除内容推送失败', '内容推送管理');
return json(['code' => 1, 'msg' => '删除内容推送失败']);
}
Log::record('删除内容推送', 1, '', '内容推送管理');
return json(['code' => 0, 'msg' => '删除成功']);
}
return json(['code' => 1, 'msg' => '请求方法无效']);
}
// 修改内容推送状态
public function contentpushstatus()
{
if (Request::isPost()) {
$id = input('post.id');
$status = input('post.status');
if (empty($id)) {
Log::record('修改内容推送状态', 0, 'ID不能为空', '内容推送管理');
return json(['code' => 1, 'msg' => 'ID不能为空']);
}
$res = ContentPush::where('id', $id)->update(['status' => $status]);
if ($res === false) {
Log::record('修改内容推送状态', 0, '更新状态失败', '内容推送管理');
return json(['code' => 1, 'msg' => '更新状态失败']);
}
Log::record('修改内容推送状态', 1, '', '内容推送管理');
return json(['code' => 0, 'msg' => '更新成功']);
}
return json(['code' => 1, 'msg' => '请求方法无效']);
}
}