我正在使用 PHP Codeigniter 。对于我希望允许转销商为其自己的用户添加余额的系统。条件是他只能为他的每个用户分配 5 EUROS ,而不是更少且不超过5.假设经销商当前余额是20欧元那么他应该能够只分配5欧元,所以4个用户每个将获得5欧元,最重要的是我想在每个 30天之后将用户余额重置为零,我的意思是在一个月结束时。经销商余额应根据用户之间的划分扣除,而用户余额将每30天设置为零。我真的很困惑,从哪里开始以及如何!
控制器代码:
public function edit ($id = NULL)
{
$usertype=$this->session->userdata('usertype');
if($usertype ==="admin")
{
// Fetch a user or set a new one
if ($id) {
$this->data['user'] = $this->reseller_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
}
else
{
$this->data['user'] = $this->reseller_m->get_new();
}
// Set up the form
$rules = $this->reseller_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->reseller_m->array_from_post(array('sip_username','sip_password','key','allocation_block','name','email','password','phone','balance','user_num','address','country','country_code','created','modified','status'));
$data['password'] = $this->reseller_m->hash($data['password']);
$key=$this->reseller_m->save($data, $id);
//here we get the last inserted record id in $last_id//
$last_id = $this->db->insert_id();
//The logic to create key to uniquely identify a reseller.
$values=array($this->input->post('name'),$this->input->post('country_code'),$this->input->post('allocation_block'),$this->input->post('user_num'));
$key=implode('-',$values);
$this->db->where('id',$last_id);
$this->db->update('reseller',array('key'=>$key));
//Loop To Creates Users Dynamically as user_num value.
$this->reseller_m->get($id);
if($id === NULl)
{
for($i=1; $i<=$data['user_num'];$i++)
{
$userdata=array('key'=>$key);
$this->db->insert('users',$userdata);
}
}
redirect('admin/reseller');
}
// Load the view
$this->data['subview'] = 'admin/reseller/edit';
$this->load->view('admin/_layout_main', $this->data);
}
else
{
$this->load->view('permission');
}
}
答案 0 :(得分:1)
请使用Mysql Event Scheduler。
有关更多详情,请点击链接 - https://dev.mysql.com/doc/refman/5.1/en/events.html