我来这里是为了得到你的帮助。
我正在使用Codeigniter制作Unilevel MLM 现在我可以成功添加新成员
但问题是我需要将收益分配到其他级别 成功添加新成员后
见下图:
我需要像上面的图像一样分发。
我希望你能帮助我这些家伙。
答案 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个数据库表,我假设您已经创建了这些表,只需使用逻辑来更新代码。如果您发现任何困难,请发表评论以便将其排除