From 2deb11111c9852b0530a665d1b2a12cef2bf2a77 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Thu, 29 Feb 2024 15:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=95=E5=9D=97=E8=AF=95?= =?UTF-8?q?=E4=BB=B6=E8=A7=81=E8=AF=81=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...pervisionTestBlocksSpecimensController.php | 108 +++++++++++ .../SupervisionTestBlocksSpecimensLists.php | 91 +++++++++ .../SupervisionWitnessSamplingLists.php | 3 + .../SupervisionTestBlocksSpecimensLogic.php | 176 ++++++++++++++++++ ...SupervisionTestBlocksSpecimensValidate.php | 173 +++++++++++++++++ .../supervision_work/SupervisionProblem.php | 2 +- .../SupervisionTestBlocksSpecimens.php | 52 ++++++ 7 files changed, 604 insertions(+), 1 deletion(-) create mode 100644 app/adminapi/controller/supervision_work/SupervisionTestBlocksSpecimensController.php create mode 100644 app/adminapi/lists/supervision_work/SupervisionTestBlocksSpecimensLists.php create mode 100644 app/adminapi/logic/supervision_work/SupervisionTestBlocksSpecimensLogic.php create mode 100644 app/adminapi/validate/supervision_work/SupervisionTestBlocksSpecimensValidate.php create mode 100644 app/common/model/supervision_work/SupervisionTestBlocksSpecimens.php diff --git a/app/adminapi/controller/supervision_work/SupervisionTestBlocksSpecimensController.php b/app/adminapi/controller/supervision_work/SupervisionTestBlocksSpecimensController.php new file mode 100644 index 000000000..96ac972b3 --- /dev/null +++ b/app/adminapi/controller/supervision_work/SupervisionTestBlocksSpecimensController.php @@ -0,0 +1,108 @@ +dataLists(new SupervisionTestBlocksSpecimensLists()); + } + + + /** + * @notes 添加工程监理--试块试件见证 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function add() + { + $params = (new SupervisionTestBlocksSpecimensValidate())->post()->goCheck('add'); + $result = SupervisionTestBlocksSpecimensLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SupervisionTestBlocksSpecimensLogic::getError()); + } + + + /** + * @notes 编辑工程监理--试块试件见证 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function edit() + { + $params = (new SupervisionTestBlocksSpecimensValidate())->post()->goCheck('edit'); + $result = SupervisionTestBlocksSpecimensLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SupervisionTestBlocksSpecimensLogic::getError()); + } + + + /** + * @notes 删除工程监理--试块试件见证 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function delete() + { + $params = (new SupervisionTestBlocksSpecimensValidate())->post()->goCheck('delete'); + SupervisionTestBlocksSpecimensLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取工程监理--试块试件见证详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function detail() + { + $params = (new SupervisionTestBlocksSpecimensValidate())->goCheck('detail'); + $result = SupervisionTestBlocksSpecimensLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/supervision_work/SupervisionTestBlocksSpecimensLists.php b/app/adminapi/lists/supervision_work/SupervisionTestBlocksSpecimensLists.php new file mode 100644 index 000000000..55473ae65 --- /dev/null +++ b/app/adminapi/lists/supervision_work/SupervisionTestBlocksSpecimensLists.php @@ -0,0 +1,91 @@ + ['project_id', 'test_result'], + '%like%' => ['test_type', 'code', 'witness', 'test_site'], + ]; + } + + + /** + * @notes 获取工程监理--试块试件见证列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function lists(): array + { + return SupervisionTestBlocksSpecimens::withoutField('update_time,delete_time')->where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty(); + $company = SupervisionParticipatingUnits::field('unit_name')->where('id',$data['company_id'])->findOrEmpty(); + $create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty(); + $data['project_name'] = $project['project_name']; + $data['company_name'] = $company['unit_name']; + $data['create_user_name'] = $create_user['name']; + $data['test_result_text'] = $data->test_result_text; + $data['problem_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',6)->count(); + $data['reply_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',6)->where('is_rectification',1)->count(); + }) + ->toArray(); + } + + + /** + * @notes 获取工程监理--试块试件见证数量 + * @return int + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function count(): int + { + return SupervisionTestBlocksSpecimens::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/lists/supervision_work/SupervisionWitnessSamplingLists.php b/app/adminapi/lists/supervision_work/SupervisionWitnessSamplingLists.php index 0a2a72c9b..704fda312 100644 --- a/app/adminapi/lists/supervision_work/SupervisionWitnessSamplingLists.php +++ b/app/adminapi/lists/supervision_work/SupervisionWitnessSamplingLists.php @@ -20,6 +20,7 @@ use app\common\model\supervision_project\SupervisionParticipatingUnits; use app\common\model\supervision_project\SupervisionProject; use app\common\model\supervision_work\SupervisionMaterialEntry; use app\common\model\supervision_work\SupervisionMaterialEntryDetail; +use app\common\model\supervision_work\SupervisionProblem; use app\common\model\supervision_work\SupervisionWitnessSampling; use app\common\lists\ListsSearchInterface; use app\common\model\supervision_work\SupervisionWitnessSamplingDetail; @@ -90,6 +91,8 @@ class SupervisionWitnessSamplingLists extends BaseAdminDataLists implements List $data['model'] = $material_entry_detail['model']; $data['entry_number'] = $material_entry_detail['entry_number']; $data['check_result_text'] = $data->check_result_text; + $data['problem_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',5)->count(); + $data['reply_num'] = SupervisionProblem::field('id')->where('data_id',$data['id'])->where('data_type',5)->where('is_rectification',1)->count(); }) ->toArray(); } diff --git a/app/adminapi/logic/supervision_work/SupervisionTestBlocksSpecimensLogic.php b/app/adminapi/logic/supervision_work/SupervisionTestBlocksSpecimensLogic.php new file mode 100644 index 000000000..98e93a5b7 --- /dev/null +++ b/app/adminapi/logic/supervision_work/SupervisionTestBlocksSpecimensLogic.php @@ -0,0 +1,176 @@ + $params['project_id'], + 'test_type' => $params['test_type'], + 'code' => data_unique_code('SKSJJZ'), + 'witness' => $params['witness'], + 'test_site' => $params['test_site'], + 'company_id' => $params['company_id'], + 'start_date' => !empty($params['start_date']) ? strtotime($params['start_date']) : 0, + 'end_date' => !empty($params['end_date']) ? strtotime($params['end_date']) : 0, + 'test_result' => $params['test_result'], + 'remark' => $params['remark'], + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'create_user' => $admin_id + ]); + if(!empty($params['problem'])){ + foreach($params['problem'] as $v){ + SupervisionProblem::create([ + 'data_id' => $res->id, + 'data_type' => 6, + 'problem_cate' => $v['problem_cate'], + 'problem_description' => $v['problem_description'], + 'problem_name' => $v['problem_name'], + 'create_user' => $admin_id, + ]); + } + } + 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/02/29 14:02 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + SupervisionTestBlocksSpecimens::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'test_type' => $params['test_type'], + 'witness' => $params['witness'], + 'test_site' => $params['test_site'], + 'company_id' => $params['company_id'], + 'start_date' => !empty($params['start_date']) ? strtotime($params['start_date']) : 0, + 'end_date' => !empty($params['end_date']) ? strtotime($params['end_date']) : 0, + 'test_result' => $params['test_result'], + 'remark' => $params['remark'], + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + ]); + if(!empty($params['problem'])){ + foreach($params['problem'] as $v){ + if(!empty($v['id'])){ + SupervisionProblem::where('id',$v['id'])->update([ + 'data_id' => $params['id'], + 'data_type' => 6, + 'problem_cate' => $v['problem_cate'], + 'problem_description' => $v['problem_description'], + 'problem_name' => $v['problem_name'], + 'update_time' => time(), + ]); + }else{ + SupervisionProblem::create([ + 'data_id' => $params['id'], + 'data_type' => 6, + 'problem_cate' => $v['problem_cate'], + 'problem_description' => $v['problem_description'], + 'problem_name' => $v['problem_name'], + 'create_user' => $admin_id, + ]); + } + } + } + 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/02/29 14:02 + */ + public static function delete(array $params): bool + { + $problem = SupervisionProblem::where('data_id',$params['id'])->where('data_type',6)->findOrEmpty(); + if(!$problem->isEmpty()){ + self::setError('该内容下存在试块试件见证问题数据,请先删除试块试件见证问题数据'); + return false; + } + return SupervisionTestBlocksSpecimens::destroy($params['id']); + } + + + /** + * @notes 获取工程监理--试块试件见证详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public static function detail($params): array + { + $data = SupervisionTestBlocksSpecimens::withoutField('update_time,delete_time')->findOrEmpty($params['id']); + $project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty(); + $company = SupervisionParticipatingUnits::field('unit_name')->where('id',$data['company_id'])->findOrEmpty(); + $create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty(); + $data['project_name'] = $project['project_name']; + $data['company_name'] = $company['unit_name']; + $data['create_user_name'] = $create_user['name']; + $data['test_result_text'] = $data->test_result_text; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/supervision_work/SupervisionTestBlocksSpecimensValidate.php b/app/adminapi/validate/supervision_work/SupervisionTestBlocksSpecimensValidate.php new file mode 100644 index 000000000..1ad8f2fec --- /dev/null +++ b/app/adminapi/validate/supervision_work/SupervisionTestBlocksSpecimensValidate.php @@ -0,0 +1,173 @@ + 'require|checkData', + 'project_id' => 'require|checkProject', + 'witness' => 'require', + 'company_id' => 'checkCompany', + 'start_date' => 'require|dateFormat:Y-m-d', + 'end_date' => 'require|dateFormat:Y-m-d', + 'test_result' => 'require|in:0,1', + 'annex' => 'checkAnnex', + 'problem' => 'checkProblem' + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_id' => '项目id', + 'test_type' => '试验类型', + 'code' => '编号', + 'witness' => '见证人', + 'test_site' => '试验部位', + 'company_id' => '单位名称', + 'start_date' => '开始日期', + 'end_date' => '结束日期', + 'test_result' => '试验结果 0-符合标准 1-不符合标准', + 'remark' => '备注', + 'create_user' => '创建人', + ]; + + + /** + * @notes 添加场景 + * @return SupervisionTestBlocksSpecimensValidate + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return SupervisionTestBlocksSpecimensValidate + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return SupervisionTestBlocksSpecimensValidate + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SupervisionTestBlocksSpecimensValidate + * @author likeadmin + * @date 2024/02/29 14:02 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value){ + $data = SupervisionTestBlocksSpecimens::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '数据不存在'; + } + return true; + } + + public function checkProject($value): bool|string + { + $data = SupervisionProject::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目信息不存在'; + } + return true; + } + + public function checkCompany($value,$rule,$params): bool|string + { + $data = SupervisionParticipatingUnits::where('id',$value)->where('project_id',$params['project_id'])->findOrEmpty(); + if($data->isEmpty()){ + return '单位信息不存在'; + } + return true; + } + + public function checkAnnex($value): bool|string + { + if(!empty($value) && $value != '' && !is_array($value)){ + return '附件格式错误'; + } + return true; + } + + public function checkProblem($value): bool|string + { + if(!isset($value) || $value == '') return true; + if(!is_array($value)) return '试块试件见证问题数据格式错误'; + foreach($value as $k=>$v){ + if(!empty($v['id'])){ + $data = SupervisionProblem::where('id',$v['id'])->findOrEmpty(); + if($data->isEmpty()){ + return '试块试件见证问题列表第'.($k+1).'行数据不存在'; + } + } + if(empty($v['problem_cate'])){ + return '试块试件见证问题列表第'.($k+1).'行问题分类为空'; + }else{ + $dict = DictData::where('type_value','problem_cate')->column('value'); + if(!in_array($v['problem_cate'],$dict)) return '试块试件见证问题列表第'.($k+1).'行问题分类数据值无效'; + } + if(empty($v['problem_description'])) return '试块试件见证问题列表第'.($k+1).'行问题说明为空'; + if(empty($v['problem_name'])) return '试块试件见证问题列表第'.($k+1).'行问题名称为空'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/supervision_work/SupervisionProblem.php b/app/common/model/supervision_work/SupervisionProblem.php index b453d063d..0f2715738 100644 --- a/app/common/model/supervision_work/SupervisionProblem.php +++ b/app/common/model/supervision_work/SupervisionProblem.php @@ -34,7 +34,7 @@ class SupervisionProblem extends BaseModel public function getDataTypeTextAttr($value,$data): string { //1-巡视 2-旁站 3-验收 4-设备进场 5-见证取样 6-材料平行检验 7-实体平行检验 - $arr = [1=>'巡视', 2=>'旁站', 3=>'验收', 4=>'设备进场', 5=>'见证取样', 6=>'材料平行检验', 7=>'实体平行检验']; + $arr = [1=>'巡视', 2=>'旁站', 3=>'验收', 4=>'设备进场', 5=>'见证取样', 6=>'试块试件见证', 7=>'材料平行检验', 8=>'实体平行检验']; return $arr[$data['data_type']]; } diff --git a/app/common/model/supervision_work/SupervisionTestBlocksSpecimens.php b/app/common/model/supervision_work/SupervisionTestBlocksSpecimens.php new file mode 100644 index 000000000..523e48816 --- /dev/null +++ b/app/common/model/supervision_work/SupervisionTestBlocksSpecimens.php @@ -0,0 +1,52 @@ +'符合标准', 1=>'不符合标准']; + return $arr[$data['test_result']]; + } + + public function getStartDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getEndDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } +} \ No newline at end of file