public function activate()
 {
     $condition = array();
     if (IS_POST && isset($_POST['activateSubmit'])) {
         $code = $_POST['invitecode'];
         $user_id = $_POST['userid'];
         $websiteUserFuncManager = new WebsiteUserFuncManager($user_id);
         $res = $websiteUserFuncManager->activate($code, current(M('user')->field('username')->find(session(C('USER_AUTH_KEY')))));
         if ($res['success'] == 1) {
             $this->success("充值成功!");
         } else {
             $this->error($res['error']);
         }
     } else {
         $id = $this->_get('id', 'intval', -1);
         if (!$id) {
             $this->error('参数错误!');
         }
         $Model = new Model();
         // 实例化一个model对象 没有对应任何数据表
         $fgroups = $Model->query("SELECT  tp_function_group.`name` ,tp_function_group.visible visible,tp_function_group.id id, tp_user_func_group.id relationid, tp_user_func_group.status status, tp_user_func_group.start_time, tp_user_func_group.expire_time from tp_function_group LEFT OUTER JOIN tp_user_func_group  on tp_function_group.id = tp_user_func_group.group_id and tp_function_group.status =1 and tp_user_func_group.user_id=" . $id . " order by tp_function_group.sort asc, tp_function_group.id asc");
         $this->assign('func_groups', $fgroups);
         $this->assign('userid', $id);
         $this->assign('tpltitle', '授权');
         $smsAccount = M('smsaccount')->where(array('user_id' => $id))->find();
         if (!empty($smsAccount)) {
             $smsAccount['balance'] = $smsAccount['total'] - $smsAccount['used'];
             $this->assign('smsaccount', $smsAccount);
         }
         $this->display();
     }
 }
 public function activate()
 {
     if (IS_POST) {
         $code = trim($_POST['invitecode']);
         $user_id = $_SESSION['uid'];
         $websiteUserFuncManager = new WebsiteUserFuncManager($user_id);
         $res = $websiteUserFuncManager->activate($code, session('uname'));
         if ($res['success'] == 1) {
             $this->success("充值成功!", U('Index/index'));
         } else {
             $this->error($res['error']);
         }
     } else {
         $this->display();
     }
 }