From 0fe30a5b7d781f25ced412f1791c864751a76e6b Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Mon, 3 Jun 2024 15:07:25 +0800 Subject: [PATCH] update --- .../jxgl/OaExamineTempController.php | 111 ++++++++++++++ .../lists/jxgl/OaExamineTempLists.php | 81 ++++++++++ .../logic/jxgl/OaExamineTempLogic.php | 141 +++++++++++++++++ .../validate/jxgl/OaExamineTempValidate.php | 144 ++++++++++++++++++ app/common/model/jxgl/OaExamineTemp.php | 38 +++++ app/common/model/jxgl/OaExamineTempItem.php | 34 +++++ 6 files changed, 549 insertions(+) create mode 100644 app/adminapi/controller/jxgl/OaExamineTempController.php create mode 100644 app/adminapi/lists/jxgl/OaExamineTempLists.php create mode 100644 app/adminapi/logic/jxgl/OaExamineTempLogic.php create mode 100644 app/adminapi/validate/jxgl/OaExamineTempValidate.php create mode 100644 app/common/model/jxgl/OaExamineTemp.php create mode 100644 app/common/model/jxgl/OaExamineTempItem.php diff --git a/app/adminapi/controller/jxgl/OaExamineTempController.php b/app/adminapi/controller/jxgl/OaExamineTempController.php new file mode 100644 index 000000000..431fba4e7 --- /dev/null +++ b/app/adminapi/controller/jxgl/OaExamineTempController.php @@ -0,0 +1,111 @@ +dataLists(new OaExamineTempLists()); + } + + + /** + * @notes 添加考核模板 + * @return \think\response\Json + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function add() + { + $params = (new OaExamineTempValidate())->post()->goCheck('add'); + $result = OaExamineTempLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(OaExamineTempLogic::getError()); + } + + + /** + * @notes 编辑考核模板 + * @return \think\response\Json + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function edit() + { + $params = (new OaExamineTempValidate())->post()->goCheck('edit'); + $result = OaExamineTempLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(OaExamineTempLogic::getError()); + } + + + /** + * @notes 删除考核模板 + * @return \think\response\Json + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function delete() + { + $params = (new OaExamineTempValidate())->post()->goCheck('delete'); + $result = OaExamineTempLogic::delete($params); + if (true === $result) { + return $this->success('删除成功', [], 1, 1); + } + return $this->fail(OaExamineTempLogic::getError()); + } + + + /** + * @notes 获取考核模板详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function detail() + { + $params = (new OaExamineTempValidate())->goCheck('detail'); + $result = OaExamineTempLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/jxgl/OaExamineTempLists.php b/app/adminapi/lists/jxgl/OaExamineTempLists.php new file mode 100644 index 000000000..90473d933 --- /dev/null +++ b/app/adminapi/lists/jxgl/OaExamineTempLists.php @@ -0,0 +1,81 @@ + ['examine_type'], + '%like%' => ['temp_name'], + ]; + } + + + /** + * @notes 获取考核模板列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function lists(): array + { + return OaExamineTemp::withoutField('update_time,delete_time')->where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $data['examine_type_text'] = $data->examine_type_text; + $data['total_score'] = OaExamineTempItem::where('examine_temp_id',$data['id'])->sum('score'); + }) + ->toArray(); + } + + + /** + * @notes 获取考核模板数量 + * @return int + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function count(): int + { + return OaExamineTemp::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/jxgl/OaExamineTempLogic.php b/app/adminapi/logic/jxgl/OaExamineTempLogic.php new file mode 100644 index 000000000..00b43a02e --- /dev/null +++ b/app/adminapi/logic/jxgl/OaExamineTempLogic.php @@ -0,0 +1,141 @@ + $params['examine_type'], + 'temp_name' => $params['temp_name'], + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : 0 + ]); + foreach($params['detail'] as &$v){ + $v['examine_temp_id'] = $res['id']; + $v['create_time'] = time(); + } + (new OaExamineTempItem)->saveAll($params['detail']); + 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/06/03 13:35 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + OaExamineTemp::where('id', $params['id'])->update([ + 'examine_type' => $params['examine_type'], + 'temp_name' => $params['temp_name'], + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : 0, + 'update_time' => time() + ]); + //删除原数据 + OaExamineTempItem::destroy(function($query)use($params){ + $query->where('examine_temp_id','=',$params['id']); + }); + foreach($params['detail'] as &$v){ + $v['examine_temp_id'] = $params['id']; + $v['create_time'] = time(); + } + (new OaExamineTempItem)->saveAll($params['detail']); + 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/06/03 13:35 + */ + public static function delete(array $params): bool + { + Db::startTrans(); + try { + OaExamineTemp::destroy($params['id']); + OaExamineTempItem::destroy(function($query)use($params){ + $query->where('examine_temp_id','=',$params['id']); + }); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 获取考核模板详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public static function detail($params): array + { + $data = OaExamineTemp::withoutField('update_time,delete_time')->findOrEmpty($params['id']); + $data['examine_type_text'] = $data->examine_type_text; + $data['detail'] = OaExamineTempItem::field('id,examine_item,score,examine_desc')->where('examine_temp_id',$params['id'])->select()->toArray(); + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/jxgl/OaExamineTempValidate.php b/app/adminapi/validate/jxgl/OaExamineTempValidate.php new file mode 100644 index 000000000..d128128ca --- /dev/null +++ b/app/adminapi/validate/jxgl/OaExamineTempValidate.php @@ -0,0 +1,144 @@ + 'require', + 'examine_type' => 'require|checkExamineType', + 'temp_name' => 'require', + 'create_user' => 'require', + 'create_time' => 'require|dateFormat:Y-m-d H:i:s', + 'detail' => 'require|checkDetail' + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'examine_type' => '考核类别', + 'temp_name' => '模板名称', + 'create_user' => '创建人', + 'create_time' => '创建时间', + 'detail' => '考核项' + ]; + + + /** + * @notes 添加场景 + * @return OaExamineTempValidate + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function sceneAdd() + { + return $this->only(['examine_type','temp_name','create_user','create_time','detail']); + } + + + /** + * @notes 编辑场景 + * @return OaExamineTempValidate + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function sceneEdit() + { + return $this->only(['id','examine_type','temp_name','create_user','create_time','detail']); + } + + + /** + * @notes 删除场景 + * @return OaExamineTempValidate + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OaExamineTempValidate + * @author likeadmin + * @date 2024/06/03 13:35 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkExamineType($value): bool|string + { + $dict = DictData::where('type_value','jxgl_check_type')->column('value'); + if(!in_array($value,$dict)){ + return '考核类别无效'; + } + return true; + } + + public function checkDetail($value): bool|string + { + if(!is_array($value) || empty($value)){ + return '考核项数据格式错误'; + } + foreach($value as $k => $v){ + if(isset($v['id']) && !empty($v['id'])){ + $data = OaExamineTempItem::where('id',$v['id'])->findOrEmpty(); + if($data->isEmpty()){ + return '第'.($k+1).'行数据不存在'; + } + } + if(empty($v['examine_item'])){ + return '第'.($k+1).'行考核项为空'; + } + if(empty($v['score'])){ + return '第'.($k+1).'行分数为空'; + }else{ + if(!is_numeric($v['score']) || $v['score'] < 0){ + return '第'.($k+1).'行分数必须是大于0的数字'; + } + } + if(empty($v['examine_desc'])){ + return '第'.($k+1).'行考核说明为空'; + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/jxgl/OaExamineTemp.php b/app/common/model/jxgl/OaExamineTemp.php new file mode 100644 index 000000000..6417c3314 --- /dev/null +++ b/app/common/model/jxgl/OaExamineTemp.php @@ -0,0 +1,38 @@ +column('name','value'); + return !empty($data['examine_type']) ? $dict[$data['examine_type']] : ''; + } +} \ No newline at end of file diff --git a/app/common/model/jxgl/OaExamineTempItem.php b/app/common/model/jxgl/OaExamineTempItem.php new file mode 100644 index 000000000..a70223da6 --- /dev/null +++ b/app/common/model/jxgl/OaExamineTempItem.php @@ -0,0 +1,34 @@ +