first commit
This commit is contained in:
114
ZeedFramework/library/Com/Model/Mapping/Email2userid.php
Normal file
114
ZeedFramework/library/Com/Model/Mapping/Email2userid.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2010-7-6
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Com_Model_Mapping_Email2userid extends Zeed_Db_Model_Detach {
|
||||
/*
|
||||
* @var string The table name.
|
||||
*/
|
||||
protected $_name = 'mapping_email2userid';
|
||||
|
||||
/**
|
||||
* @var integer Primary key.
|
||||
*/
|
||||
protected $_primary = 'email';
|
||||
|
||||
/**
|
||||
* @var string Table prefix.
|
||||
*/
|
||||
protected $_prefix = 'os_';
|
||||
|
||||
/**
|
||||
* 定义分表依据字段
|
||||
*
|
||||
* @var $_detachField string
|
||||
*/
|
||||
protected $_detachField = 'email';
|
||||
|
||||
/**
|
||||
* 添加 Mapping 表信息
|
||||
*
|
||||
* @param array|Com_Entity_Mapping_Email2userid $set
|
||||
* @return integer|false 添加成功返回 userid 值,失败返回 false
|
||||
* @see Com_Model_User::add()
|
||||
*/
|
||||
public function add($set)
|
||||
{
|
||||
$mappingEmail2userid = new Com_Entity_Mapping_Email2userid();
|
||||
$mappingEmail2userid->fromObject($set);
|
||||
|
||||
if ($mappingEmail2userid->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! is_numeric($mappingEmail2userid->userid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $mappingEmail2userid->toArray();
|
||||
|
||||
$this->detachToken($data);
|
||||
$name = $this->_name;
|
||||
$this->_name = $this->getTable();
|
||||
|
||||
try {
|
||||
$email = $this->insert($data);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$email = false;
|
||||
}
|
||||
|
||||
$this->_name = $name;
|
||||
return $email;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $username
|
||||
* @return BigInteger|null 如果失败返回 null
|
||||
*/
|
||||
public function getUseridByEmail($email)
|
||||
{
|
||||
$email = (string) $email;
|
||||
|
||||
$this->detachToken($email);
|
||||
|
||||
$userid = null;
|
||||
|
||||
$where = $this->getAdapter()->quoteInto($this->getAdapter()->quoteIdentifier('email') . " = ?", $email);
|
||||
$sql = 'SELECT userid FROM ' . $this->getTable() . ' WHERE ' . $where;
|
||||
$row = $this->getAdapter()->query($sql)->fetchColumn(0);
|
||||
if ($row && is_numeric($row)) {
|
||||
$userid = $row;
|
||||
}
|
||||
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Com_Model_Mapping_Email2userid
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
return parent::_instance(__CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// End ^ Native EOL ^ encoding
|
||||
150
ZeedFramework/library/Com/Model/Mapping/Idcard2userid.php
Normal file
150
ZeedFramework/library/Com/Model/Mapping/Idcard2userid.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since Mar 2, 2011
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Com_Model_Mapping_Idcard2userid extends Zeed_Db_Model_Detach
|
||||
{
|
||||
/*
|
||||
* @var string The table name.
|
||||
*/
|
||||
protected $_name = 'mapping_idcard2userid';
|
||||
|
||||
/**
|
||||
* @var integer Primary key.
|
||||
*/
|
||||
protected $_primary = 'userid';
|
||||
|
||||
/**
|
||||
* @var string Table prefix.
|
||||
*/
|
||||
protected $_prefix = 'os_';
|
||||
|
||||
/**
|
||||
* 定义分表依据字段
|
||||
*
|
||||
* @var $_detachField string
|
||||
*/
|
||||
protected $_detachField = 'idcard';
|
||||
|
||||
/**
|
||||
* 强制跳过 crc32 加密
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_skipCrc32 = true;
|
||||
|
||||
/**
|
||||
* 获取使用指定身份证的用户ID
|
||||
*
|
||||
* @param string $idcard
|
||||
* @return array
|
||||
*/
|
||||
public function getUseridsByIdcard($idcard, $count = 10000, $offset = 0)
|
||||
{
|
||||
$this->detachToken($idcard);
|
||||
$select = $this->getAdapter()->select()->from($this->getTable())->limit($count, $offset);
|
||||
$where = $this->getAdapter()->quoteInto($this->getAdapter()->quoteIdentifier('idcard') . ' = ?', $idcard);
|
||||
$select->where($where);
|
||||
|
||||
$rows = $select->query()->fetchAll();
|
||||
$ids = array();
|
||||
if (is_array($rows) && count($rows) > 0) {
|
||||
foreach ($rows as $row) {
|
||||
$ids[] = $row['userid'];
|
||||
}
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加身份证与用户ID映射记录
|
||||
*
|
||||
* @param string $idcard
|
||||
* @param integer $userid
|
||||
* @return boolean
|
||||
*/
|
||||
public function add($idcard, $userid)
|
||||
{
|
||||
$this->detachToken($idcard);
|
||||
$this->insert(array('idcard' => $idcard, 'userid' => $userid));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置身份证
|
||||
*
|
||||
* @param string $idcard
|
||||
* @param integer $userid
|
||||
*/
|
||||
public function resetIdcard($idcard, $userid)
|
||||
{
|
||||
$this->detachToken($idcard);
|
||||
$name = $this->_name;
|
||||
$this->_name = $this->getTable();
|
||||
|
||||
$this->delete(array('userid = ?' => $userid));
|
||||
|
||||
$this->_name = $name;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新身份证
|
||||
*
|
||||
* @param string $idcard
|
||||
* @param integer $userid
|
||||
* @param string $oldidcard
|
||||
* @return boolean
|
||||
*/
|
||||
public function updateIdcard($idcard, $userid, $oldidcard)
|
||||
{
|
||||
$this->detachToken($oldidcard);
|
||||
$name = $this->_name;
|
||||
$this->_name = $this->getTable();
|
||||
|
||||
$this->delete(array('userid = ?' => $userid));
|
||||
$this->_name = $name;
|
||||
$this->detachToken($idcard);
|
||||
$this->insert(array('idcard' => $idcard, 'userid' => $userid));
|
||||
|
||||
$this->_name = $name;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分表
|
||||
* 将分表条件转成字符串型
|
||||
* @see Zeed_Db_Model_Detach::detachToken()
|
||||
*/
|
||||
public function detachToken($idcard)
|
||||
{
|
||||
parent::detachToken(intval(substr(crc32($idcard), -4)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Com_Model_Mapping_Idcard2userid
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
return parent::_instance(__CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// End ^ Native EOL ^ encoding
|
||||
156
ZeedFramework/library/Com/Model/Mapping/User.php
Normal file
156
ZeedFramework/library/Com/Model/Mapping/User.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2010-7-6
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Com_Model_Mapping_User extends Zeed_Db_Model
|
||||
{
|
||||
/*
|
||||
* @var string The table name.
|
||||
*/
|
||||
protected $_name = 'mapping_user';
|
||||
|
||||
/**
|
||||
* @var integer Primary key.
|
||||
*/
|
||||
protected $_primary = 'userid';
|
||||
|
||||
/**
|
||||
* @var string Table prefix.
|
||||
*/
|
||||
protected $_prefix = 'os_';
|
||||
|
||||
/**
|
||||
* 添加 Mapping 表信息
|
||||
*
|
||||
* @param array|Com_Entity_Mapping_User $set
|
||||
* @return integer|false 添加成功返回 userid 值,失败返回 false
|
||||
* @see Com_Model_User::add()
|
||||
*/
|
||||
public function add($set)
|
||||
{
|
||||
$mappingUser = new Com_Entity_Mapping_User();
|
||||
$mappingUser->fromObject($set);
|
||||
|
||||
if ($mappingUser->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $mappingUser->toArray();
|
||||
|
||||
try {
|
||||
$userid = $this->insert($data);
|
||||
|
||||
if (isset($data['userid']) && is_numeric($data['userid'])) {
|
||||
$userid = $data['userid'];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$userid = false;
|
||||
}
|
||||
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户模糊搜索
|
||||
* @param string $like
|
||||
* @return array|null
|
||||
*/
|
||||
public function getUserByusernameLike($like)
|
||||
{
|
||||
$like = trim($like);
|
||||
if (empty($like))
|
||||
return null;
|
||||
$like = str_replace(array(
|
||||
'%',
|
||||
'*'), array(
|
||||
'_',
|
||||
'%'), $like);
|
||||
$sql = sprintf('SELECT * FROM ' . $this->getTable() . ' WHERE `username` LIKE %s LIMIT 100', $this->getAdapter()->quote($like));
|
||||
try {
|
||||
$data = $this->getAdapter()->query($sql)->fetchAll();
|
||||
} catch (Exception $e) {
|
||||
echo $e;
|
||||
}
|
||||
return is_array($data) && ! empty($data) ? $data : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个新的用户标志
|
||||
*
|
||||
* @return integer|false
|
||||
* @throws Zeed_Exception
|
||||
*/
|
||||
public function getNewUserid()
|
||||
{
|
||||
/**
|
||||
* 临时从 Cache 的配置中获取 memcached 的实例对象
|
||||
*/
|
||||
$options = Zeed_Config::loadGroup('cache.memcached.backendOption');
|
||||
if (! is_array($options['servers']) || empty($options['servers'])) {
|
||||
|
||||
throw new Zeed_Exception('getNewUserid() is use memcached increment to get userid. must set memcached servers.');
|
||||
}
|
||||
|
||||
$memd = new Memcached();
|
||||
|
||||
foreach ($options['servers'] as $server) {
|
||||
if (! array_key_exists('port', $server)) {
|
||||
$server['port'] = 11211;
|
||||
}
|
||||
|
||||
if (! array_key_exists('weight', $server)) {
|
||||
$server['weight'] = 1;
|
||||
}
|
||||
|
||||
$memd->addServer($server['host'], $server['port'], $server['weight']);
|
||||
}
|
||||
|
||||
$memd->setOption(Memcached::OPT_COMPRESSION, false);
|
||||
$memd->setOption(Memcached::OPT_CONNECT_TIMEOUT, 1000);
|
||||
$memd->setOption(Memcached::OPT_RETRY_TIMEOUT, 0);
|
||||
$memd->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, false);
|
||||
|
||||
$id = 'UNIQUEID_' . $this->getTable();
|
||||
$offset = mt_rand(1, 5);
|
||||
|
||||
if (! ($tmp = @$memd->increment($id, $offset)) || empty($tmp)) {
|
||||
$init_no = $this->getMaxId() + 10 + $offset;
|
||||
|
||||
@$memd->set($id, $init_no);
|
||||
$tmp = $init_no;
|
||||
}
|
||||
|
||||
if (is_int($tmp) || (is_numeric($tmp) && ($tmp = (int) $tmp))) {
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Com_Model_Mapping_User
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
return parent::_instance(__CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// End ^ Native EOL ^ encoding
|
||||
152
ZeedFramework/library/Com/Model/Mapping/Username2userid.php
Normal file
152
ZeedFramework/library/Com/Model/Mapping/Username2userid.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/**
|
||||
* Zeed Platform Project
|
||||
* Based on Zeed Framework & Zend Framework.
|
||||
*
|
||||
* BTS - Billing Transaction Service
|
||||
* CAS - Central Authentication Service
|
||||
*
|
||||
* LICENSE
|
||||
* http://www.zeed.com.cn/license/
|
||||
*
|
||||
* @category Zeed
|
||||
* @package Zeed_ChangeMe
|
||||
* @subpackage ChangeMe
|
||||
* @copyright Copyright (c) 2010 Zeed Technologies PRC Inc. (http://www.zeed.com.cn)
|
||||
* @author Zeed Team (http://blog.zeed.com.cn)
|
||||
* @since 2010-7-6
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
class Com_Model_Mapping_Username2userid extends Zeed_Db_Model_Detach
|
||||
{
|
||||
/*
|
||||
* @var string The table name.
|
||||
*/
|
||||
protected $_name = 'mapping_username2userid';
|
||||
|
||||
/**
|
||||
* @var integer Primary key.
|
||||
*/
|
||||
protected $_primary = 'userid';
|
||||
|
||||
/**
|
||||
* @var string Table prefix.
|
||||
*/
|
||||
protected $_prefix = 'os_';
|
||||
|
||||
/**
|
||||
* 定义分表依据字段
|
||||
*
|
||||
* @var $_detachField string
|
||||
*/
|
||||
protected $_detachField = 'username';
|
||||
|
||||
/**
|
||||
* 添加 Mapping 表信息
|
||||
*
|
||||
* @param array|Com_Entity_Mapping_Username2userid $set
|
||||
* @return integer|false 添加成功返回 userid 值,失败返回 false
|
||||
* @see Com_Model_User::add()
|
||||
*/
|
||||
public function add($set)
|
||||
{
|
||||
$mappingUsername2userid = new Com_Entity_Mapping_Username2userid();
|
||||
$mappingUsername2userid->fromObject($set);
|
||||
if ($mappingUsername2userid->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! is_numeric($mappingUsername2userid->userid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $mappingUsername2userid->toArray();
|
||||
|
||||
if ($data['userid'] > 0) {
|
||||
$userid= $data['userid'];
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->detachToken($data);
|
||||
|
||||
try {
|
||||
$this->insert($data);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$userid = false;
|
||||
}
|
||||
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $username
|
||||
* @return BigInteger|null 如果失败返回 null
|
||||
* @cached
|
||||
*/
|
||||
public function getUseridByUsername($username, $domainid = 0)
|
||||
{
|
||||
$domainid = (int) $domainid;
|
||||
|
||||
$hash = md5($username.$domainid);
|
||||
$cache = Zeed_Cache::instance();
|
||||
|
||||
if ( ($data = $cache->load($hash)) && $data ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$this->detachToken($username);
|
||||
|
||||
$userid = null;
|
||||
|
||||
$where = $this->getAdapter()->quoteInto($this->getAdapter()->quoteIdentifier('username') . " = ? AND domainid = {$domainid}", $username);
|
||||
$sql = 'SELECT userid FROM ' . $this->getTable() . ' WHERE ' . $where;
|
||||
$row = $this->getAdapter()->query($sql)->fetchColumn(0);
|
||||
if ($row && is_numeric($row)) {
|
||||
$cache->save($row, $hash);
|
||||
$userid = $row;
|
||||
}
|
||||
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小写分表 username
|
||||
* 获取分表依据字段整型值,用于分表运算
|
||||
*
|
||||
* @param string $field
|
||||
* @return integer|null
|
||||
* @overwrite
|
||||
*/
|
||||
protected function getDetcahFieldForMod($value)
|
||||
{
|
||||
$forMod = null;
|
||||
|
||||
if (is_int($value)) {
|
||||
$forMod = $value;
|
||||
} elseif (is_string($value) && ! $this->_skipCrc32) {
|
||||
$value = mb_strtolower($value, 'utf-8');
|
||||
$checksum = crc32($value);
|
||||
$forMod = sprintf("%u", $checksum);
|
||||
} else {
|
||||
$forMod = $value;
|
||||
}
|
||||
|
||||
return $forMod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Com_Model_Mapping_Username2userid
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
return parent::_instance(__CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// End ^ Native EOL ^ encoding
|
||||
Reference in New Issue
Block a user