SmsRecord.php 969 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class SmsRecord extends Model
  7. {
  8. public function add($phone){
  9. $curTime = time();
  10. $data = [
  11. 'phone' => $phone,
  12. 'code' => mt_rand(100000,999999),
  13. 'status' => 0,
  14. 'add_time' => $curTime,
  15. 'end_time' => $curTime + 10*60
  16. ];
  17. $ret = Db::name('sms_record')->insert($data);
  18. return $ret?$data['code']:false;
  19. }
  20. // 验证手机验证码
  21. public function checkCode($phone,$code){
  22. $info = Db::name('sms_record')
  23. ->where('phone',$phone)
  24. ->where('code',$code)
  25. ->find();
  26. if(!$info){
  27. return false;
  28. }
  29. if($info['status'] != 0 || $info['end_time'] < time()){
  30. return false;
  31. }
  32. Db::name('sms_record')->where('id',$info['id'])->setField('status',1);
  33. return true;
  34. }
  35. }