我想做一个分表的操作,循环表名,去获取资源,具体如下,但是没有成功,求大佬们指点下

未解决 2 1008
jiaohu
jiaohu   会员 发布于:13个月前
悬赏:60飞吻
public function findAllByAccountId($accountId)
{
$data = [];
$allTableNames = ['spend', 'spend_1', 'spend_2', 'spend_3', 'spend_4', 'spend_5', 'spend_6', 'spend_7', 'spend_8', 'spend_9'];
foreach ($allTableNames as $allTableName) {
$spend = new Spend();
$spend->getModelsManager()->setModelSource($spend, $allTableName);

$tempArr = $spend::find([
'isDeleted = ?0 AND accountId = ?1',
'bind' => [Models::NOT_DELETED, $accountId],
])->toArray();
if (!$tempArr) {
throw new ApiException(ErrorCode::DATA_NOT_FOUND, "此公众号暂无消费记录");
}

$data = array_merge($data, empty($tempArr) ? [] : $tempArr);
var_dump(count($data));
var_dump($allTableName);
}

return $data;
}
回帖

jiaohu 会员

2018-04-18 加入 来自中国

(这个人懒得留下签名)

活跃榜
大家好像都不是很活跃
本周热门
本周暂无热帖