2017-08-16 16 views
1

我在這裏有一些幫助。Codeigniter Unilevel傳銷收入分配

我使用笨 作出利華傳銷,現在我可以成功地添加新的成員

但問題是,我需要一個新成員被成功添加

後的收益與其他級別 分發請參見下面的PIC:

Distribution of earnings

我需要上述分發像圖片。

我希望你能幫助我這個傢伙。

+0

你能否進一步解釋,所以我可以幫忙。你想通過分配收入後增加一個新成員後實現分配 –

+0

例如,我將分發 –

+0

請詳細說明一下,所以我可以理解和幫助你 –

回答

0

好的,我有一個解決方案給你。我使用的過程是基於我對這個問題的理解。

所以這是它,首先我檢查了一個註冊帖子,如果發佈了一個帖子請求,我使用該帖子中的推薦ID來獲取與該推薦ID綁定的註冊數量, 100賺錢。如果這個查詢結果的計數等於4,我循環所有這些,並給他們100的收入和更新他們的付費狀態,以反映他們已經支付,然後我插入記錄,否則我只是插入記錄。

所以太多的文字,讓我們看看代碼

//this is the controller code 
//first check for post of registration 
    if($_POST){ 

     //kindly do your form validation here 

     $register = array(
      "name" => $this->input->post('name'), 
      "refid" => $this->input->post('refID') 
     ); 

     //during post, get the referral id from the post 
     $refID = $this->input->post('refID'); 

     //before registering, use referral id to get the referred that have not been given earnings yet 
     $thereffered = $this->referral_m->getReferred($refID); 

     //check for the number of registration 
     if(count($thereffered) == 4){ 

      //then get their ids and give them their earnings and update them to paid 
      foreach($thereffered as $referred){ 

       $earnings = array(
        "userID" => $referred->id, 
        "amount" => 100 
       ); 

       $paid = array(
        "paid" => 1 
       ); 

       //give earning 
       $this->referral_m->giveEarning($earnings); //this adds the user id to earning table and give it an amount of 100 
       $this->referral_m->updateUser($paid, $referred->id); //this updates the user with the paid status 

      } 

      //then proceed to register the new record 
      $this->referral_m->register($register); 

     }else{ 

      //register the new record 
      $this->referral_m->register($register); 

     } 
     //redirect after registration 
     redirect(); 

    }else{ 
     //load view here 
    } 

這是模型的樣子

function getReferred($refID){ 
    return $this->db->get_where('referral', array("refid" => $refID, "paid" => '0'))->result(); 
} 

function giveEarning($record){ 
    $this->db->insert('earnings', $record); 
} 

function register($array){ 
    $this->db->insert('referral', $array); 
} 

function updateUser($array, $id){ 
    $this->db->where('id', $id); 
    $this->db->update('referral', $array); 
} 

從模型中,你會發現,我創建2個數據庫表,我承擔你已經創建了這些表,只需使用邏輯來更新你的代碼即可。如果您發現任何困難,請親切評論讓我們解決它