team.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. $datestart = $_POST['start'] ?? '';
  5. $dateend = $_POST['end'] ?? '';
  6. $currentMonth = date('Y-m-1 00:00:00');
  7. if (empty($datestart) || !strtotime($datestart)) {
  8. $datestart = $currentMonth;
  9. } else {
  10. $datestart = date('Y-m-d 00:00:00', strtotime($datestart));
  11. }
  12. if (empty($dateend) || !strtotime($dateend)) {
  13. $dateend = date('Y-m-d H:i:s');
  14. } else {
  15. $dateend = date('Y-m-d 23:59:59', strtotime($dateend));
  16. }
  17. ?>
  18. <!DOCTYPE html>
  19. <html xmlns="http://www.w3.org/1999/xhtml">
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  22. <title>管理区域</title>
  23. <link rel="stylesheet" href="css/common.css" type="text/css" />
  24. <link rel="stylesheet" href="css/bootstrap-datepicker3.min.css" type="text/css" />
  25. <script src="js/jquery-1.7.2.min.js"></script>
  26. <script src="js/js.js"></script>
  27. <script src="js/bootstrap-datepicker.min.js"></script>
  28. <script src="js/bootstrap-datepicker.zh-CN.min.js"></script>
  29. <script>
  30. $(function(){
  31. $('#sandbox-container .input-daterange').datepicker({
  32. maxViewMode: 2,
  33. language: "zh-CN"
  34. });
  35. });
  36. </script>
  37. </head>
  38. <body class="clear">
  39. <?php require_once 'panel.php'; ?>
  40. <div id="man_zone">
  41. <div class="dashboard">
  42. <h1 class="dashboardHead">各组数据</h1>
  43. <form method="post" action="team.php">
  44. <div class="sandbox-containe" id="sandbox-container">
  45. <div class="input-daterange input-group" id="datepicker">
  46. <span class="input-group-addon">日期筛选</span>
  47. <input type="text" class="input-sm form-control" autocomplete="off" value="<?= $datestart ?>" name="start">
  48. <span class="input-group-addon">至</span>
  49. <input type="text" class="input-sm form-control" autocomplete="off" value="<?= $dateend ?>" name="end">
  50. </div>
  51. <input type="submit" class="submit" value="筛选">
  52. </div>
  53. </form>
  54. <table class="teamStatistics" border="1px" bordercollapse="collapse" cellspacing="0" cellpadding="5" bordercolor="#DDD">
  55. <tr>
  56. <td>组长</td>
  57. <td>组员</td>
  58. <td>总客户数量</td>
  59. <td width="25%">本月成交</td>
  60. <td>进公海客户总数</td>
  61. <td>公海认领</td>
  62. </tr>
  63. <?php
  64. $result = $conn->query("SELECT id, em_user FROM employee WHERE em_role=0 AND id<>13");
  65. while ($row = $result->fetch_assoc()) {
  66. $clstr = "";
  67. // Get total customer count
  68. $c1Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c1 FROM customer WHERE cs_belong=" . $row['id']);
  69. $c1Row = $c1Result->fetch_assoc();
  70. $c1 = $c1Row['c1'];
  71. // Get customers going to public sea
  72. $c2Result = $conn->query("SELECT COUNT(id) as c2 FROM customer
  73. WHERE cs_deal<>3 AND cs_deal<>0 AND cs_type<>2
  74. AND DATEDIFF(NOW(), cs_updatetime) > 90
  75. AND cs_belongclient=0 AND cs_belong=" . $row['id']);
  76. $c2Row = $c2Result->fetch_assoc();
  77. $c2 = $c2Row['c2'];
  78. // Get deals in date range
  79. $c3Result = $conn->query("SELECT DISTINCT cs_code FROM customer
  80. WHERE cs_dealdate > '" . $conn->real_escape_string($datestart) . "'
  81. AND cs_dealdate <= '" . $conn->real_escape_string($dateend) . "'
  82. AND cs_deal=3 AND cs_belong=" . $row['id']);
  83. $c3 = $c3Result->num_rows;
  84. while ($c3Row = $c3Result->fetch_assoc()) {
  85. $clstr .= $c3Row['cs_code'] . "<br>";
  86. }
  87. // Get claimed customers count
  88. $c4Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c4 FROM customer
  89. WHERE cs_claimdate > '" . $conn->real_escape_string($datestart) . "'
  90. AND cs_claimdate <= '" . $conn->real_escape_string($dateend) . "'
  91. AND cs_belong=" . $row['id']);
  92. $c4Row = $c4Result->fetch_assoc();
  93. $c4 = $c4Row['c4'];
  94. // Get team member count
  95. $c5Result = $conn->query("SELECT COUNT(id) as c5 FROM employee WHERE em_role=" . $row['id']);
  96. $c5Row = $c5Result->fetch_assoc();
  97. $c5 = $c5Row['c5'];
  98. ?>
  99. <tr>
  100. <td rowspan="<?= 1 + $c5 ?>"><?= htmlspecialchars($row['em_user']) ?></td>
  101. <td><?= htmlspecialchars($row['em_user']) ?></td>
  102. <td><?= $c1 ?></td>
  103. <td><?= $clstr ?></td>
  104. <td><?= $c2 ?></td>
  105. <td><?= $c4 ?></td>
  106. </tr>
  107. <?php
  108. // Get team members data
  109. $memberResult = $conn->query("SELECT id, em_user FROM employee WHERE em_role=" . $row['id']);
  110. while ($memberRow = $memberResult->fetch_assoc()) {
  111. $clstr = "";
  112. // Get member's total customer count
  113. $mc1Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c1 FROM customer WHERE cs_belong=" . $memberRow['id']);
  114. $mc1Row = $mc1Result->fetch_assoc();
  115. $mc1 = $mc1Row['c1'];
  116. // Get member's customers going to public sea
  117. $mc2Result = $conn->query("SELECT COUNT(DISTINCT cs_code) as c2 FROM customer
  118. WHERE cs_deal<>3 AND cs_deal<>0 AND cs_type<>2
  119. AND DATEDIFF(NOW(), cs_updatetime) > 90
  120. AND cs_belongclient=0 AND cs_belong=" . $memberRow['id']);
  121. $mc2Row = $mc2Result->fetch_assoc();
  122. $mc2 = $mc2Row['c2'];
  123. // Get member's deals in date range
  124. $mc3Result = $conn->query("SELECT DISTINCT cs_code FROM customer
  125. WHERE cs_dealdate > '" . $conn->real_escape_string($datestart) . "'
  126. AND cs_dealdate <= '" . $conn->real_escape_string($dateend) . "'
  127. AND cs_deal=3 AND cs_belong=" . $memberRow['id']);
  128. $mc3 = $mc3Result->num_rows;
  129. while ($mc3Row = $mc3Result->fetch_assoc()) {
  130. $clstr .= $mc3Row['cs_code'] . "<br>";
  131. }
  132. // Get member's claimed customers count
  133. $mc4Result = $conn->query("SELECT COUNT(id) as c4 FROM customer
  134. WHERE cs_claimdate > '" . $conn->real_escape_string($datestart) . "'
  135. AND cs_claimdate <= '" . $conn->real_escape_string($dateend) . "'
  136. AND cs_belong=" . $memberRow['id']);
  137. $mc4Row = $mc4Result->fetch_assoc();
  138. $mc4 = $mc4Row['c4'];
  139. ?>
  140. <tr>
  141. <td><?= htmlspecialchars($memberRow['em_user']) ?></td>
  142. <td><?= $mc1 ?></td>
  143. <td><?= $clstr ?></td>
  144. <td><?= $mc2 ?></td>
  145. <td><?= $mc4 ?></td>
  146. </tr>
  147. <?php
  148. }
  149. }
  150. ?>
  151. </table>
  152. </div>
  153. </div>
  154. </body>
  155. </html>