123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- require_once 'conn.php';
- checkLogin();
- ?>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>客户关系管理</title>
- <link rel="stylesheet" href="css/common.css" type="text/css" />
- <script src="js/jquery-1.7.2.min.js"></script>
- <script src="js/js.js"></script>
- </head>
- <body class="clear">
- <div id="man_zone">
- <form action="" method="get" id="searchForm">
- <table width="100%" cellpadding="3" cellspacing="1" class="table1">
- <tr>
- <td>
- <input type="text" name="Keys" size="30" placeholder="关键词搜索" value="<?= htmlspecialchars($_GET['Keys'] ?? '') ?>" />
- <select name="FliterRelationType">
- <option value="">所有关系类型</option>
- <option value="1" <?= ($_GET['FliterRelationType'] ?? '') == '1' ? 'selected' : '' ?>>母公司-子公司</option>
- <option value="2" <?= ($_GET['FliterRelationType'] ?? '') == '2' ? 'selected' : '' ?>>供应商-客户</option>
- <option value="3" <?= ($_GET['FliterRelationType'] ?? '') == '3' ? 'selected' : '' ?>>合作伙伴</option>
- <option value="4" <?= ($_GET['FliterRelationType'] ?? '') == '4' ? 'selected' : '' ?>>竞争对手</option>
- <option value="5" <?= ($_GET['FliterRelationType'] ?? '') == '5' ? 'selected' : '' ?>>推荐人</option>
- <option value="6" <?= ($_GET['FliterRelationType'] ?? '') == '6' ? 'selected' : '' ?>>其他</option>
- </select>
- <select name="FliterStatus">
- <option value="">全部状态</option>
- <option value="1" <?= ($_GET['FliterStatus'] ?? '') == '1' ? 'selected' : '' ?>>启用</option>
- <option value="0" <?= ($_GET['FliterStatus'] ?? '') == '0' ? 'selected' : '' ?>>停用</option>
- </select>
- <input type="submit" value="搜索" class="btn1" />
- <input type="button" value="新增客户关系" class="btn1" onclick="window.location.href='relationshipAdd.php'" />
- </td>
- </tr>
- </table>
- </form>
-
- <table width="100%" cellpadding="3" cellspacing="1" class="table1">
- <tr>
- <th>源客户</th>
- <th>目标客户</th>
- <th>关系类型</th>
- <th>状态</th>
- <th>创建人</th>
- <th>创建时间</th>
- <th>更新时间</th>
- <th>操作</th>
- </tr>
- <?php
- // 构建查询条件
- $whereClause = "WHERE 1=1";
- $params = [];
-
- if (!empty($_GET['Keys'])) {
- $keys = '%' . $_GET['Keys'] . '%';
- $whereClause .= " AND (c1.cs_company LIKE ? OR c2.cs_company LIKE ? OR cr.description LIKE ?)";
- $params[] = $keys;
- $params[] = $keys;
- $params[] = $keys;
- }
-
- if (!empty($_GET['FliterRelationType'])) {
- $whereClause .= " AND cr.relationship_type = ?";
- $params[] = $_GET['FliterRelationType'];
- }
-
- if (isset($_GET['FliterStatus']) && $_GET['FliterStatus'] !== '') {
- $whereClause .= " AND cr.relationship_status = ?";
- $params[] = $_GET['FliterStatus'];
- }
-
- // 分页设置
- $page = isset($_GET['Page']) ? intval($_GET['Page']) : 1;
- $perpage = 20; // 每页显示条数
- $start = ($page - 1) * $perpage;
-
- // 计算总记录数
- $countQuery = "SELECT COUNT(*) as total
- FROM customer_relationship cr
- JOIN customer c1 ON cr.source_customer_id = c1.id
- JOIN customer c2 ON cr.target_customer_id = c2.id
- $whereClause";
-
- $stmt = $conn->prepare($countQuery);
- if (!empty($params)) {
- $types = str_repeat('s', count($params));
- $stmt->bind_param($types, ...$params);
- }
- $stmt->execute();
- $result = $stmt->get_result();
- $row = $result->fetch_assoc();
- $totalRecords = $row['total'];
- $totalPages = ceil($totalRecords / $perpage);
-
- // 获取关系列表
- $query = "SELECT cr.*,
- c1.cs_company as source_company,
- c2.cs_company as target_company,
- e.em_user as creator
- FROM customer_relationship cr
- JOIN customer c1 ON cr.source_customer_id = c1.id
- JOIN customer c2 ON cr.target_customer_id = c2.id
- LEFT JOIN employee e ON cr.employee_id = e.id
- $whereClause
- ORDER BY cr.updated_at DESC
- LIMIT ?, ?";
-
- $stmt = $conn->prepare($query);
- if (!empty($params)) {
- $params[] = $start;
- $params[] = $perpage;
- $types = str_repeat('s', count($params) - 2) . 'ii';
- $stmt->bind_param($types, ...$params);
- } else {
- $stmt->bind_param('ii', $start, $perpage);
- }
-
- $stmt->execute();
- $result = $stmt->get_result();
-
- if ($result->num_rows > 0) {
- while ($row = $result->fetch_assoc()) {
- // 获取关系类型描述
- $relationType = '';
- switch ($row['relationship_type']) {
- case 1: $relationType = '母公司-子公司'; break;
- case 2: $relationType = '供应商-客户'; break;
- case 3: $relationType = '合作伙伴'; break;
- case 4: $relationType = '竞争对手'; break;
- case 5: $relationType = '推荐人'; break;
- case 6: $relationType = '其他'; break;
- }
-
- $status = $row['relationship_status'] == 1 ? '<span style="color:green">启用</span>' : '<span style="color:red">停用</span>';
-
- echo '<tr>';
- echo '<td>' . textDecode($row['source_company']) . '</td>';
- echo '<td>' . textDecode($row['target_company']) . '</td>';
- echo '<td>' . $relationType . '</td>';
- echo '<td>' . $status . '</td>';
- echo '<td>' . textDecode($row['creator']) . '</td>';
- echo '<td>' . $row['created_at'] . '</td>';
- echo '<td>' . $row['updated_at'] . '</td>';
- echo '<td>
- <a href="relationshipAdd.php?id=' . $row['id'] . '">编辑</a> |
- <a href="javascript:void(0)" onclick="if(confirm(\'确定要删除此关系记录吗?\')) window.location.href=\'relationshipSave.php?act=delete&id=' . $row['id'] . '\'">删除</a>
- </td>';
- echo '</tr>';
- }
- } else {
- echo '<tr><td colspan="8" style="text-align:center">没有找到客户关系记录</td></tr>';
- }
- ?>
- </table>
-
- <!-- 分页 -->
- <div class="pages">
- <?php
- // 构建分页链接的基础URL
- $baseUrl = 'relationships.php?';
- if (!empty($_GET['Keys'])) $baseUrl .= 'Keys=' . urlencode($_GET['Keys']) . '&';
- if (!empty($_GET['FliterRelationType'])) $baseUrl .= 'FliterRelationType=' . $_GET['FliterRelationType'] . '&';
- if (isset($_GET['FliterStatus']) && $_GET['FliterStatus'] !== '') $baseUrl .= 'FliterStatus=' . $_GET['FliterStatus'] . '&';
-
- if ($page > 1) {
- echo '<a href="' . $baseUrl . 'Page=1">首页</a>';
- echo '<a href="' . $baseUrl . 'Page=' . ($page - 1) . '">上一页</a>';
- }
-
- // 显示5个页码,当前页在中间
- $startPage = max(1, $page - 2);
- $endPage = min($totalPages, $page + 2);
-
- for ($i = $startPage; $i <= $endPage; $i++) {
- if ($i == $page) {
- echo '<span class="current">' . $i . '</span>';
- } else {
- echo '<a href="' . $baseUrl . 'Page=' . $i . '">' . $i . '</a>';
- }
- }
-
- if ($page < $totalPages) {
- echo '<a href="' . $baseUrl . 'Page=' . ($page + 1) . '">下一页</a>';
- echo '<a href="' . $baseUrl . 'Page=' . $totalPages . '">末页</a>';
- }
-
- echo '<span class="pagestatus">第' . $page . '页/共' . $totalPages . '页</span>';
- ?>
- </div>
- </div>
- </body>
- </html>
|