假设需要在A对象信息里绑定B、C、D的信息
//A类 class A { /** * @param $aIds * @param $params * with_b_info 获取b信息 * with_c_info 获取c信息 * with_d_info 获取d信息 * @return array */ public function getMulliAInfo($aIds, $params = []) { //获取A的数据(mc包一层) $list = $mc->getMulti($aIds); //从mc取数据 if ($list === false) { $list = $db->select(['id' => $aIds]); //从db取数据 $mc->setMulti($aIds, $list); //写入mc } //补充其他数据 if (!empty($params['with_b_info'])) { $list = $this->_mergeBInfo($list); } if (!empty($params['with_c_info'])) { $list = $this->_mergeCInfo($list); } if (!empty($params['with_d_info'])) { $list = $this->_mergeDInfo($list); } return $list; } //绑定B信息 private function _mergeBInfo($list) { $bIds = array_column($list, 'b_id'); $bList = B模块->getMultiBInfo($bIds); foreach ($list as $_k => $_item) { $list[$_k]['b_info'] = $bList[$_item['b_id']] ?? []; } return $list; } //绑定C信息 private function _mergeCInfo($list) { //类似_mergeBInfo return $list; } //绑定D信息 private function _mergeDInfo($list) { //类似_mergeBInfo return $list; } }