From 8d5e9224b96d4ccd5080e61a7d865603497d0779 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 5 Jun 2025 17:30:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(PhysicalTest):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BD=93=E6=B5=8B=E6=8A=A5=E5=91=8A=E8=AF=A6=E6=83=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改接口参数,使用体测报告的 id 替代员工或学生资源 id - 更新服务层方法,增加字段选择功能 - 优化数据查询,关联查询学生资源信息 - 添加综合评分计算逻辑 --- .../controller/apiController/PhysicalTest.php | 17 +++++----- .../api/apiService/PhysicalTestService.php | 31 +++++++++++++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/niucloud/app/api/controller/apiController/PhysicalTest.php b/niucloud/app/api/controller/apiController/PhysicalTest.php index 6f5e8443..9c7bbe1e 100644 --- a/niucloud/app/api/controller/apiController/PhysicalTest.php +++ b/niucloud/app/api/controller/apiController/PhysicalTest.php @@ -44,19 +44,22 @@ class PhysicalTest extends BaseApiService //详情 public function info(Request $request) { - $personnel_id = $request->param('personnel_id', '');//员工人力资源表id(两个参数2选1) - $customer_resources_id = $request->param('customer_resources_id', '');//学生资源表id(两个参数2选1) - if (empty($personnel_id) && empty($customer_resources_id)) { + $id = $request->param('id', '');//体测报告的id + + if (empty($id)) { return fail('缺少参数'); } $where = [ - 'personnel_id' => $personnel_id, - 'customer_resources_id' => $customer_resources_id, + 'id' => $id, ]; - $res = (new ChatService())->getChatFriendsPage($where); + $res = (new PhysicalTestService())->getInfo($where); - return success($res); + if(!$res['code']){ + return fail($res['msg']); + } + + return success($res['data']); } } diff --git a/niucloud/app/service/api/apiService/PhysicalTestService.php b/niucloud/app/service/api/apiService/PhysicalTestService.php index 95d201cd..08b429a5 100644 --- a/niucloud/app/service/api/apiService/PhysicalTestService.php +++ b/niucloud/app/service/api/apiService/PhysicalTestService.php @@ -69,21 +69,34 @@ class PhysicalTestService extends BaseApiService } //查询详情 - public function getTestInfo(array $where) + public function getInfo(array $where,string $field = '*') { - $model = new ChatFriends(); - //判断用没有员工id - if (!empty($where['personnel_id'])) { - $model = $model->where('personnel_id', $where['personnel_id']); - } - if (!empty($where['customer_resources_id'])) { - $model = $model->where('customer_resources_id', $where['customer_resources_id']); + $model = new PhysicalTest(); + //判断用没有体测报告id + if (!empty($where['id'])) { + $model = $model->where('id', $where['id']); } - $data = $model->find(); + + $data = $model + ->field($field) + ->append([ + 'customerResources' + ]) + ->with([ + 'customerResourcesHasOne' + ]) + ->find(); if ($data) { $data = $data->toArray(); + + $age = $data['customerResourcesHasOne']['age'];//年龄 + $gender = $data['customerResourcesHasOne']['gender'] == 'female' ? 2 : 1;//性别( 1:男,2:女) + $height = $data['height'];//身高 + $weight = $data['weight'];//体重 + $data['calculateChildHealthScore'] = calculateChildHealthScore($age, $gender, $height, $weight);//综合评分 + $res = [ 'code' => 1, 'msg' => '操作成功',