1

我来这里是为了得到你的帮助。

我正在使用 Codeigniter 制作 Unilevel MLM,现在我可以成功添加新成员

但问题是我需要在成功添加新成员后将收益分配到其他级别

见下图:

收益分配

我需要像上图一样分发。

我希望你能帮助我解决这些问题。

4

1 回答 1

0

好的,我有一个解决方案给你。我使用的过程是基于我对问题的理解。

就是这样,首先我检查了一个注册帖子,如果发出一个帖子请求,我使用帖子中的推荐 ID 来获取与该推荐 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 个数据库表,我假设您已经创建了这些表,只需使用逻辑来更新您的代码。如果您发现任何困难,请评论让我们解决

于 2017-08-19T21:59:29.880 回答