php添加邀请码

/*
* 生成邀请码 唯一
* */
public function make_coupon_card()  {
     $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $rand = $code[rand(0,25)]
  .strtoupper(dechex(date('m')))
  .date('d').substr(time(),-5)
  .substr(microtime(),2,5)
  .sprintf('%02d',rand(0,99));
  for(
    $a = md5( $rand, true ),
    $s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',
    $d = '',
    $f = 0;
    $f < 8;
    $g = ord( $a[ $f ] ),
    $d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],
    $f++
  );
// 判断$d 是否存在
  if(M('users')->where("my_invitation = '$d'")->find()) {
    return self::make_coupon_card();
  }
  return $d;
}

posted @ 2020-08-10 11:24  をもって剣を制す  阅读(261)  评论(0编辑  收藏  举报