smslogic.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-03 16:33:07
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-09-03 17:58:59
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\smscoderecordmodel;
  10. use app\index\model\userinfomodel;
  11. class smslogic
  12. {
  13. /***
  14. * 20210903
  15. * wj
  16. * 创建验证码
  17. */
  18. public function createCode($arr)
  19. {
  20. $m_scr = new smscoderecordmodel();
  21. $m_u = new userinfomodel();
  22. if (!isset($arr['smscode']) || !empty($arr['smscode']) || !is_numeric($arr['smscode'])) {
  23. return false;
  24. }
  25. $tel = $arr['tel'];
  26. $wuInfo = $m_u->getInfo(['telno' => $tel]);
  27. $wid = empty($wuInfo) ? 0 : $wuInfo['id'];
  28. $insertData = [
  29. 'tel' => $tel,
  30. 'wid' => $wid,
  31. 'smscode' => $arr['smscode'],
  32. 'createtime' => time(),
  33. ];
  34. $id = $m_scr->insinfo($insertData);
  35. return $id;
  36. }
  37. /***
  38. * 20210903
  39. * wj
  40. * 根据id删除验证码
  41. */
  42. public function deleteCoeById($id)
  43. {
  44. $m_scr = new smscoderecordmodel();
  45. $result = $m_scr->delbyid($id);
  46. return $result;
  47. }
  48. public function getinfobyid($id)
  49. {
  50. $m_scr = new smscoderecordmodel();
  51. $sccInfo = $m_scr->getinfobyid($id);
  52. return $sccInfo;
  53. }
  54. public function getlastinfobytel($tel)
  55. {
  56. $m_scr = new smscoderecordmodel();
  57. $sccInfo = $m_scr->getlastinfobytel($tel);
  58. return $sccInfo;
  59. }
  60. public function deletebytime($tel)
  61. {
  62. $m_scr = new smscoderecordmodel();
  63. //间隔时间大于2分钟删除
  64. //$maxtime = 120;
  65. $maxtime = 120;
  66. $time = time();
  67. $where['tel'] = $tel;
  68. $sccInfo = $m_scr->getinfo($where, false);
  69. foreach ($sccInfo as $value) {
  70. $createTime = $value['createtime'];
  71. if ($time > $createTime && $time - $createTime >= $maxtime) {
  72. $result = $m_scr->deletebyid($value['id']);
  73. }
  74. }
  75. }
  76. }