Codeigniter获取推荐用户并给予奖励奖励

时间:2017-08-29 13:28:33

标签: php codeigniter mlm

我正致力于我的多层次营销。

现在我可以成功推荐用户并将其显示如下:

我的级别

  

等级1 =由我推荐的成员   等级2 =我的1级用户引用的成员   3级=由我的2级用户引用的成员   级别4 =我的3级用户引用的成员

我的问题是如果任何用户在"等级4"推荐新会员

看起来像这样。

::Level 1::  ::Level 2::    ::Level 3::  ::Level 4::  
 - user_1        - user_2    - user_3     - user_4

如果" user_4"在第4级下提到了新成员..

我需要给予user_3,user_2和user_1 100个奖励奖励。

  

注意:唯一将获得奖励奖励的用户是用户   谁将用户从第4级引用到第2级。

     

user_1引用user_2,user_2引用user_3和user_3引用   user_4

     

所以user_3到user_1将收到奖励奖励......

1 个答案:

答案 0 :(得分:0)

您也可以在用户表中存储上线级别。在注册过程中,您可以获取上线,然后上线等,以便稍后在查询用户表时可以获取它们。

我这样做了6个级别,所以它还有6个查询,但我并不在乎,注册不会每天发生一百万次。

enter image description here

这是我的流量交换中的用户表...希望它有所帮助。正如您所看到的,我还使用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

这就是我能做的所有事情。

相关问题