index_not_html.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. require_once 'conn.php';
  3. $IP = getIp();
  4. $Act = $_GET['act'] ?? '';
  5. if ($Act == "logout") {
  6. $stmt = $conn->prepare("INSERT INTO logrecord (loginName, loginTime, loginAct) VALUES (?, ?, ?)");
  7. $logAct = $_SESSION['employee_name'] . " " . date('Y-m-d H:i:s') . "从" . $IP . "退出系统";
  8. $stmt->bind_param("sss", $_SESSION['employee_name'], date('Y-m-d H:i:s'), $logAct);
  9. $stmt->execute();
  10. // 清除所有session
  11. $sessionKeys = ['employee_id', 'employee_name', 't', 't1', 't2', 't3', 't4', 'd1', 'd2'];
  12. foreach ($sessionKeys as $key) {
  13. unset($_SESSION[$key]);
  14. }
  15. }
  16. unset($_SESSION['employee_id']);
  17. if ($Act == "login") {
  18. $loginuser = textEncode($_POST['loginuser'] ?? '');
  19. $loginpwd = textEncode($_POST['loginpwd'] ?? '');
  20. $logincode = $_POST['logincode'] ?? '';
  21. if (empty($loginuser)) {
  22. echo "1";
  23. exit;
  24. }
  25. if (empty($loginpwd)) {
  26. echo "2";
  27. exit;
  28. }
  29. if ($logincode != $_SESSION['zengscode']) {
  30. echo "3";
  31. exit;
  32. }
  33. // 查询用户
  34. $stmt = $conn->prepare("SELECT id, em_user, em_password, em_role, em_code, em_email, em_tel, lastIp FROM employee WHERE em_user = ?");
  35. $stmt->bind_param("s", $loginuser);
  36. $stmt->execute();
  37. $result = $stmt->get_result();
  38. if ($result->num_rows == 0) {
  39. echo "4";
  40. exit;
  41. }
  42. $row = $result->fetch_assoc();
  43. if ($row['em_password'] != md5($loginpwd)) {
  44. echo "5";
  45. exit;
  46. }
  47. $_SESSION['employee_id'] = (int)$row['id'];
  48. $_SESSION['employee_name'] = $row['em_user'];
  49. echo "7";
  50. // 更新最后登录IP
  51. $stmt = $conn->prepare("UPDATE employee SET lastIp = ? WHERE id = ?");
  52. $stmt->bind_param("si", $IP, $_SESSION['employee_id']);
  53. $stmt->execute();
  54. // 处理回收逻辑
  55. $BackToSeaStr = "SELECT id, cs_updatetime, cs_claimdate, cs_claimFrom, cs_chain
  56. FROM customer
  57. WHERE cs_claimFrom != ''
  58. AND cs_claimdate > '2023-01-01'
  59. AND cs_deal != 3
  60. AND cs_belong = ?";
  61. $stmt = $conn->prepare($BackToSeaStr);
  62. $stmt->bind_param("i", $_SESSION['employee_id']);
  63. $stmt->execute();
  64. $result = $stmt->get_result();
  65. while ($row = $result->fetch_assoc()) {
  66. $timeDiff = (strtotime('now') - strtotime($row['cs_claimdate'])) / (24 * 3600);
  67. $updateDiff = strtotime($row['cs_updatetime']) - strtotime($row['cs_claimdate']);
  68. if ($timeDiff > 4 && $updateDiff == 0) {
  69. $myArray = explode(",", $row['cs_chain']);
  70. $Litem = end($myArray);
  71. $cs_chain = ($Litem == $row['cs_claimFrom']) ?
  72. $row['cs_claimFrom'] :
  73. $row['cs_chain'] . "," . $row['cs_claimFrom'];
  74. $updateStr = "UPDATE customer SET cs_belong = ?, cs_chain = ? WHERE id = ?";
  75. $stmt2 = $conn->prepare($updateStr);
  76. $stmt2->bind_param("isi", $row['cs_claimFrom'], $cs_chain, $row['id']);
  77. $stmt2->execute();
  78. } elseif ($updateDiff > 0) {
  79. $stmt2 = $conn->prepare("UPDATE customer SET cs_claimdate = '2022-12-31' WHERE id = ?");
  80. $stmt2->bind_param("i", $row['id']);
  81. $stmt2->execute();
  82. }
  83. }
  84. // 统计数据
  85. $countQueries = [
  86. 't' => "SELECT COUNT(id) FROM customer WHERE cs_belong = ?",
  87. 't1' => "SELECT COUNT(id) FROM customer WHERE cs_type = 1 AND cs_belong = ?",
  88. 't2' => "SELECT COUNT(id) FROM customer WHERE cs_type = 2 AND cs_belong = ?",
  89. 't3' => "SELECT COUNT(id) FROM customer WHERE cs_type = 3 AND cs_belong = ?",
  90. 't4' => "SELECT COUNT(id) FROM customer WHERE cs_type = 4 AND cs_belong = ?",
  91. 'd1' => "SELECT COUNT(id) FROM customer WHERE cs_deal = 3 AND cs_belong = ?",
  92. 'd2' => "SELECT COUNT(id) FROM customer WHERE cs_deal = 2 AND cs_belong = ?",
  93. 'd3' => "SELECT COUNT(id) FROM customer WHERE DATEDIFF(NOW(), cs_updatetime) > 120 AND cs_belong = ?"
  94. ];
  95. foreach ($countQueries as $key => $query) {
  96. $stmt = $conn->prepare($query);
  97. $stmt->bind_param("i", $_SESSION['employee_id']);
  98. $stmt->execute();
  99. $result = $stmt->get_result();
  100. $_SESSION[$key] = $result->fetch_row()[0];
  101. }
  102. // 记录登录日志
  103. $stmt = $conn->prepare("INSERT INTO logrecord (loginName, loginTime, loginAct) VALUES (?, ?, ?)");
  104. $logAct = $_SESSION['employee_name'] . " " . date('Y-m-d H:i:s') . "从" . $IP . "登录";
  105. $stmt->bind_param("sss", $_SESSION['employee_name'], date('Y-m-d H:i:s'), $logAct);
  106. $stmt->execute();
  107. exit;
  108. }