我目前正在使用Codeigniter Framework开发MLM网站。
我现在正在注册。我可以使用推荐用户注册成功
问题是每3次注册使用我的推荐用户名/身份证我需要运行另一个查询,因为在第1和第2次推荐中我获得了200.而在第3位用户将推荐我将只获得100。
我如何在Codeigniter中做到这一点?有人这样做过吗?请帮忙
答案 0 :(得分:1)
让我对此有所了解 因此,假设您为每次注册发布帖子,帖子转到类名注册和注册方法,引用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();
}
}
我希望这可以解释你真正想要的东西,并帮助你。如果您发现任何困难,请发表评论并进行整理。