$cardNoBegin = 1;
$cardNoEnd = 10000;
$where['number'] = array('between' , [$cardNoBegin , $cardNoEnd]);
$list = VipCardModel::where($where)->field('id,number,issue_uid,rank')->select();foreach($list as &$value){ // 只想到foreach来处理,但是这样很奇怪,觉得这样处理不对。
$value['name'] = UserModel::where(array('id' => $value['issue_uid']))->value('name');
}
1 回答
holdtom
TA贡献1805条经验 获得超10个赞
shmiyle同学已经正确的回答了这个问题,我在他的基础上优化一下,提升一点效率
$where['number'] = array('between' , [$cardNoBegin , $cardNoEnd]); $list = VipCardModel::where($where)->field('id,number,issue_uid,rank')->select(); $issueUidList = array_unique((array_column($list, 'issue_uid')));unset($list);//查询用户信息$userList = UserModel::where(array('id' => array('in', $issueUidList)))->value('name'); $userInfoList=array_column($userList,'name','id');foreach($list as $key => $value){ $list[$key]['name'] = $userInfoList[$value['issue_uid']] ?? ''; }
添加回答
举报
0/150
提交
取消