prepare("INSERT INTO logrecord (loginName, loginTime, loginAct) VALUES (?, ?, ?)"); $logAct = $_SESSION['employee_name'] . " " . date('Y-m-d H:i:s') . "从" . $IP . "退出系统"; $stmt->bind_param("sss", $_SESSION['employee_name'], date('Y-m-d H:i:s'), $logAct); $stmt->execute(); // 清除所有session $sessionKeys = ['employee_id', 'employee_name', 't', 't1', 't2', 't3', 't4', 'd1', 'd2']; foreach ($sessionKeys as $key) { unset($_SESSION[$key]); } } unset($_SESSION['employee_id']); if ($Act == "login") { $loginuser = textEncode($_POST['loginuser'] ?? ''); $loginpwd = textEncode($_POST['loginpwd'] ?? ''); $logincode = $_POST['logincode'] ?? ''; if (empty($loginuser)) { echo "1"; exit; } if (empty($loginpwd)) { echo "2"; exit; } if ($logincode != $_SESSION['zengscode']) { echo "3"; exit; } // 查询用户 $stmt = $conn->prepare("SELECT id, em_user, em_password, em_role, em_code, em_email, em_tel, lastIp FROM employee WHERE em_user = ?"); $stmt->bind_param("s", $loginuser); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows == 0) { echo "4"; exit; } $row = $result->fetch_assoc(); if ($row['em_password'] != md5($loginpwd)) { echo "5"; exit; } $_SESSION['employee_id'] = (int)$row['id']; $_SESSION['employee_name'] = $row['em_user']; echo "7"; // 更新最后登录IP $stmt = $conn->prepare("UPDATE employee SET lastIp = ? WHERE id = ?"); $stmt->bind_param("si", $IP, $_SESSION['employee_id']); $stmt->execute(); // 处理回收逻辑 $BackToSeaStr = "SELECT id, cs_updatetime, cs_claimdate, cs_claimFrom, cs_chain FROM customer WHERE cs_claimFrom != '' AND cs_claimdate > '2023-01-01' AND cs_deal != 3 AND cs_belong = ?"; $stmt = $conn->prepare($BackToSeaStr); $stmt->bind_param("i", $_SESSION['employee_id']); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { $timeDiff = (strtotime('now') - strtotime($row['cs_claimdate'])) / (24 * 3600); $updateDiff = strtotime($row['cs_updatetime']) - strtotime($row['cs_claimdate']); if ($timeDiff > 4 && $updateDiff == 0) { $myArray = explode(",", $row['cs_chain']); $Litem = end($myArray); $cs_chain = ($Litem == $row['cs_claimFrom']) ? $row['cs_claimFrom'] : $row['cs_chain'] . "," . $row['cs_claimFrom']; $updateStr = "UPDATE customer SET cs_belong = ?, cs_chain = ? WHERE id = ?"; $stmt2 = $conn->prepare($updateStr); $stmt2->bind_param("isi", $row['cs_claimFrom'], $cs_chain, $row['id']); $stmt2->execute(); } elseif ($updateDiff > 0) { $stmt2 = $conn->prepare("UPDATE customer SET cs_claimdate = '2022-12-31' WHERE id = ?"); $stmt2->bind_param("i", $row['id']); $stmt2->execute(); } } // 统计数据 $countQueries = [ 't' => "SELECT COUNT(id) FROM customer WHERE cs_belong = ?", 't1' => "SELECT COUNT(id) FROM customer WHERE cs_type = 1 AND cs_belong = ?", 't2' => "SELECT COUNT(id) FROM customer WHERE cs_type = 2 AND cs_belong = ?", 't3' => "SELECT COUNT(id) FROM customer WHERE cs_type = 3 AND cs_belong = ?", 't4' => "SELECT COUNT(id) FROM customer WHERE cs_type = 4 AND cs_belong = ?", 'd1' => "SELECT COUNT(id) FROM customer WHERE cs_deal = 3 AND cs_belong = ?", 'd2' => "SELECT COUNT(id) FROM customer WHERE cs_deal = 2 AND cs_belong = ?", 'd3' => "SELECT COUNT(id) FROM customer WHERE DATEDIFF(NOW(), cs_updatetime) > 120 AND cs_belong = ?" ]; foreach ($countQueries as $key => $query) { $stmt = $conn->prepare($query); $stmt->bind_param("i", $_SESSION['employee_id']); $stmt->execute(); $result = $stmt->get_result(); $_SESSION[$key] = $result->fetch_row()[0]; } // 记录登录日志 $stmt = $conn->prepare("INSERT INTO logrecord (loginName, loginTime, loginAct) VALUES (?, ?, ?)"); $logAct = $_SESSION['employee_name'] . " " . date('Y-m-d H:i:s') . "从" . $IP . "登录"; $stmt->bind_param("sss", $_SESSION['employee_name'], date('Y-m-d H:i:s'), $logAct); $stmt->execute(); exit; }