繁体   English   中英

Codeigniter识别每第三个用户注册推荐人

[英]Codeigniter Identify Every 3rd user Registration referral

我目前正在使用Codeigniter Framework开发一个MLM网站。

我现在正在注册。 我可以向推荐用户注册成功

问题是每3个使用我的推荐用户名/ ID进行注册,我都需要运行另一个查询,因为在第一和第二推荐中我赚了200。在第三用户中,我只能赚100。

如何在Codeigniter中做到这一点? 有人这样做吗? 请帮忙

让我对此进行一些说明。因此,可以说您为每个注册创建了一个帖子,该帖子转到了一个类名注册和一个register方法,并且引用id作为会话(refID)运行。 另外,您有一个注册模型,这可能是您应该做的:

class registration extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->model('registration_model');
    }

    //ensue to check for the existence of the refID session before processing
    function register(){

        if($_POST){
            //first run form validation
            //you should have auto loaded the form_validation library
            //and created a rules function that carries the form rules
            $rules = $this->rules();
            $this->form_validation->set_rules($rules);

            if($this->form_validation->run() == FALSE){
                //load view here
            }else{
                //first, get post data
                //then get the number of registration done by user using the refID
                //if registration is greater than 2, set earnings to 100
                //set earnings to 200
                //then proceed to insert registration and do something else



                //get post data, assumed post data
                $name = $this->input->post('name');
                $email = $this->input->post('email');

                //get number of registrations
                $numOfRegs = $this->registration_model->getRegByRefID();

                //set the earnings from the number of registrations
                $earning = $numOfRegs < 3 ? 200 : 100;
                //please note that the for $numOfRegs = 4, $earnings will be 100, as this was not specified in the question

                //at this point, you have set the earnings, you can proceed to do whatever you wish to do, perhaps insert the records

                //please note that this code block just explains what you can likely do after setting the earnings
                $insert = array(
                    "name" => $name,
                    "email" => $email,
                    "earning" => $earning
                );
                $this->registration_model->insert($array);
                // then do anything else
            }
        }else{
            //load view here
        }
    }
}

现在这就是您的注册模型的样子

class Registration_model extends CI_Model{

    function __construct(){
        parent::__construct();
    }

    function getRegByRefID(){
        $refID = $this->session->refID;
        return $this->db->get_where('mydb', array("refID" => $refID))->num_rows();
    }


}

我希望这可以解释您的真正需求并为您提供帮助。 如果发现任何困难,请发表评论并进行整理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM