//根据ID计算唯一邀请码
public static function createCode($Id){
static $sourceString = [
0,1,2,3,4,5,6,7,8,9,10,
'a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','p','q','r',
's','t','u','v','w','x',
'y','z'
];

$num = $Id;
$code = '';
while($num)
{
$mod = $num % 36;
$num = (int)($num / 36);
$code = "{$sourceString[$mod]}{$code}";
}

//判断code的长度
if( empty($code[4]))
str_pad($code,5,'0',STR_PAD_LEFT);

return $code;
}

posted on 2019-10-24 08:24  caohongchang  阅读(644)  评论(0)    收藏  举报