Browse Source

refactor(PhysicalTest): 重构体测报告详情接口

- 修改接口参数,使用体测报告的 id 替代员工或学生资源 id
- 更新服务层方法,增加字段选择功能
- 优化数据查询,关联查询学生资源信息
- 添加综合评分计算逻辑
master
liutong 10 months ago
parent
commit
8d5e9224b9
  1. 17
      niucloud/app/api/controller/apiController/PhysicalTest.php
  2. 31
      niucloud/app/service/api/apiService/PhysicalTestService.php

17
niucloud/app/api/controller/apiController/PhysicalTest.php

@ -44,19 +44,22 @@ class PhysicalTest extends BaseApiService
//详情 //详情
public function info(Request $request) public function info(Request $request)
{ {
$personnel_id = $request->param('personnel_id', '');//员工人力资源表id(两个参数2选1) $id = $request->param('id', '');//体测报告的id
$customer_resources_id = $request->param('customer_resources_id', '');//学生资源表id(两个参数2选1)
if (empty($personnel_id) && empty($customer_resources_id)) { if (empty($id)) {
return fail('缺少参数'); return fail('缺少参数');
} }
$where = [ $where = [
'personnel_id' => $personnel_id, 'id' => $id,
'customer_resources_id' => $customer_resources_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']);
} }
} }

31
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(); $model = new PhysicalTest();
//判断用没有员工id //判断用没有体测报告id
if (!empty($where['personnel_id'])) { if (!empty($where['id'])) {
$model = $model->where('personnel_id', $where['personnel_id']); $model = $model->where('id', $where['id']);
}
if (!empty($where['customer_resources_id'])) {
$model = $model->where('customer_resources_id', $where['customer_resources_id']);
} }
$data = $model->find();
$data = $model
->field($field)
->append([
'customerResources'
])
->with([
'customerResourcesHasOne'
])
->find();
if ($data) { if ($data) {
$data = $data->toArray(); $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 = [ $res = [
'code' => 1, 'code' => 1,
'msg' => '操作成功', 'msg' => '操作成功',

Loading…
Cancel
Save