function addSubagent() { $post = $this->req->post; if (count($post)) { $name = $post['name']; $phone = $post['phone']; $pass = $post['pass']; $agent_id = (int) $post['agent_id']; $tag = $post['tag']; $arr = array('name' => $name, 'phone' => $phone, 'can_cashout' => 1, 'subagent_id' => 0, 'date' => timenow(), 'pass' => md5($pass)); if (empty($agent_id)) { setHint('代理ID必须是数字'); $this->res->red('user/addSubagent'); } if (strlen($name) < 1) { setHint('名称太短'); $this->res->red('user/addSubagent'); } if (!validate('phone', $phone)) { setHint('电话不符合要求'); $this->res->red('user/addSubagent'); } if (!validate('pass', $pass)) { setHint('密码不符合要求'); $this->res->red('user/addSubagent'); } $hasUser = $this->load->model('user')->findByPhone($phone); if ($hasUser) { setHint('电话已经存在,请重新输入', 'bad'); $this->res->red('user/addSubagent'); } $role = $this->load->model('role')->findByTag($tag); $agent = $this->load->model('user')->findByRole($agent_id, 'agent'); if (!$role) { setHint('tag不存在,不能添加', 'bad'); $this->res->red('user/addSubagent'); } if (!$agent) { setHint('代理不存在,不能添加', 'bad'); $this->res->red('user/addSubagent'); } $arr['role_id'] = (int) $role['role_id']; $arr['branch_id'] = (int) $agent['branch_id']; $arr['sale_id'] = (int) $agent['sale_id']; $arr['p_id'] = (int) $agent['p_id']; $arr['agent_id'] = (int) $agent['user_id']; $result = $this->load->model('user')->add($arr); if ($result) { setHint('添加成功'); $lastId = $this->db->lastId(); //初始化用户积分账户 $this->load->model('amount')->add(array('user_id' => $lastId, 'money' => 0, 'score' => 0)); $randcode = randImgName(25); $link = $randcode . 'u' . $lastId; $imgarr = array('user_id' => $lastId, 'link' => $link, 'linkimg' => $link . '.png', 'logoimg' => $link . "logo.png"); $update = $this->load->model("user")->updateQcode($imgarr); if ($update) { createQcode(HOSTNAME . 'home/register/' . $link, $link, 'logo.png', QCODE, 7); } } else { setHint('添加失败', 'bad'); } $this->res->red('user/addSubagent'); } else { return $this->load->view('user_add_subagent'); } }
function register($args) { $post = $this->req->post; if (count($post)) { $phone = $post['phone']; $pass = $post['pass']; $code = $post['code']; $sms = $post['sms']; $name = $post['name']; // return var_dump($post); if (empty($this->session->data['invitationcode'])) { setHint('对不起,不通过邀请链接不能注册'); $this->res->redirect('home/register'); } if (!validate('pass', $pass)) { setHint('密码不符合要求'); $this->res->redirect('home/register'); } if (!validate('code', $code)) { setHint('验证码格式不正确'); $this->res->redirect('home/register'); } if ($this->session->data['validatecode'] != $code) { setHint('验证码不正确'); $this->res->redirect('home/register'); } if (!validate('sms', $sms)) { setHint('短信验证码格式不正确'); $this->res->redirect('home/register'); } if (!validate('name', $name)) { setHint('姓名必须为2~4个中文字符'); $this->res->redirect('home/register'); } if (empty($this->session->data['smscode'])) { setHint('您没有获取短信验证码'); $this->res->redirect('home/register'); } if ($this->session->data['smscode'] != $sms) { setHint('短信验证码不正确'); $this->res->redirect('home/register'); } $user = $this->load->model('user'); $link = $user->findByLink($this->session->data['invitationcode']); if (!$link) { setHint('对不起,邀请链接不合法', 'bad'); $this->res->redirect('home/register'); } $euser = $user->findByPhone($phone); if ($euser) { setHint('对不起,手机号已经被注册', 'bad'); $this->res->redirect('home/register'); } $arr = array("phone" => $phone, "pass" => md5($pass), 'name' => $name, 'can_cashout' => 1, 'date' => timenow()); $tag = $link['tag']; if ($tag == 'sale') { //添加代理 $role_id = (int) $this->load->model('role')->findByTag('agent')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['user_id']; $arr['agent_id'] = 0; $arr['subagent_id'] = 0; $arr['p_id'] = 0; } else { if ($tag == 'agent') { //添加分代理 $role_id = (int) $this->load->model('role')->findByTag('subagent')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['sale_id']; $arr['agent_id'] = (int) $link['user_id']; $arr['subagent_id'] = 0; $arr['p_id'] = 0; } else { if ($tag == 'subagent') { //添加会员 $role_id = (int) $this->load->model('role')->findByTag('member')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['sale_id']; $arr['agent_id'] = (int) $link['agent_id']; $arr['subagent_id'] = (int) $link['user_id']; $arr['p_id'] = 0; } else { if ($tag == 'member') { //添加介绍会员 $role_id = (int) $this->load->model('role')->findByTag('member')["role_id"]; $arr['role_id'] = $role_id; $arr['branch_id'] = (int) $link['branch_id']; $arr['sale_id'] = (int) $link['sale_id']; $arr['agent_id'] = (int) $link['agent_id']; $arr['subagent_id'] = (int) $link['subagent_id']; $arr['p_id'] = (int) $link['user_id']; } else { setHint('您的链接不合法', 'bad'); $this->res->redirect('home/register'); } } } } $result = $user->add($arr); if ($result) { $lastId = (int) $this->db->lastId(); $randcode = randImgName(25); $link = $randcode . 'u' . $lastId; $update = $user->updateLink(array('user_id' => $lastId, 'link' => $link, 'linkimg' => $link . '.png', 'logoimg' => $link . "logo.png")); if ($update) { createQcode(HOSTNAME . 'home/register/' . $link, $link, 'logo.png', QCODE, 7); } setHint('注册成功'); //为用户生成积分账号 $this->load->model('amount')->add(array('user_id' => $lastId, 'money' => 0, 'score' => 0)); $newuser = $user->findById($lastId); if (!empty($newuser['permission'])) { $newuser['permission'] = unserialize($newuser['permission']); } else { $newuser['permission'] = array(); } $this->session->data['user'] = $newuser; $this->session->data['validatecode'] = null; $this->session->data['smscode'] = null; $this->res->redirect('user/dashboard'); } else { setHint('注册失败', "bad"); } //无论注册成功失败,都重置关于验证码的session $this->session->data['validatecode'] = null; $this->session->data['smscode'] = null; $this->res->redirect('home/register'); } else { if (!empty($args[0])) { $this->session->data['invitationcode'] = $args[0]; } $catalogs = $this->load->model('catalog')->findFirst(); return $this->load->view('register', array('invitationcode' => $this->session->data['invitationcode'], 'catalogs' => $catalogs)); } }