public function index()
 {
     $ticket = M('ticket')->where(['type' => 'js_ticket'])->find();
     $expire = time() - $ticket['time'];
     $url = __SELF__;
     if ($expire >= 7200) {
         $tool = new ToolController();
         $tool->GetAccessToken();
         $ticket = M('ticket')->where(['type' => 'js_ticket'])->find();
     }
     $this->assign('ticket', $ticket['token']);
     $data = M('school')->where(['status' => 1])->field('id as school_id, school_name, praise')->select();
     $this->assign('data', $data);
     $this->assign('url', $url);
     $this->display();
 }
 public function _initialize()
 {
     $session_uid = session('uid');
     if ($session_uid == null || $session_uid == '') {
         $tools = new ToolController();
         $userInfo = $tools->GetOpenid();
         if ($userInfo['openid'] == null || $userInfo['openid'] == '') {
             $this->redirect('Index/index');
         }
         $users = M('users');
         if ($users->where(['openid' => $userInfo['openid']])->count()) {
             $uid = $users->where(['openid' => $userInfo['openid']])->getField('id');
             session('uid', $uid);
         } else {
             $data = ['openid' => $userInfo['openid'], 'nickname' => $userInfo['nickname'], 'avatar' => $userInfo['headimgurl'], 'role_id' => 1, 'password' => ''];
             $users->add($data);
             $uid = $users->where(['openid' => $userInfo['openid']])->getField('id');
             session('uid', $uid);
         }
     }
 }