From c23e649d6559f1b736b909bd534277a1774c50ec Mon Sep 17 00:00:00 2001 From: Ying Date: Mon, 3 Jul 2023 10:09:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/system/AdminNotice.php | 181 ++++++++++++ app/admin/view/system/admin_notice/bells.html | 258 ++++++++++++++++++ app/admin/view/system/admin_notice/index.html | 180 ++++++++++++ .../view/system/admin_notice/message.html | 56 ++++ .../view/system/admin_notice/notice.html | 19 ++ app/admin/view/system/admin_notice/todo.html | 23 ++ app/common/validate/system/AdminNotice.php | 73 +++++ 7 files changed, 790 insertions(+) create mode 100644 app/admin/controller/system/AdminNotice.php create mode 100644 app/admin/view/system/admin_notice/bells.html create mode 100644 app/admin/view/system/admin_notice/index.html create mode 100644 app/admin/view/system/admin_notice/message.html create mode 100644 app/admin/view/system/admin_notice/notice.html create mode 100644 app/admin/view/system/admin_notice/todo.html create mode 100644 app/common/validate/system/AdminNotice.php diff --git a/app/admin/controller/system/AdminNotice.php b/app/admin/controller/system/AdminNotice.php new file mode 100644 index 0000000..c2eba22 --- /dev/null +++ b/app/admin/controller/system/AdminNotice.php @@ -0,0 +1,181 @@ + Apache 2.0 License Code +// +---------------------------------------------------------------------- + +namespace app\admin\controller\system; + +use app\admin\enums\AdminNoticeEnum; +use app\admin\service\AdminNoticeService; +use app\AdminController; +use app\common\exception\OperateException; +use app\common\model\system\AdminNotice as AdminNoticeModel; +use app\common\model\system\Admin as AdminModel; +use Exception; +use support\Response; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + +class AdminNotice extends AdminController +{ + /** + * 消息类型 + * @var array + */ + public array $msgType = [ + 'notice' => '通知', + 'message' => '消息', + 'todo' => '待办', + ]; + + // 初始化函数 + public function __construct() + { + parent::__construct(); + $this->model = new AdminNoticeModel(); + } + + /** + * 获取资源列表 + * @return Response + * @throws Exception + */ + public function index(): Response + { + if (request()->isAjax()) { + list($count, $list) = AdminNoticeService::dataList(get_admin_id()); + return $this->success('查询成功', null, $list, $count); + } + + return view('/system/admin_notice/index', [ + 'msgType' => $this->msgType, + ]); + } + + /** + * 消息模板 + * @return Response + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function bells(): Response + { + list($count, $list) = AdminNoticeService::bells(get_admin_id()); + return view('/system/admin_notice/bells', [ + 'list' => $list, + 'count' => $count + ]); + } + + /** + * 获取消息列表 + * @return Response + * @throws DbException + */ + public function getBells(): Response + { + $data = AdminNoticeService::getBells(get_admin_id()); + return $this->success('获取成功', '/', $data); + } + + /** + * 阅读消息 + * @return Response + * @throws OperateException + */ + public function read(): Response + { + $id = request()->get('id', 0); + $detail = AdminNoticeService::getDetail($id, get_admin_id()); + return view('/system/admin_notice/' . $detail['type'], [ + 'detail' => $detail + ]); + } + + /** + * 发送消息 + * @return Response + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @throws OperateException + */ + public function add(): Response + { + if (request()->isPost()) { + $post = request()->post(); + $post['send_id'] = get_admin_id(); + $post['type'] = AdminNoticeEnum::MESSAGE; + $post['send_ip'] = request()->getRealIp(); + $post['create_time'] = time(); + validate(\app\common\validate\system\AdminNotice::class)->check($post); + AdminNoticeService::add($post); + return $this->success('发送成功'); + } + + return view('/system/admin_notice/add', [ + 'adminList' => AdminModel::select()->toArray(), + ]); + } + + /** + * 清空消息 + * @return Response + * @throws Exception + */ + public function clear(): Response + { + $type = input('type', AdminNoticeEnum::NOTICE); + $where[] = ['type', '=', $type]; + $where[] = ['admin_id', '=', get_admin_id()]; + $where[] = ['status', '=', AdminNoticeEnum::STATUS_READ]; + try { + AdminNoticeModel::where($where)->delete(); + } catch (Exception $e) { + return $this->error('清空失败'); + } + return $this->success('清空成功'); + } + + /** + * 全部消息已读 + * @return Response + * @throws Exception + */ + public function readAll(): Response + { + $type = input('type', AdminNoticeEnum::NOTICE); + $where[] = ['type', '=', $type]; + $where[] = ['admin_id', '=', get_admin_id()]; + $where[] = ['status', '=', AdminNoticeEnum::STATUS_UNREAD]; + try { + AdminNoticeModel::where($where)->update(['status' => 1]); + } catch (Exception $e) { + return $this->error('操作失败'); + } + + return $this->success('全部已读成功'); + } + + /** + * 删除消息 + * @return Response + * @throws OperateException + */ + public function del(): Response + { + $id = request()->get('id', 0); + AdminNoticeService::delete($id, get_admin_id()); + return $this->success('删除成功'); + } +} diff --git a/app/admin/view/system/admin_notice/bells.html b/app/admin/view/system/admin_notice/bells.html new file mode 100644 index 0000000..49afc28 --- /dev/null +++ b/app/admin/view/system/admin_notice/bells.html @@ -0,0 +1,258 @@ + + +
+ +
    +
  • {:__('通知')}({$count['notice']})
  • +
  • {:__('私信')}({$count['message']})
  • +
  • {:__('待办')}({$count['todo']})
  • +
+ +
+
+ + + +
style="display:black;" style="display:none;" > +
{:__('没有通知')}
+
+ + + + + +
+ +
+ + + + +
style="display:black;" style="display:none;" > +
{:__('没有私信')}
+
+ + + +
+ +
+ + + +
style="display:black;" style="display:none;" > +
{:__('没有待办')}
+
+ + + +
+ +
+
+ + + + \ No newline at end of file diff --git a/app/admin/view/system/admin_notice/index.html b/app/admin/view/system/admin_notice/index.html new file mode 100644 index 0000000..3029c49 --- /dev/null +++ b/app/admin/view/system/admin_notice/index.html @@ -0,0 +1,180 @@ + + + +
+
+
+ +
+
+
{:__('我的信箱')}
+
+
+
  • + + 待办项 +
  • +
  • + + 已发送 +
  • +
  • + + 系统通知 +
  • +
  • + + 我的私信 +
  • +
    +
    +
    + +
    + +
    + +
    +
    +
    + +
    +
    + +
    +
    + +
    + + + + + +
    +
    +
    +
    + + +
    +
    + +
    + +
    +
    + + + + + + + + + diff --git a/app/admin/view/system/admin_notice/message.html b/app/admin/view/system/admin_notice/message.html new file mode 100644 index 0000000..4125d5b --- /dev/null +++ b/app/admin/view/system/admin_notice/message.html @@ -0,0 +1,56 @@ + + +
    +
    +
    +
    +
    发送者: + + {$detail.nickname|default='隐藏用户'} +
    +
    {$detail.create_time}
    +
    +
    {$detail.content|raw}
    +
    +
    + +
    + + + + diff --git a/app/admin/view/system/admin_notice/notice.html b/app/admin/view/system/admin_notice/notice.html new file mode 100644 index 0000000..a3a7bd8 --- /dev/null +++ b/app/admin/view/system/admin_notice/notice.html @@ -0,0 +1,19 @@ + + +
    +
    +
    +
    标题:{$detail.title}
    +
    时间:{$detail.create_time}
    +
    +
    {$detail.content|raw}
    +
    +
    +

    本消息属系统通知,来源于业务流程管理系统,请勿回复

    +

    在系统使用过程中,如果有问题请联系网站运维组:##

    +
    + +
    + diff --git a/app/admin/view/system/admin_notice/todo.html b/app/admin/view/system/admin_notice/todo.html new file mode 100644 index 0000000..a58999c --- /dev/null +++ b/app/admin/view/system/admin_notice/todo.html @@ -0,0 +1,23 @@ + + +
    +
    +
    +
    +
    {$detail.title}
    +
    任务创建于:{$detail.create_time}
    +
    +
    {$detail.content|raw}
    +
    +

    本消息属系统工作流待办流程管理

    +

    在系统使用过程中,如果有问题请联系网站运维组

    +
    +
    + + +
    +
    + + \ No newline at end of file diff --git a/app/common/validate/system/AdminNotice.php b/app/common/validate/system/AdminNotice.php new file mode 100644 index 0000000..144719f --- /dev/null +++ b/app/common/validate/system/AdminNotice.php @@ -0,0 +1,73 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'admin_id' => 'require|checkUser', + 'send_id' => 'checkReceive', + 'type' => 'require', + 'content' => 'require', + ]; + + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = [ + 'admin_id.require' => '请选择用户', + 'admin_id.checkUser' => '用户不存在', + 'type.require' => '请选择消息类型', + 'content.require' => '消息内容不能为空', + 'send_id.checkReceive' => '不能给自己发送消息', + ]; + + // 测试验证场景 + protected $scene = []; + + /** + * 验证用户组权限 + * @param $value + * @param $rule + * @param $data + * @return bool + */ + protected function checkUser($value, $rule, $data): bool + { + $result = AdminModel::where('id', $value)->findOrEmpty()->toArray(); + if (empty($result)) { + return false; + } + return true; + } + + /** + * @param $value + * @param $rule + * @param $data + * @return bool + */ + protected function checkReceive($value, $rule, $data): bool + { + if ($data['type'] == AdminNoticeEnum::MESSAGE && $value == $data['admin_id']) { + return false; + } + + return true; + } +}