team.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. <style>
  38. body {
  39. margin: 0;
  40. padding: 20px;
  41. background: #fff;
  42. }
  43. #man_zone {
  44. margin-left: 0;
  45. }
  46. </style>
  47. </head>
  48. <body class="clear">
  49. <?php // require_once 'panel.php'; ?>
  50. <div id="man_zone">
  51. <div class="dashboard">
  52. <h1 class="dashboardHead">各组数据</h1>
  53. <form method="post" action="team.php">
  54. <div class="sandbox-containe" id="sandbox-container">
  55. <div class="input-daterange input-group" id="datepicker">
  56. <span class="input-group-addon">日期筛选</span>
  57. <input type="text" class="input-sm form-control" autocomplete="off" value="<?= $datestart ?>" name="start">
  58. <span class="input-group-addon">至</span>
  59. <input type="text" class="input-sm form-control" autocomplete="off" value="<?= $dateend ?>" name="end">
  60. </div>
  61. <input type="submit" class="submit" value="筛选">
  62. </div>
  63. </form>
  64. <table class="teamStatistics" border="1px" bordercollapse="collapse" cellspacing="0" cellpadding="5" bordercolor="#DDD">
  65. <tr>
  66. <td>组长</td>
  67. <td>组员</td>
  68. <td>总客户数量</td>
  69. <td width="25%">本月成交</td>
  70. <td>进公海客户总数</td>
  71. <td>公海认领</td>
  72. </tr>
  73. <?php
  74. $result = $conn->query("SELECT id, em_user FROM employee WHERE em_role=0 AND id<>13");
  75. while ($row = $result->fetch_assoc()) {
  76. $clstr = "";
  77. // Get total customer count
  78. $c1Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c1 FROM customer c WHERE c.cs_belong=" . $row['id']);
  79. $c1Row = $c1Result->fetch_assoc();
  80. $c1 = $c1Row['c1'];
  81. // Get customers going to public sea
  82. $c2Result = $conn->query("SELECT COUNT(c.id) as c2 FROM customer c
  83. WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2
  84. AND DATEDIFF(NOW(), c.cs_updatetime) > 90
  85. AND c.cs_belongclient=0 AND c.cs_belong=" . $row['id']);
  86. $c2Row = $c2Result->fetch_assoc();
  87. $c2 = $c2Row['c2'];
  88. // Get deals in date range
  89. $c3Result = $conn->query("SELECT DISTINCT c.cs_code FROM customer c
  90. WHERE c.cs_dealdate > '" . $conn->real_escape_string($datestart) . "'
  91. AND c.cs_dealdate <= '" . $conn->real_escape_string($dateend) . "'
  92. AND c.cs_deal=3 AND c.cs_belong=" . $row['id']);
  93. $c3 = $c3Result->num_rows;
  94. while ($c3Row = $c3Result->fetch_assoc()) {
  95. $clstr .= $c3Row['cs_code'] . "<br>";
  96. }
  97. // Get claimed customers count
  98. $c4Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c4 FROM customer c
  99. WHERE c.cs_claimdate > '" . $conn->real_escape_string($datestart) . "'
  100. AND c.cs_claimdate <= '" . $conn->real_escape_string($dateend) . "'
  101. AND c.cs_belong=" . $row['id']);
  102. $c4Row = $c4Result->fetch_assoc();
  103. $c4 = $c4Row['c4'];
  104. // Get team member count
  105. $c5Result = $conn->query("SELECT COUNT(id) as c5 FROM employee WHERE em_role=" . $row['id']);
  106. $c5Row = $c5Result->fetch_assoc();
  107. $c5 = $c5Row['c5'];
  108. ?>
  109. <tr>
  110. <td rowspan="<?= 1 + $c5 ?>"><?= htmlspecialcharsFix($row['em_user']) ?></td>
  111. <td><?= htmlspecialcharsFix($row['em_user']) ?></td>
  112. <td><?= $c1 ?></td>
  113. <td><?= $clstr ?></td>
  114. <td><?= $c2 ?></td>
  115. <td><?= $c4 ?></td>
  116. </tr>
  117. <?php
  118. // Get team members data
  119. $memberResult = $conn->query("SELECT id, em_user FROM employee WHERE em_role=" . $row['id']);
  120. while ($memberRow = $memberResult->fetch_assoc()) {
  121. $clstr = "";
  122. // Get member's total customer count
  123. $mc1Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c1 FROM customer c WHERE c.cs_belong=" . $memberRow['id']);
  124. $mc1Row = $mc1Result->fetch_assoc();
  125. $mc1 = $mc1Row['c1'];
  126. // Get member's customers going to public sea
  127. $mc2Result = $conn->query("SELECT COUNT(DISTINCT c.cs_code) as c2 FROM customer c
  128. WHERE c.cs_deal<>3 AND c.cs_deal<>0 AND c.cs_type<>2
  129. AND DATEDIFF(NOW(), c.cs_updatetime) > 90
  130. AND c.cs_belongclient=0 AND c.cs_belong=" . $memberRow['id']);
  131. $mc2Row = $mc2Result->fetch_assoc();
  132. $mc2 = $mc2Row['c2'];
  133. // Get member's deals in date range
  134. $mc3Result = $conn->query("SELECT DISTINCT c.cs_code FROM customer c
  135. WHERE c.cs_dealdate > '" . $conn->real_escape_string($datestart) . "'
  136. AND c.cs_dealdate <= '" . $conn->real_escape_string($dateend) . "'
  137. AND c.cs_deal=3 AND c.cs_belong=" . $memberRow['id']);
  138. $mc3 = $mc3Result->num_rows;
  139. while ($mc3Row = $mc3Result->fetch_assoc()) {
  140. $clstr .= $mc3Row['cs_code'] . "<br>";
  141. }
  142. // Get member's claimed customers count
  143. $mc4Result = $conn->query("SELECT COUNT(c.id) as c4 FROM customer c
  144. WHERE c.cs_claimdate > '" . $conn->real_escape_string($datestart) . "'
  145. AND c.cs_claimdate <= '" . $conn->real_escape_string($dateend) . "'
  146. AND c.cs_belong=" . $memberRow['id']);
  147. $mc4Row = $mc4Result->fetch_assoc();
  148. $mc4 = $mc4Row['c4'];
  149. ?>
  150. <tr>
  151. <td><?= htmlspecialcharsFix($memberRow['em_user']) ?></td>
  152. <td><?= $mc1 ?></td>
  153. <td><?= $clstr ?></td>
  154. <td><?= $mc2 ?></td>
  155. <td><?= $mc4 ?></td>
  156. </tr>
  157. <?php
  158. }
  159. }
  160. ?>
  161. </table>
  162. </div>
  163. </div>
  164. </body>
  165. </html>