diff --git a/app/adminapi/controller/IndexController.php b/app/adminapi/controller/IndexController.php index f045dec53..f948221fb 100644 --- a/app/adminapi/controller/IndexController.php +++ b/app/adminapi/controller/IndexController.php @@ -14,18 +14,33 @@ 1=>'5分钟',2=>'15分钟',3=>'30分钟',4=>'1小时',5=>'2小时',6=>'1天' }; if(time() > strtotime($v['remind_time'])){ - Db::name('oa_message')->insert([ - 'title' => '您有一条新的日程安排提醒', - 'template' => 0, - 'content' => '您的日程安排还有'.$date.'开始,请合理安排时间', - 'from_uid' => 0, - 'to_uid' => $v['admin_id'], - 'type' => 1, - 'send_time' => time(), - 'status' => 1, - 'is_draft' => 1, - ]); + Db::startTrans(); + try { + Db::name('oa_message')->insert([ + 'title' => '您有一条新的日程安排提醒', + 'content' => '您的日程安排还有'.$date.'开始,请合理安排时间', + 'from_uid' => 0, + 'to_uid' => $v['admin_id'], + 'read_time' => 0, + 'create_time' => time(), + 'data_id' => $v['id'], + 'req_url' => '/adminapi/works.rcbg.oa_plan/detail' + ]); + OaPlan::where('id',$v['id'])->update(['is_remind'=>1]); + Db::commit(); + continue; + } catch (\Exception $e) { + Db::rollback(); + dump($e->getMessage()); + continue; + } } } + $message_count = Db::name('oa_message')->where([ + ['to_uid','=',$this->adminId], + ['read_time','=',0], + ['delete_time','=',null], + ])->count(); + return $this->success('ok',['message_count'=>$message_count]); } } \ No newline at end of file diff --git a/app/adminapi/controller/works/OaMessageController.php b/app/adminapi/controller/works/OaMessageController.php new file mode 100644 index 000000000..daca3688d --- /dev/null +++ b/app/adminapi/controller/works/OaMessageController.php @@ -0,0 +1,107 @@ +dataLists(new OaMessageLists()); + } + + + /** + * @notes 添加系统消息 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/29 14:04 + */ +// public function add() +// { +// $params = (new OaMessageValidate())->post()->goCheck('add'); +// $result = OaMessageLogic::add($params); +// if (true === $result) { +// return $this->success('添加成功', [], 1, 1); +// } +// return $this->fail(OaMessageLogic::getError()); +// } + + + /** + * @notes 编辑系统消息 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/29 14:04 + */ +// public function edit() +// { +// $params = (new OaMessageValidate())->post()->goCheck('edit'); +// $result = OaMessageLogic::edit($params); +// if (true === $result) { +// return $this->success('编辑成功', [], 1, 1); +// } +// return $this->fail(OaMessageLogic::getError()); +// } + + + /** + * @notes 删除系统消息 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function delete() + { + $params = (new OaMessageValidate())->post()->goCheck('delete'); + OaMessageLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取系统消息详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function detail() + { + $params = (new OaMessageValidate())->goCheck('detail'); + $result = OaMessageLogic::detail($params); + return $this->data($result); + } + +} \ No newline at end of file diff --git a/app/adminapi/lists/works/OaMessageLists.php b/app/adminapi/lists/works/OaMessageLists.php new file mode 100644 index 000000000..dc43024c5 --- /dev/null +++ b/app/adminapi/lists/works/OaMessageLists.php @@ -0,0 +1,83 @@ + ['title'], + ]; + } + + + /** + * @notes 获取系统消息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function lists(): array + { + $params = $this->request->get(['start_time','end_time']); + if(!empty($params['start_time']) && !empty($params['end_time'])){ + $this->where[] = ['create_time','between',[strtotime($params['start_time']),strtotime($params['end_time'])]]; + } + return OaMessage::where($this->searchWhere)->where($this->where)->where('to_uid',$this->adminId) + ->field(['id', 'title', 'content', 'read_time', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $data['is_read'] = empty($data['read_time']) ? '未读' : '已读'; + }) + ->toArray(); + } + + + /** + * @notes 获取系统消息数量 + * @return int + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function count(): int + { + return OaMessage::where($this->searchWhere)->where($this->where)->where('to_uid',$this->adminId)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/works/OaMessageLogic.php b/app/adminapi/logic/works/OaMessageLogic.php new file mode 100644 index 000000000..f06efed77 --- /dev/null +++ b/app/adminapi/logic/works/OaMessageLogic.php @@ -0,0 +1,121 @@ + $params['title'], + 'content' => $params['content'], + 'from_uid' => $params['from_uid'], + 'to_uid' => $params['to_uid'], + 'read_time' => $params['read_time'], + 'create_time' => $params['create_time'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑系统消息 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + OaMessage::where('id', $params['id'])->update([ + 'title' => $params['title'], + 'content' => $params['content'], + 'from_uid' => $params['from_uid'], + 'to_uid' => $params['to_uid'], + 'read_time' => $params['read_time'], + 'create_time' => $params['create_time'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除系统消息 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public static function delete(array $params): bool + { + return OaMessage::destroy($params['id']); + } + + + /** + * @notes 获取系统消息详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public static function detail($params): array + { + $data = OaMessage::findOrEmpty($params['id']); + $data['to_user_name'] = Admin::where('id',$data['to_uid'])->value('name'); + OaMessage::where('id',$params['id'])->update(['read_time'=>time()]); + return $data->toArray(); + } + +} \ No newline at end of file diff --git a/app/adminapi/validate/works/OaMessageValidate.php b/app/adminapi/validate/works/OaMessageValidate.php new file mode 100644 index 000000000..f71410d2c --- /dev/null +++ b/app/adminapi/validate/works/OaMessageValidate.php @@ -0,0 +1,104 @@ + 'require', + 'title' => 'require', + 'from_uid' => 'require', + 'to_uid' => 'require', + 'read_time' => 'require', + 'create_time' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'title' => '消息主题', + 'from_uid' => '发送人id', + 'to_uid' => '接收人id', + 'read_time' => '阅读时间', + 'create_time' => '创建时间', + ]; + + + /** + * @notes 添加场景 + * @return OaMessageValidate + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function sceneAdd() + { + return $this->only(['title','from_uid','to_uid','read_time','create_time']); + } + + + /** + * @notes 编辑场景 + * @return OaMessageValidate + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function sceneEdit() + { + return $this->only(['id','title','from_uid','to_uid','read_time','create_time']); + } + + + /** + * @notes 删除场景 + * @return OaMessageValidate + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OaMessageValidate + * @author likeadmin + * @date 2024/05/29 14:04 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/works/OaMessage.php b/app/common/model/works/OaMessage.php new file mode 100644 index 000000000..34461f9d2 --- /dev/null +++ b/app/common/model/works/OaMessage.php @@ -0,0 +1,34 @@ +