您也可以将上线级别存储在用户表中。在注册期间,您先获取上线,然后获取上线的上线等,以便稍后在查询用户表时获取它们。
我做了 6 个级别的深度,所以还有 6 个查询,但我真的不在乎,每天注册不会发生一百万次。

这是我的流量交换中的用户表......希望它有所帮助。正如您所看到的,我还使用 upline_val 列来存储冲浪积分,以后可以通过他们的上线使用“从推荐人那里获得积分”按钮来申请这些积分。
并注册模型代码以创建成员:
$data = array(
'username' => $username,
'password' => password_hash($password, PASSWORD_DEFAULT),
'email' => $email,
'first_name' => $first_name,
'last_name' => $last_name,
'active' => $active,
'referred_by_id' => $referred_by_id,
'referral_url' => $this->session->userdata('referral_url'),
'next_subscription_update' => $now->format("Y-m-d H:i:s"),
'email_newsletter' => $newsletter,
'autoassign_pct' => Settings_model::$db_config['autoassign_value']
);
// select upline ids
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['referred_by_id']); // $data['referred_by_id'] is passed in the url e.g. http://example.com/register/1867
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl2'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl2']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl3'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl3']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl4'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl4']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl5'] = $q->row()->referred_by_id;
$this->db->select('referred_by_id')->from(DB_PREFIX .'user')->where('user_id', $data['upline_lvl5']);
$q = $this->db->get();
if ($q->num_rows() == 1) {
$data['upline_lvl6'] = $q->row()->referred_by_id;
}
}
}
}
}
// ...etc...
$this->db->insert(DB_PREFIX .'user', $data); // $data is inserted here
我想这就是我能做的。