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 @@ +
+ \ 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"} +{$vo.content}
+通知时间:{$vo.create_at}
+通知人:{$vo.creator.name|default='通知人员'}
+