From 94f653471398cb125dfea50bff843380466ecc88 Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:02:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9A=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91=EF=BC=9A?= =?UTF-8?q?=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91=EF=BC=9A=20?= =?UTF-8?q?=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/AdminController.class.php | 81 +++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/FlyCube/MpApi/Controller/AdminController.class.php b/FlyCube/MpApi/Controller/AdminController.class.php index 917cf68..536b282 100644 --- a/FlyCube/MpApi/Controller/AdminController.class.php +++ b/FlyCube/MpApi/Controller/AdminController.class.php @@ -287,6 +287,8 @@ class AdminController extends PublicController $dataList = array(); foreach ($idArr as $admin_id) { $dataList[] = array( + 'shop_id' => $this->tokenShop_id, + 'by_admin_id' => $this->admin_id, 'admin_id' => intval($admin_id), 'message' => $message, 'tit' => $tit, @@ -305,10 +307,15 @@ class AdminController extends PublicController } } /** - * @description 获取公告列表(当前管理员 + 未过期) + * @description 获取公告列表(未过期),连表获取 发送者管理员信息 */ public function getMessageList() { + // 权限判断 + if ($this->tokenShop_id != C('powerId')) { + $where['m.shop_id'] = $this->tokenShop_id; // 非总管理员 只返回自己的账户信息 + } + $adminId = $this->admin_id; //当前管理员 $now = time(); @@ -318,12 +325,28 @@ class AdminController extends PublicController 'end_time' => array('gt', $now) // 未过期 ); - // 查询字段 - $fields = array('id', 'tit', 'message', 'end_time', 'add_time'); + // 查询字段,注意字段前加表别名 + $fields = array( + 'm.id', + 'm.admin_id', + 'm.by_admin_id', + 'm.tit', + 'm.message', + 'm.end_time', + 'm.add_time', + 'a.name' => 'admin_name', + 'a.uname' => 'admin_uname' + ); // 数据库查询 - $messageDb = D('message'); - $messageList = $messageDb->where($where)->field($fields)->order('add_time DESC')->select(); + $messageDb = M('message'); + $messageList = $messageDb + ->alias('m') + ->join('__ADMINUSER__ a ON m.by_admin_id = a.id', 'LEFT') + ->where($where) + ->field($fields) + ->order('m.add_time DESC') + ->select(); if ($messageList !== false) { echo json_encode(array( @@ -338,6 +361,54 @@ class AdminController extends PublicController )); } } + + /** + * @description 获取全部公告 不只 和自己admin_id相关的 且不考虑过期 + */ + public function getAllMessageList() + { + // 权限判断 + if ($this->tokenShop_id != C('powerId')) { + $where['m.shop_id'] = $this->tokenShop_id; // 非总管理员 只返回自己的账户信息 + } + + // 查询字段,注意字段前加表别名 + $fields = array( + 'm.id', + 'm.admin_id', + 'm.by_admin_id', + 'm.tit', + 'm.message', + 'm.end_time', + 'm.add_time', + 'a.name' => 'admin_name', + 'a.uname' => 'admin_uname' + ); + + // 数据库查询 + $messageDb = M('message'); + $messageList = $messageDb + ->alias('m') + ->join('__ADMINUSER__ a ON m.by_admin_id = a.id', 'LEFT') + ->where($where) + ->field($fields) + ->order('m.add_time DESC') + ->select(); + + if ($messageList !== false) { + echo json_encode(array( + 'status' => 1, + 'msg' => '获取成功', + 'messageList' => $messageList + )); + } else { + echo json_encode(array( + 'status' => 0, + 'msg' => '获取失败' + )); + } + } + /** * @description: 分类列表 */