123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- require_once 'conn.php';
- $IP = getIp();
- $Act = $_GET['act'] ?? '';
- if ($Act == "logout") {
- $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();
-
- // 清除所有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;
- }
|