query($userInfoQuery); if ($userResult && $userRow = $userResult->fetch_assoc()) { // 只有 em_permission_role_id=2 表示该用户是组长 $isLeader = ($userRow['em_permission_role_id'] == 2); } // 如果不是组长,直接跳转到客户列表页面 if (!$isLeader) { header('Location: customers.php'); exit; } $act = $_GET['act'] ?? ''; if ($act == 'postchk') { $keys = urlencode($_GET['Keys'] ?? ''); $page = $_GET['Page'] ?? ''; $chkact = $_POST['chkact'] ?? ''; if (isset($_POST['chkbox'])) { $sqlStr = "(" . implode(',', array_map('intval', (array)$_POST['chkbox'])) . ")"; $count = count($_POST['chkbox']); // 检查是否为员工转让操作 if (substr($chkact, 0, 1) === 't') { // 从chkact值中提取员工ID $employeeId = (int)substr($chkact, 1); // 获取员工代码和名称 $stmt = $conn->prepare("SELECT em_code, em_user FROM employee WHERE id = ?"); $stmt->bind_param("i", $employeeId); $stmt->execute(); $result = $stmt->get_result(); $employeeCode = ''; $employeeName = '未知业务员'; if ($row = $result->fetch_assoc()) { $employeeCode = $row['em_code']; $employeeName = $row['em_user']; } $stmt->close(); // 更新客户记录 $sql = "UPDATE customer SET cs_updatetime = NOW(), cs_code = REPLACE(cs_code, '-', '/{$employeeCode}-'), cs_belong = {$employeeId}, cs_chain = CONCAT(cs_chain, ',{$employeeId}') WHERE id IN {$sqlStr}"; $conn->query($sql); // 记录操作日志 $ids = implode(',', array_map('intval', (array)$_POST['chkbox'])); $action = "{$_SESSION['employee_name']} 批量转移{$count}个客户({$ids})给组员【{$employeeName}】"; logAction($action); } else { $chkact = (int)$chkact; $sql = "UPDATE customer SET cs_deal = {$chkact} WHERE id IN {$sqlStr}"; $conn->query($sql); // 记录跟进阶段变更日志 $dealStatus = ""; switch($chkact) { case 0: $dealStatus = "无响应"; break; case 1: $dealStatus = "背景调查"; break; case 2: $dealStatus = "明确需求"; break; case 3: $dealStatus = "已成交"; break; default: $dealStatus = "未知状态"; } $ids = implode(',', array_map('intval', (array)$_POST['chkbox'])); $action = "{$_SESSION['employee_name']} 批量将{$count}个客户({$ids})的跟进阶段更改为【{$dealStatus}】"; logAction($action); } $deleteTag = "DELETE FROM tagtable WHERE customerId IN " . $sqlStr; $conn->query($deleteTag); } header("Location: ?Keys=" . $keys . "&Page=" . $page); exit; } // 处理搜索和过滤参数 $keys = $_GET['Keys'] ?? ''; $keys = str_replace([" ", "+"], "", $keys); $keyscode = textEncode($keys); $page = $_GET['Page'] ?? ''; $filters = [ 'Country' => $_GET['fliterCountry'] ?? '', 'Qudao' => $_GET['fliterQudao'] ?? '', 'Deal' => $_GET['fliterDeal'] ?? '', 'Business' => $_GET['fliterBusiness'] ?? '', 'Contact' => $_GET['fliterContact'] ?? '' ]; $filterStr = ""; $urlStr = ""; // 构建过滤条件 if (!empty($filters['Country'])) { $filterStr .= " AND c.cs_country=" . (int)$filters['Country']; $urlStr .= "&fliterCountry=" . $filters['Country']; } if (!empty($filters['Qudao'])) { $filterStr .= " AND c.cs_from=" . (int)$filters['Qudao']; $urlStr .= "&fliterQudao=" . $filters['Qudao']; } if (!empty($filters['Deal'])) { $filterStr .= " AND c.cs_deal=" . (int)$filters['Deal']; $urlStr .= "&fliterDeal=" . $filters['Deal']; } if (!empty($filters['Business'])) { $filterStr .= " AND c.cs_type=" . (int)$filters['Business']; $urlStr .= "&fliterBusiness=" . $filters['Business']; } // 改进联系方式过滤查询 if (!empty($filters['Contact'])) { switch ($filters['Contact']) { case "1": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE tel_1 != '' OR tel_2 != '' OR tel_3 != '')"; break; case "2": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE wechat_1 != '' OR wechat_2 != '' OR wechat_3 != '')"; break; case "3": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE whatsapp_1 != '' OR whatsapp_2 != '' OR whatsapp_3 != '')"; break; case "4": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE email_1 != '' OR email_2 != '' OR email_3 != '')"; break; case "5": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE linkedin_1 != '' OR linkedin_2 != '' OR linkedin_3 != '')"; break; case "6": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE facebook_1 != '' OR facebook_2 != '' OR facebook_3 != '')"; break; case "7": $filterStr .= " AND c.id IN (SELECT customer_id FROM customer_contact WHERE alibaba_1 != '' OR alibaba_2 != '' OR alibaba_3 != '')"; break; } $urlStr .= "&fliterContact=" . $filters['Contact']; } $keys = urlencode($keys); $hrefstr = "?keys=" . $keys; ?>