123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class SmsRecord extends Model
- {
- public function add($phone){
- $curTime = time();
- $data = [
- 'phone' => $phone,
- 'code' => mt_rand(100000,999999),
- 'status' => 0,
- 'add_time' => $curTime,
- 'end_time' => $curTime + 10*60
- ];
- $ret = Db::name('sms_record')->insert($data);
- return $ret?$data['code']:false;
- }
- // 验证手机验证码
- public function checkCode($phone,$code){
- $info = Db::name('sms_record')
- ->where('phone',$phone)
- ->where('code',$code)
- ->find();
- if(!$info){
- return false;
- }
- if($info['status'] != 0 || $info['end_time'] < time()){
- return false;
- }
- Db::name('sms_record')->where('id',$info['id'])->setField('status',1);
- return true;
- }
- }
|