$builder = new QueryBuilder(User::class);
$builder->joinTo(UserSource::class);
$builder->joinFrom(UserTanPoint::class);
$builder->setCondition([
'id', 'cellphone', 'status', 'user_source_id', 'user_source.title' => 'fuzzy',
'province_name', 'city_name', 'area_name', 'created_at' => 'range'
]);
if (!empty($params['tag_id'])) {
$builder->exposeBuilder()
->whereIn('user.id', function ($q) use ($params) {
$q->select('user_id')
->from(with(new UserTag)->getTable())
->where('tag_id', $params['tag_id'])
->distinct();
});
}
// $builder->select('user.*');
$builder->addSelect('user_source.name AS user_source_name');
$builder->addSelect('user_tan_point.point');
return $builder->query($params);
各位看官就看代码猜功能吧🙃,还有一些特殊的用法和额外参数这个例子没展示出来