loginlogic.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-03 15:18:25
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-11-10 17:41:01
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\companymodel;
  10. use app\index\model\smscoderecordmodel;
  11. use app\index\model\userinfomodel;
  12. use app\index\model\workermodel;
  13. class loginlogic
  14. {
  15. private function checkwechatlogin($loginfo)
  16. {
  17. if (!isset($loginfo['unionid']) || empty($loginfo['unionid'])) {
  18. return false;
  19. }
  20. return true;
  21. }
  22. //短信登录
  23. /*
  24. * 20210908
  25. * edit by steelxu
  26. * 如果短信验证成功应当返回用户数据
  27. */
  28. public function smslogin($loginfo)
  29. {
  30. $m_sc = new smscoderecordmodel();
  31. $m_u = new userinfomodel();
  32. $m_w = new workermodel();
  33. $checkResult = $this->checksmslogin($loginfo);
  34. if (!$checkResult) {
  35. return backarr(-1, '请求数据错误');
  36. }
  37. $tel = $loginfo['tel'];
  38. $smscode = $loginfo['smscode'];
  39. $searchData = [
  40. 'tel' => $tel,
  41. 'smscode' => $smscode,
  42. ];
  43. $sccInfo = $m_sc->getinfo($searchData);
  44. if ($sccInfo) {
  45. $m_sc->deletebyid($sccInfo['id']);
  46. $uInfo = $m_u->getInfo(['telno' => $tel]);
  47. if (empty($uInfo['isactive'])) {
  48. return backarr(0, '用户状态不可用');
  49. }
  50. if (!$uInfo) {
  51. $insertinfo['telno'] = $tel;
  52. $id = $m_u->insertData($insertinfo);
  53. $info = [
  54. 'id' => $id,
  55. 'gender' => '',
  56. 'telno' => $tel,
  57. 'wname' => '',
  58. 'isactive' => '1',
  59. 'labid' => 0,
  60. 'sfzid' => false,
  61. 'company' => [], //非企业用户
  62. ];
  63. //worderinsert
  64. $winsertInfo = [
  65. 'userid' => $id,
  66. 'telno' => $tel,
  67. ];
  68. $wid = $m_w->insertData($winsertInfo);
  69. //return backarr(2, '未注册');
  70. return backarr(1, '登录成功', $info);
  71. } else {
  72. //$m_sc->deletebyid($sccInfo['id']);
  73. $m_c = new companymodel();
  74. $cinfo = $m_c->getInfo(['userid' => $uInfo['id'], 'isactive' => 1], ['id', 'company']);
  75. $info = array();
  76. $info['id'] = $uInfo['id'];
  77. $info['gender'] = $uInfo['gender'];
  78. $info['telno'] = $uInfo['telno'];
  79. $info['wname'] = $uInfo['wname'];
  80. $info['isactive'] = strval($uInfo['isactive']);
  81. $info['labid'] = $uInfo['labid'];
  82. $info['sfzid'] = empty($uInfo['sfzid']) ? false : true;
  83. $info['company'] = empty($cinfo) ? [] : $cinfo;
  84. return backarr(1, '登录成功', $info);
  85. }
  86. } else {
  87. return backarr(0, '登录失败');
  88. }
  89. }
  90. private function checksmslogin($loginfo)
  91. {
  92. $fillFiled = ['tel', 'smscode'];
  93. foreach ($fillFiled as $value) {
  94. if (!isset($loginfo[$value]) || empty($loginfo[$value]) || !is_numeric($loginfo[$value])) {
  95. return false;
  96. }
  97. }
  98. return true;
  99. }
  100. }