diff --git a/app/adminapi/controller/manage_communication/ManageInfoReportController.php b/app/adminapi/controller/manage_communication/ManageInfoReportController.php new file mode 100644 index 000000000..94f0cc663 --- /dev/null +++ b/app/adminapi/controller/manage_communication/ManageInfoReportController.php @@ -0,0 +1,108 @@ +dataLists(new ManageInfoReportLists()); + } + + + /** + * @notes 添加项目管理--项目信息上报 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function add() + { + $params = (new ManageInfoReportValidate())->post()->goCheck('add'); + $result = ManageInfoReportLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ManageInfoReportLogic::getError()); + } + + + /** + * @notes 编辑项目管理--项目信息上报 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function edit() + { + $params = (new ManageInfoReportValidate())->post()->goCheck('edit'); + $result = ManageInfoReportLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ManageInfoReportLogic::getError()); + } + + + /** + * @notes 删除项目管理--项目信息上报 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function delete() + { + $params = (new ManageInfoReportValidate())->post()->goCheck('delete'); + ManageInfoReportLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取项目管理--项目信息上报详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function detail() + { + $params = (new ManageInfoReportValidate())->goCheck('detail'); + $result = ManageInfoReportLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/manage_communication/ManageInfoReportLists.php b/app/adminapi/lists/manage_communication/ManageInfoReportLists.php new file mode 100644 index 000000000..13c6ca0d0 --- /dev/null +++ b/app/adminapi/lists/manage_communication/ManageInfoReportLists.php @@ -0,0 +1,84 @@ + ['project_id', 'severity'], + '%like%' => ['giver'], + ]; + } + + + /** + * @notes 获取项目管理--项目信息上报列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function lists(): array + { + return ManageInfoReport::where($this->searchWhere) + ->field(['id', 'project_id', 'abstract', 'happen_date', 'severity', 'info_cate', 'giver']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $project = ManageProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty(); + $data['project_name'] = $project['project_name']; + $data['severity_text'] = $data->severity_text; + $data['info_cate_text'] = $data->info_cate_text; + }) + ->toArray(); + } + + + /** + * @notes 获取项目管理--项目信息上报数量 + * @return int + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function count(): int + { + return ManageInfoReport::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/manage_communication/ManageInfoReportLogic.php b/app/adminapi/logic/manage_communication/ManageInfoReportLogic.php new file mode 100644 index 000000000..7fe4a8927 --- /dev/null +++ b/app/adminapi/logic/manage_communication/ManageInfoReportLogic.php @@ -0,0 +1,130 @@ + $params['project_id'], + 'abstract' => $params['abstract'], + 'happen_date' => !empty($params['happen_date']) ? strtotime($params['happen_date']) : 0, + 'severity' => $params['severity'] ?? 0, + 'info_cate' => $params['info_cate'] ? json_encode($params['info_cate']) : null, + 'content' => $params['content'] ?? '', + 'opinions' => $params['opinions'] ?? '', + 'giver' => $params['giver'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : 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/03/08 13:33 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ManageInfoReport::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'abstract' => $params['abstract'], + 'happen_date' => !empty($params['happen_date']) ? strtotime($params['happen_date']) : 0, + 'severity' => $params['severity'] ?? 0, + 'info_cate' => $params['info_cate'] ? json_encode($params['info_cate']) : null, + 'content' => $params['content'] ?? '', + 'opinions' => $params['opinions'] ?? '', + 'giver' => $params['giver'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time(), + 'update_time' => 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/03/08 13:33 + */ + public static function delete(array $params): bool + { + return ManageInfoReport::destroy($params['id']); + } + + + /** + * @notes 获取项目管理--项目信息上报详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public static function detail($params): array + { + $data = ManageInfoReport::withoutField('update_time,delete_time')->findOrEmpty($params['id']); + $project = ManageProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty(); + $data['project_name'] = $project['project_name']; + $data['severity_text'] = $data->severity_text; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/manage_communication/ManageInfoReportValidate.php b/app/adminapi/validate/manage_communication/ManageInfoReportValidate.php new file mode 100644 index 000000000..8904ee3bb --- /dev/null +++ b/app/adminapi/validate/manage_communication/ManageInfoReportValidate.php @@ -0,0 +1,160 @@ + 'require|checkData', + 'project_id' => 'require|checkProject', + 'abstract' => 'require', + 'happen_date' => 'require|dateFormat:Y-m-d', + 'severity' => 'checkSeverity', + 'info_cate' => 'checkInfoCate', + 'create_user' => 'require', + 'create_time' => 'require|dateFormat:Y-m-d H:i:s', + 'annex' => 'checkAnnex' + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_id' => '项目id', + 'abstract' => '信息摘要', + 'happen_date' => '发生日期', + 'severity' => '严重程度', + 'content' => '信息内容', + 'opinions' => '项目部意见', + 'giver' => '主送人', + 'create_user' => '创建人', + 'create_time' => '创建时间', + ]; + + + /** + * @notes 添加场景 + * @return ManageInfoReportValidate + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ManageInfoReportValidate + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ManageInfoReportValidate + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ManageInfoReportValidate + * @author likeadmin + * @date 2024/03/08 13:33 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = ManageInfoReport::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '数据不存在'; + } + return true; + } + + public function checkProject($value): bool|string + { + $data = ManageProject::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目信息不存在'; + } + return true; + } + + public function checkSeverity($value): bool|string + { + $dict = DictData::where('type_value','severity')->column('value'); + if(!in_array($value,$dict)){ + return '严重程度数据值无效'; + } + return true; + } + + public function checkInfoCate($value): bool|string + { + if(empty($value)) return true; + if(!is_array($value)) return '信息类别数据格式错误'; + $dict = DictData::where('type_value','info_cate')->column('value'); + foreach($value as $v){ + if(!in_array($v,$dict)){ + return '信息类别数据值无效'; + } + } + return true; + } + + public function checkAnnex($value): bool|string + { + if(!empty($value) && $value != '' && !is_array($value)){ + return '附件格式错误'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/manage_communication/ManageInfoReport.php b/app/common/model/manage_communication/ManageInfoReport.php new file mode 100644 index 000000000..ef03fbe32 --- /dev/null +++ b/app/common/model/manage_communication/ManageInfoReport.php @@ -0,0 +1,57 @@ +whereIn('value',json_decode($data['info_cate'],true))->column('name'); + return !empty($data['info_cate']) ? implode(',',$dict) : ''; + } + + public function getHappenDateAttr($value): string + { + return !empty($value) ? date('Y-m-d',$value) : ''; + } + + public function getSeverityTextAttr($value,$data){ + $dict = DictData::where('type_value','severity')->column('name','value'); + return !empty($data['severity']) ? $dict[$data['severity']] : ''; + } +} \ No newline at end of file