From c2306073a007f96577bde8fc2482446230fd6ac4 Mon Sep 17 00:00:00 2001 From: weiz Date: Wed, 25 Oct 2023 17:45:41 +0800 Subject: [PATCH] fixed --- app/api/controller/UserController.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/api/controller/UserController.php b/app/api/controller/UserController.php index dbd1dda9..05e174ce 100644 --- a/app/api/controller/UserController.php +++ b/app/api/controller/UserController.php @@ -119,13 +119,29 @@ class UserController extends BaseApiController if($params['type'] == 3){ foreach($arr1 as $k=>$v) { $actionIds = array_column($v['actions'],'id'); - $arr1[$k]['action_record'] = Db::name('farmer_animal_record')->where('action_id','in',$actionIds)->order('id desc')->limit(5)->select(); + $actionsInfo = $v['actions']; + $arr1[$k]['action_record'] = Db::name('farmer_animal_record')->where('action_id','in',$actionIds)->order('id desc')->limit(5)->select()->each(function($item)use($actionsInfo){ + foreach ($actionsInfo as $val){ + if($item['action_id'] == $val['id']){ + $item['action_name'] = $val['name']; + } + } + return $item; + }); } } if($params['type'] == 2) { foreach($arr1 as $k=>$v) { $actionIds = array_column($v['actions'],'id'); - $arr1[$k]['action_record'] = Db::name('farmer_poultry_record')->where('action_id','in',$actionIds)->order('id desc')->limit(5)->select(); + $actionsInfo = $v['actions']; + $arr1[$k]['action_record'] = Db::name('farmer_poultry_record')->where('action_id','in',$actionIds)->order('id desc')->limit(5)->select()->each(function($item)use($actionsInfo){ + foreach ($actionsInfo as $val){ + if($item['action_id'] == $val['id']){ + $item['action_name'] = $val['name']; + } + } + return $item; + }); } } return $this->success('请求成功',$arr1);