From f87916a61bc0cc1eeb8d121648b9ca19e3e7284e Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 24 Jun 2025 15:09:38 +0800 Subject: [PATCH] =?UTF-8?q?[notice]=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service.php | 3 +- src/controller/Broadcast.php | 118 +++++++++++++++++++++++++++ src/model/NoticeBroadcast.php | 34 ++++++++ src/view/broadcast/form.html | 99 ++++++++++++++++++++++ src/view/broadcast/index.html | 50 ++++++++++++ src/view/broadcast/index_search.html | 30 +++++++ src/view/broadcast/view.html | 11 +++ src/view/notice/index.html | 8 +- 8 files changed, 351 insertions(+), 2 deletions(-) create mode 100644 src/controller/Broadcast.php create mode 100644 src/model/NoticeBroadcast.php create mode 100644 src/view/broadcast/form.html create mode 100644 src/view/broadcast/index.html create mode 100644 src/view/broadcast/index_search.html create mode 100644 src/view/broadcast/view.html diff --git a/src/Service.php b/src/Service.php index 4f8766f..a92fdd5 100644 --- a/src/Service.php +++ b/src/Service.php @@ -13,8 +13,9 @@ class Service extends Plugin { return [ [ - 'name' => '通知提醒', + 'name' => '通知', 'subs' => [ + ['name' => '通知通告', 'icon' => 'layui-icon layui-icon-cols', 'url' => 'notice/broadcast/index'], ['name' => '通知提醒', 'icon' => 'layui-icon layui-icon-cols', 'url' => 'notice/notice/index'], ] ] diff --git a/src/controller/Broadcast.php b/src/controller/Broadcast.php new file mode 100644 index 0000000..18e248d --- /dev/null +++ b/src/controller/Broadcast.php @@ -0,0 +1,118 @@ +title = '通知公告'; + NoticeBroadcast::mQuery()->layTable(function () { + $this->types = NoticeBroadcast::types(); + }, static function (QueryHelper $query) { + $query->equal('type,status')->like('title,content'); + }); + } + + /** + * 添加通知公告 + * @auth true + * @return void + */ + public function add() + { + NoticeBroadcast::mForm('form'); + } + + /** + * 编辑通知公告 + * @auth true + * @return void + */ + public function edit() + { + NoticeBroadcast::mForm('form'); + } + + protected function _form_filter(array &$vo) + { + if ($this->request->isPost()) { + if (empty($vo['to_depts'])) { + if (empty($vo['id'])) { + $this->error('请选择通知对象!'); + } + unset($vo['to_depts']); + } else { + $vo['to_depts'] = arr2str($vo['to_depts']); + } + if (empty($vo['to'])) { + if (empty($vo['id'])) { + $this->error('请选择通知对象!'); + } + unset($vo['to']); + } + $vo['create_by'] = session('user.id'); + } else { + $this->depts = StaffDept::items(); + $this->types = NoticeBroadcast::types(); + } + } + + protected function _form_result(bool $status, $vo) + { + if ($status) { + if (empty($vo['id']) || !empty($vo['rebroadcast'])) { + if (!empty($vo['to_all'])) { + $staffs = StaffUser::mk()->select(); + } else { + $depts = str2arr($vo['to_depts']); + $staffs = StaffUser::mk()->whereIn('dept_id', $depts)->select(); + } + NoticeService::send_notice_to($vo['type'], $vo['content'], url('broadcast/view', ['id' => $vo['id']])->build(), $staffs->map(function($staff) { + return $staff['id']; + })); + } + } + } + + /** + * 查看通知公告 + * @auth false + * @return void + */ + public function view() + { + $this->title = '查看通知公告'; + NoticeBroadcast::mForm('view'); + } + + protected function _view_form_filter(array &$vo) { + $vo['creator'] = StaffUser::mk()->where(['id' => $vo['create_by']])->findOrEmpty(); + } + + /** + * 删除通知公告 + * @auth true + * @return void + */ + public function remove() + { + NoticeBroadcast::mDelete(); + } +} \ No newline at end of file diff --git a/src/model/NoticeBroadcast.php b/src/model/NoticeBroadcast.php new file mode 100644 index 0000000..6f45007 --- /dev/null +++ b/src/model/NoticeBroadcast.php @@ -0,0 +1,34 @@ +where('is_deleted', '=', 0); + } + + public function scopeDeleted(Query $query): void + { + $query->where('is_deleted', '=', 1); + } + + public static function types() + { + return static::mk()->group('type')->field('type')->select(); + } + + public function creator() + { + return $this->hasOne(StaffUser::class, 'id', 'create_by')->with(['dept']); + } +} \ No newline at end of file diff --git a/src/view/broadcast/form.html b/src/view/broadcast/form.html new file mode 100644 index 0000000..cb2d342 --- /dev/null +++ b/src/view/broadcast/form.html @@ -0,0 +1,99 @@ +
+
+
+ 基础信息 + + + +
+
+ 通知人 + {notempty name='vo.id'} + + + {/notempty} + +
+ +
+
+ +
+ {foreach $depts as $dept} + + {/foreach} +
+
+
+
+ +
+ {notempty name='vo.id'}{/notempty} + + +
+ + +
+
+ \ No newline at end of file diff --git a/src/view/broadcast/index.html b/src/view/broadcast/index.html new file mode 100644 index 0000000..63ff35c --- /dev/null +++ b/src/view/broadcast/index.html @@ -0,0 +1,50 @@ +{extend name='table'} + +{block name="button"} + +{:lang('新 增')} + + +{:lang('批量删除')} + +{/block} + +{block name="content"} +
+ {include file="broadcast/index_search"} +
+
+ + +{/block} \ No newline at end of file diff --git a/src/view/broadcast/index_search.html b/src/view/broadcast/index_search.html new file mode 100644 index 0000000..01b8079 --- /dev/null +++ b/src/view/broadcast/index_search.html @@ -0,0 +1,30 @@ +
+ {:lang('条件搜索')} + +
\ No newline at end of file diff --git a/src/view/broadcast/view.html b/src/view/broadcast/view.html new file mode 100644 index 0000000..63b6165 --- /dev/null +++ b/src/view/broadcast/view.html @@ -0,0 +1,11 @@ +
+
通知公告
+
+

{$vo.title}

+
+

{$vo.content}

+
+

通知时间:{$vo.create_at}

+

通知人:{$vo.creator.name|default='通知人员'}

+
+
\ No newline at end of file diff --git a/src/view/notice/index.html b/src/view/notice/index.html index b373966..060a4be 100644 --- a/src/view/notice/index.html +++ b/src/view/notice/index.html @@ -9,6 +9,12 @@ {include file="notice/index_search"}
+