relationships.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. ?>
  5. <!DOCTYPE html>
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>客户关系管理</title>
  10. <link rel="stylesheet" href="css/common.css" type="text/css" />
  11. <script src="js/jquery-1.7.2.min.js"></script>
  12. <script src="js/js.js"></script>
  13. </head>
  14. <body class="clear">
  15. <div id="man_zone">
  16. <form action="" method="get" id="searchForm">
  17. <table width="100%" cellpadding="3" cellspacing="1" class="table1">
  18. <tr>
  19. <td>
  20. <input type="text" name="Keys" size="30" placeholder="关键词搜索" value="<?= htmlspecialchars($_GET['Keys'] ?? '') ?>" />
  21. <select name="FliterRelationType">
  22. <option value="">所有关系类型</option>
  23. <option value="1" <?= ($_GET['FliterRelationType'] ?? '') == '1' ? 'selected' : '' ?>>母公司-子公司</option>
  24. <option value="2" <?= ($_GET['FliterRelationType'] ?? '') == '2' ? 'selected' : '' ?>>供应商-客户</option>
  25. <option value="3" <?= ($_GET['FliterRelationType'] ?? '') == '3' ? 'selected' : '' ?>>合作伙伴</option>
  26. <option value="4" <?= ($_GET['FliterRelationType'] ?? '') == '4' ? 'selected' : '' ?>>竞争对手</option>
  27. <option value="5" <?= ($_GET['FliterRelationType'] ?? '') == '5' ? 'selected' : '' ?>>推荐人</option>
  28. <option value="6" <?= ($_GET['FliterRelationType'] ?? '') == '6' ? 'selected' : '' ?>>其他</option>
  29. </select>
  30. <select name="FliterStatus">
  31. <option value="">全部状态</option>
  32. <option value="1" <?= ($_GET['FliterStatus'] ?? '') == '1' ? 'selected' : '' ?>>启用</option>
  33. <option value="0" <?= ($_GET['FliterStatus'] ?? '') == '0' ? 'selected' : '' ?>>停用</option>
  34. </select>
  35. <input type="submit" value="搜索" class="btn1" />
  36. <input type="button" value="新增客户关系" class="btn1" onclick="window.location.href='relationshipAdd.php'" />
  37. </td>
  38. </tr>
  39. </table>
  40. </form>
  41. <table width="100%" cellpadding="3" cellspacing="1" class="table1">
  42. <tr>
  43. <th>源客户</th>
  44. <th>目标客户</th>
  45. <th>关系类型</th>
  46. <th>状态</th>
  47. <th>创建人</th>
  48. <th>创建时间</th>
  49. <th>更新时间</th>
  50. <th>操作</th>
  51. </tr>
  52. <?php
  53. // 构建查询条件
  54. $whereClause = "WHERE 1=1";
  55. $params = [];
  56. if (!empty($_GET['Keys'])) {
  57. $keys = '%' . $_GET['Keys'] . '%';
  58. $whereClause .= " AND (c1.cs_company LIKE ? OR c2.cs_company LIKE ? OR cr.description LIKE ?)";
  59. $params[] = $keys;
  60. $params[] = $keys;
  61. $params[] = $keys;
  62. }
  63. if (!empty($_GET['FliterRelationType'])) {
  64. $whereClause .= " AND cr.relationship_type = ?";
  65. $params[] = $_GET['FliterRelationType'];
  66. }
  67. if (isset($_GET['FliterStatus']) && $_GET['FliterStatus'] !== '') {
  68. $whereClause .= " AND cr.relationship_status = ?";
  69. $params[] = $_GET['FliterStatus'];
  70. }
  71. // 分页设置
  72. $page = isset($_GET['Page']) ? intval($_GET['Page']) : 1;
  73. $perpage = 20; // 每页显示条数
  74. $start = ($page - 1) * $perpage;
  75. // 计算总记录数
  76. $countQuery = "SELECT COUNT(*) as total
  77. FROM customer_relationship cr
  78. JOIN customer c1 ON cr.source_customer_id = c1.id
  79. JOIN customer c2 ON cr.target_customer_id = c2.id
  80. $whereClause";
  81. $stmt = $conn->prepare($countQuery);
  82. if (!empty($params)) {
  83. $types = str_repeat('s', count($params));
  84. $stmt->bind_param($types, ...$params);
  85. }
  86. $stmt->execute();
  87. $result = $stmt->get_result();
  88. $row = $result->fetch_assoc();
  89. $totalRecords = $row['total'];
  90. $totalPages = ceil($totalRecords / $perpage);
  91. // 获取关系列表
  92. $query = "SELECT cr.*,
  93. c1.cs_company as source_company,
  94. c2.cs_company as target_company,
  95. e.em_user as creator
  96. FROM customer_relationship cr
  97. JOIN customer c1 ON cr.source_customer_id = c1.id
  98. JOIN customer c2 ON cr.target_customer_id = c2.id
  99. LEFT JOIN employee e ON cr.employee_id = e.id
  100. $whereClause
  101. ORDER BY cr.updated_at DESC
  102. LIMIT ?, ?";
  103. $stmt = $conn->prepare($query);
  104. if (!empty($params)) {
  105. $params[] = $start;
  106. $params[] = $perpage;
  107. $types = str_repeat('s', count($params) - 2) . 'ii';
  108. $stmt->bind_param($types, ...$params);
  109. } else {
  110. $stmt->bind_param('ii', $start, $perpage);
  111. }
  112. $stmt->execute();
  113. $result = $stmt->get_result();
  114. if ($result->num_rows > 0) {
  115. while ($row = $result->fetch_assoc()) {
  116. // 获取关系类型描述
  117. $relationType = '';
  118. switch ($row['relationship_type']) {
  119. case 1: $relationType = '母公司-子公司'; break;
  120. case 2: $relationType = '供应商-客户'; break;
  121. case 3: $relationType = '合作伙伴'; break;
  122. case 4: $relationType = '竞争对手'; break;
  123. case 5: $relationType = '推荐人'; break;
  124. case 6: $relationType = '其他'; break;
  125. }
  126. $status = $row['relationship_status'] == 1 ? '<span style="color:green">启用</span>' : '<span style="color:red">停用</span>';
  127. echo '<tr>';
  128. echo '<td>' . textDecode($row['source_company']) . '</td>';
  129. echo '<td>' . textDecode($row['target_company']) . '</td>';
  130. echo '<td>' . $relationType . '</td>';
  131. echo '<td>' . $status . '</td>';
  132. echo '<td>' . textDecode($row['creator']) . '</td>';
  133. echo '<td>' . $row['created_at'] . '</td>';
  134. echo '<td>' . $row['updated_at'] . '</td>';
  135. echo '<td>
  136. <a href="relationshipAdd.php?id=' . $row['id'] . '">编辑</a> |
  137. <a href="javascript:void(0)" onclick="if(confirm(\'确定要删除此关系记录吗?\')) window.location.href=\'relationshipSave.php?act=delete&id=' . $row['id'] . '\'">删除</a>
  138. </td>';
  139. echo '</tr>';
  140. }
  141. } else {
  142. echo '<tr><td colspan="8" style="text-align:center">没有找到客户关系记录</td></tr>';
  143. }
  144. ?>
  145. </table>
  146. <!-- 分页 -->
  147. <div class="pages">
  148. <?php
  149. // 构建分页链接的基础URL
  150. $baseUrl = 'relationships.php?';
  151. if (!empty($_GET['Keys'])) $baseUrl .= 'Keys=' . urlencode($_GET['Keys']) . '&';
  152. if (!empty($_GET['FliterRelationType'])) $baseUrl .= 'FliterRelationType=' . $_GET['FliterRelationType'] . '&';
  153. if (isset($_GET['FliterStatus']) && $_GET['FliterStatus'] !== '') $baseUrl .= 'FliterStatus=' . $_GET['FliterStatus'] . '&';
  154. if ($page > 1) {
  155. echo '<a href="' . $baseUrl . 'Page=1">首页</a>';
  156. echo '<a href="' . $baseUrl . 'Page=' . ($page - 1) . '">上一页</a>';
  157. }
  158. // 显示5个页码,当前页在中间
  159. $startPage = max(1, $page - 2);
  160. $endPage = min($totalPages, $page + 2);
  161. for ($i = $startPage; $i <= $endPage; $i++) {
  162. if ($i == $page) {
  163. echo '<span class="current">' . $i . '</span>';
  164. } else {
  165. echo '<a href="' . $baseUrl . 'Page=' . $i . '">' . $i . '</a>';
  166. }
  167. }
  168. if ($page < $totalPages) {
  169. echo '<a href="' . $baseUrl . 'Page=' . ($page + 1) . '">下一页</a>';
  170. echo '<a href="' . $baseUrl . 'Page=' . $totalPages . '">末页</a>';
  171. }
  172. echo '<span class="pagestatus">第' . $page . '页/共' . $totalPages . '页</span>';
  173. ?>
  174. </div>
  175. </div>
  176. </body>
  177. </html>