shopro商城,User数据表关联Agent数据表查询
最终的效果是:在User数据表筛选出会员id=20的所有下级,并且在Agent数据表有记录的下级,直接上代码$all_child1_ids=[];//当前用户的所有下级id集合$a1=Db::query("selectidfromfa_userwherestatus='normal'andparen
最终的效果是:在User数据表筛选出会员id=20的所有下级,并且在Agent数据表有记录的下级,直接上代码
$all_child1_ids = []; //当前用户的所有下级id集合 $a1 = Db::query("select id from fa_user where status='normal' and parent_user_id=".$agentId); foreach ($a1 as $k1 => $v1){ array_push($all_child1_ids,$v1['id']); } $data4 = UserModel::hasWhere('agent',function($query) use ($all_child1_ids) { return $query->where('user_id','in',$all_child1_ids); }) ->with(['agent' => function ($query) { return $query->with('level_info'); }]) ->paginate($this->request->param('list_rows', 8));