From c3aa8befeeaca80ec328b9b9189933745504e4dd Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 5 Jun 2025 17:25:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E4=BD=93?= =?UTF-8?q?=E6=B5=8B=E6=8A=A5=E5=91=8A=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增体测报告列表和详情接口 - 实现体测报告数据的查询和处理 - 添加学生资源一对一关系的方法 - 优化体测报告数据的展示逻辑 --- .../controller/apiController/PhysicalTest.php | 24 +++++++++++--- niucloud/app/api/route/route.php | 5 +++ .../app/model/physical_test/PhysicalTest.php | 7 ++++ .../api/apiService/PhysicalTestService.php | 33 +++++++++++-------- 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/niucloud/app/api/controller/apiController/PhysicalTest.php b/niucloud/app/api/controller/apiController/PhysicalTest.php index 340d7423..6f5e8443 100644 --- a/niucloud/app/api/controller/apiController/PhysicalTest.php +++ b/niucloud/app/api/controller/apiController/PhysicalTest.php @@ -12,21 +12,37 @@ namespace app\api\controller\apiController; use app\Request; -use app\service\api\apiService\CampusService; use app\service\api\apiService\ChatService; -use app\service\api\apiService\CommonService; +use app\service\api\apiService\PhysicalTestService; use core\base\BaseApiService; /** - * 体测报告控制器相关接口 + * 体测报告-控制器相关接口 * Class Personnel * @package app\api\controller\apiController */ class PhysicalTest extends BaseApiService { - //测试控制器Demo + //列表 public function index(Request $request) + { + $resource_id = $request->param('resource_id', '');//学生资源表id + if (empty($resource_id)) { + return fail('缺少参数'); + } + + $where = [ + 'resource_id' => $resource_id, + ]; + + $res = (new PhysicalTestService())->getList($where); + + return success($res); + } + + //详情 + 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) diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 8b5897a4..0a94a83b 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -347,6 +347,11 @@ Route::group(function () { //学生端-用户聊天-发送聊天内容 Route::post('xy/chat/sendChatMessages', 'apiController.Chat/sendChatMessages'); + //学生端-体测报告-列表 + Route::get('xy/physicalTest', 'apiController.PhysicalTest/index'); + //学生端-体测报告-详情 + Route::get('xy/physicalTest/info', 'apiController.PhysicalTest/info'); + diff --git a/niucloud/app/model/physical_test/PhysicalTest.php b/niucloud/app/model/physical_test/PhysicalTest.php index c81da6ec..61290480 100644 --- a/niucloud/app/model/physical_test/PhysicalTest.php +++ b/niucloud/app/model/physical_test/PhysicalTest.php @@ -81,6 +81,13 @@ class PhysicalTest extends BaseModel return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']); } + //获取学生资源一对一 + public function customerResourcesHasOne(){ + return $this->hasOne(CustomerResources::class, 'id', 'resource_id'); + } + + + public function student(){ return $this->hasOne(Student::class, 'id', 'student_id')->joinType('left')->withField('name,id')->bind(['student_id_name'=>'name']); } diff --git a/niucloud/app/service/api/apiService/PhysicalTestService.php b/niucloud/app/service/api/apiService/PhysicalTestService.php index 04254c09..95d201cd 100644 --- a/niucloud/app/service/api/apiService/PhysicalTestService.php +++ b/niucloud/app/service/api/apiService/PhysicalTestService.php @@ -14,10 +14,8 @@ namespace app\service\api\apiService; use app\model\campus\Campus; use app\model\campus_person_role\CampusPersonRole; use app\model\chat_friends\ChatFriends; -use app\model\chat_messages\ChatMessages; -use app\model\dict\Dict; +use app\model\physical_test\PhysicalTest; use core\base\BaseApiService; -use think\facade\Db; /** * 体测报告-控制器服务层 @@ -32,32 +30,41 @@ class PhysicalTestService extends BaseApiService } //查询列表 - public function getTestList(array $where) + public function getList(array $where,string $field = '*') { $page_params = $this->getPageParam();//获取请求参数中的页码+分页数 $page = $page_params['page']; $limit = $page_params['limit']; - $model = new ChatFriends(); + $model = new PhysicalTest(); //判断用没有员工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']); + if (!empty($where['resource_id'])) { + $model = $model->where('resource_id', $where['resource_id']); } $data = $model + ->field($field) + ->order('id','desc') + ->append([ + 'customerResources' + ]) ->with([ - 'personnel', - 'customer', + 'customerResourcesHasOne' ]) ->paginate([ 'list_rows' => $limit, 'page' => $page, ])->toArray(); + + foreach ($data['data'] as &$v) { + $age = $v['customerResourcesHasOne']['age'];//年龄 + $gender = $v['customerResourcesHasOne']['gender'] == 'female' ? 2:1 ;//性别( 1:男,2:女) + $height = $v['height'];//身高 + $weight = $v['weight'];//体重 + $v['calculateChildHealthScore'] = calculateChildHealthScore($age, $gender, $height, $weight);//综合评分 + } + return $data; }