码迷,mamicode.com
首页 > 其他好文 > 详细

tp5生成6位不重复验证码

时间:2018-11-29 12:23:28      阅读:529      评论:0      收藏:0      [点我收藏+]

标签:not   utf8   fun   having   pre   empty   cti   arc   comm   

/**
     * 获取激活码
     */
    public function getnum()
    {
        $num = microtime(true);
        for ($i = $num; $i < ($num + 10); $i++) {
//            dump(substr(md5($i), 0, 6));exit;
            Db::name("fangchan_jihuoma")->insert([
                ‘num‘ => substr(md5($i), 0, 6),
                ‘status‘ => ‘‘,
                ‘created_time‘ => time(),
                ‘info_time‘ => $i
            ]);
        }
        $sql = "select count(*) as sum,num from osc_fangchan_jihuoma group by num HAVING sum>1";//查询重复的验证码数量和重复的验证码
        $data = Db::query($sql);
        if(!empty($data)) {
            foreach($data as $k=> $v) {
                for($j=0;$j<$v[‘sum‘];$j++){
                    Db::name("fangchan_jihuoma")->where(‘num‘,1)->delete();删除重复的验证码
                }
            }
        }
        $this->success(‘激活码已生成!‘);
    }
CREATE TABLE `osc_fangchan_jihuoma` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 自增长id,
  `num` varchar(8) NOT NULL COMMENT 激活码,
  `uid` int(10) unsigned zerofill DEFAULT NULL COMMENT member表id,
  `status` tinyint(1) unsigned zerofill NOT NULL DEFAULT 0 COMMENT 是否核销 0:未核销,1:已核销,
  `created_time` int(11) NOT NULL DEFAULT 0 COMMENT 激活码创建时间,
  `info_time` int(11) NOT NULL DEFAULT 0 COMMENT 标记用时间,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=134 DEFAULT CHARSET=utf8mb4;

 

tp5生成6位不重复验证码

标签:not   utf8   fun   having   pre   empty   cti   arc   comm   

原文地址:https://www.cnblogs.com/shark1100913/p/10037146.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!