From 19dda20812a898b0d905668cdaf1e8aec8d064ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=BF=97=E5=BC=BA?= <357099073@qq.com> Date: Mon, 16 Jun 2025 17:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=A0=E6=9D=90=E4=B8=AD=E5=BF=83=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/YunzeradminController.php | 141 +++++++ app/admin/view/yunzeradmin/materialcenter.php | 363 ++++++++++++++++++ .../view/yunzeradmin/materialcenteradd.php | 0 .../view/yunzeradmin/materialcenteredit.php | 0 4 files changed, 504 insertions(+) create mode 100644 app/admin/view/yunzeradmin/materialcenter.php create mode 100644 app/admin/view/yunzeradmin/materialcenteradd.php create mode 100644 app/admin/view/yunzeradmin/materialcenteredit.php diff --git a/app/admin/controller/YunzeradminController.php b/app/admin/controller/YunzeradminController.php index 448bb38..db86292 100644 --- a/app/admin/controller/YunzeradminController.php +++ b/app/admin/controller/YunzeradminController.php @@ -612,4 +612,145 @@ class YunzeradminController extends Base } return json(['code' => 1, 'msg' => '请求方法无效']); } + + //素材中心 + public function materialcenter() + { + return View::fetch(); + } + // 内容推送列表 + public function materialcenterlist() + { + 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 materialcenteradd() + { + 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 materialcenteredit() + { + 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 materialcenterdel() + { + 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 materialcenterstatus() + { + 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' => '请求方法无效']); + } } \ No newline at end of file diff --git a/app/admin/view/yunzeradmin/materialcenter.php b/app/admin/view/yunzeradmin/materialcenter.php new file mode 100644 index 0000000..991d5cd --- /dev/null +++ b/app/admin/view/yunzeradmin/materialcenter.php @@ -0,0 +1,363 @@ +{include file="public/header" /} +