conn = connect(); /** * 如果用户在当前站点登录,那么就会有username和password、uid的session;如果当前站点是响应其他的站点进行登录的话,那么就只会有synUid这个session。 */ if( isset($_SESSION['username']) ) { $this->uid = $_SESSION['uid']; $this->logType = 'current'; }else if( isset($_SESSION['synUid']) && $_SESSION['synUid'] > 0) { $this->uid = $_SESSION['synUid']; $this->logType = 'syn'; } } public function main() { //TODO:主函数,分别执行两个获取信息的函数 $this->getInfoFromUcenterMembers(); $this->getRestInfoFromProfileTable(); $this->getUserState(); $this->setSession(); return $this; } public function setSession() { $allInfo = $this->getInfo(); foreach ($allInfo as $key=>$value){ $_SESSION[$key] = $value; } } public function getInfo() { //TODO:将从数据库中获取的数据返回给调用者 return array( "uid" => $this->uid, "email"=> $this->email, "username" => $this->username, "realName" => $this->realName, "regDate" => $this->regDate, "qq" => $this->qq, #公司以及职能 "company" => $this->company, "position" => $this->position, "demand" => $this->demand, "mobile" => $this->mobile, "address" => $this->address, "level" => $this->level, "allowadmincp" => $this->allowadmincp, "groupid" => $this->groupid, "frActivityCode" => $this->frActivityCode, "fbiActivityCode" => $this->fbiActivityCode, "frActivityTime" => $this->frActivityTime, "fbiActivityTime" => $this->fbiActivityTime ); } public function __get($name){ // TODO: Implement __get() method. if( isset($this->$name)) { return $this->$name; }else{ return "Invalid variable name"; } } public function getInfoFromUcenterMembers() { //TODO:从pre_ucenter_members表中获取email、username、和注册时间的信息 $sql = "select username, email, regdate from pre_ucenter_members where uid=?"; //这里需要测试一下如果sql有问题会不会抛出错误 $this->stmt = $this->conn->prepare($sql); $this->judgeStmt($sql); $this->stmt->bind_param('i', $this->uid); $this->stmt->execute(); $this->stmt->store_result(); $this->stmt->bind_result($this->username, $this->email, $this->regDate); $this->stmt->fetch(); $this->freeResult(); //将注册时间转换成字符串格式 // $when = new DateTime(strval($this->regDate)); // $when->setTimezone(new DateTimeZone('Asia/Shanghai')); // $this->regDate = $when->format('Y/m/d'); $this->regDate = date('Y-m-d', $this->regDate); } /** * 从pre_common_member_profile表中获取realname、qq、mobile、company、finereportActivityCode和finebiActivityCode、以及职位、对fineReport产品的需求的信息 */ public function getRestInfoFromProfileTable() { $sql = "select realname, qq, company, address, mobile, finereport_code, finebi_code, `position`, field4, finereport_activation_time, finebi_activation_time from pre_common_member_profile where uid=?"; $this->stmt = $this->conn->prepare($sql); $this->judgeStmt($sql); $this->stmt->bind_param('i', $this->uid); $this->stmt->execute(); $this->stmt->store_result(); $this->stmt->bind_result($this->realName, $this->qq, $this->company, $this->address, $this->mobile, $this->frActivityCode, $this->fbiActivityCode, $this->position, $this->demand, $this->frActivityTime, $this->fbiActivityTime); $this->stmt->fetch(); $this->freeResult(); //将数据库中保存的unicode编码转换成中文 if( strpos($this->company, '[') !== false ) { $this->company = unicodeToChinese($this->company); } if( strpos($this->realName, '[') !== false ) { $this->realName = unicodeToChinese($this->realName); } //将数据库中保存的unicode编码转换成中文 if( strpos($this->demand, '[') !== false ) { $this->demand = unicodeToChinese($this->demand); } } /** * 获取数据库中的公司、职位以及对fineReport产品的需求的信息 */ public function getCompany() { //TODO:获取pre_common_member_profile表中的company字段数据 $sql = "select company, `position`, field4, realName from pre_common_member_profile where uid=?"; //这里需要测试一下如果sql有问题会不会抛出错误 $this->stmt = $this->conn->prepare($sql); $this->judgeStmt($sql); $this->stmt->bind_param('i', $this->uid); $this->stmt->execute(); $this->stmt->store_result(); $this->stmt->bind_result($this->company, $this->position, $this->demand, $this->realName); $this->stmt->fetch(); $this->freeResult(); //将数据库中保存的unicode编码转换成中文 if( strpos($this->company, '[') !== false ) { $this->company = unicodeToChinese($this->company); } if( strpos($this->realName, '[') !== false ) { $this->realName = unicodeToChinese($this->realName); } //将数据库中保存的unicode编码转换成中文 if( strpos($this->demand, '[') !== false ) { $this->demand = unicodeToChinese($this->demand); } } public function checkProduceActivationCode() { //TODO:获取pre_common_member_profile表中的finereport_code, finebi_code字段数据 $sql = "select finereport_code, finebi_code from pre_common_member_profile where uid=?"; //这里需要测试一下如果sql有问题会不会抛出错误 $this->stmt = $this->conn->prepare($sql); $this->judgeStmt($sql); $this->stmt->bind_param('i', $this->uid); $this->stmt->execute(); $this->stmt->store_result(); $this->stmt->bind_result($this->frActivityCode, $this->fbiActivityCode); $this->stmt->fetch(); $this->freeResult(); } public function getUserState() { //TODO:获取pre_common_member表中的用户组、权限信息 $sql = "select pcm.groupid,allowadmincp,grouptitle from pre_common_member as pcm join pre_common_usergroup as pcu on pcm.groupid = pcu.groupid where uid=?"; //这里需要测试一下如果sql有问题会不会抛出错误 $this->stmt = $this->conn->prepare($sql); $this->judgeStmt($sql); $this->stmt->bind_param('i', $this->uid); $this->stmt->execute(); $this->stmt->store_result(); $this->stmt->bind_result($this->groupid, $this->allowadmincp, $this->level); $this->stmt->fetch(); $this->freeResult(); } protected function judgeStmt($sql) { /* * 判断当前的预处理语句执行之后是否正确 */ if( !$this->stmt ) { throw new Exception('预处理语句有错,请检查——'.$sql); }else{ return true; } } protected function freeResult() { $this->stmt->free_result(); } public function __destruct(){ // TODO: Implement __destruct() method. $this->freeResult(); $this->conn->close(); } } //计算两个日期之差,服务器的PHP不支持这个 function diffTime1($timeStempOne, $timeStempTwo) { // $first = new DateTime('@'.strval($timeStempOne), new DateTimeZone('Asia/Shanghai')); // $second = new DateTime('@'.strval($timeStempTwo), new DateTimeZone('Asia/Shanghai')); // // $diff = $second->diff($first); // // $str = "还有{$diff->format('%a')}天过期"; // return $str; } function diffTime($timeOne, $timeTwo) { //需要$timeOne 大于$timeTwo if( $timeOne < $timeTwo ) { list( $timeOne, $timeTwo ) = array($timeTwo, $timeOne); } $day = intval(($timeOne-$timeTwo) / (3600 * 24)); $str = "还有{$day}天过期"; return $str; }