dashboard.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. require_once("conn.php");
  3. checkLogin("信息管理");
  4. ?>
  5. <!DOCTYPE html>
  6. <html>
  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. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  12. <script src="js/jquery-1.7.2.min.js"></script>
  13. <script src="js/js.js"></script>
  14. <script>
  15. //绘制饼图
  16. function drawCircle(canvasId, data_arr, color_arr, text_arr) {
  17. var c = document.getElementById(canvasId);
  18. var ctx = c.getContext("2d");
  19. var ctxw = c.getContext("2d");
  20. var radius = 140; //半径
  21. var ox = radius + 20, oy = radius + 20; //圆心
  22. var width = 10, height = 10; //图例宽和高
  23. var posX = 500, posY = 50; //
  24. var textX = posX + width + 5, textY = posY + 10;
  25. var startAngle = 0; //起始弧度
  26. var endAngle = 0; //结束弧度
  27. for (var i = 0; i < data_arr.length; i++) {
  28. //绘制饼图
  29. endAngle = endAngle + data_arr[i] * Math.PI * 2; //结束弧度
  30. ctx.fillStyle = color_arr[i];
  31. ctx.beginPath();
  32. ctx.moveTo(ox, oy); //移动到到圆心
  33. ctx.arc(ox, oy, radius, startAngle, endAngle, false);
  34. ctx.closePath();
  35. ctx.fill();
  36. startAngle = endAngle; //设置起始弧度
  37. //绘制比例图及文字
  38. ctx.fillStyle = color_arr[i];
  39. ctx.fillRect(posX, posY + 20 * i, width, height);
  40. ctx.moveTo(posX, posY + 20 * i);
  41. ctx.font = 'bold 12px 微软雅黑'; //斜体 30像素 微软雅黑字体
  42. ctx.fillStyle = "#666666";
  43. var icount = 100 * data_arr[i];
  44. var percent = text_arr[i] + ":" + icount.toFixed(2) + "%";
  45. ctx.fillText(percent, textX, textY + 20 * i);
  46. }
  47. ctxw.fillStyle = "#FFFFFF";
  48. ctxw.beginPath();
  49. ctxw.moveTo(ox, oy); //移动到到圆心
  50. ctxw.arc(ox, oy, 90, 0, 2* Math.PI, false);
  51. ctxw.closePath();
  52. ctxw.fill();
  53. }
  54. function drawRectangle(canvasId, data_arr, text_arr) {
  55. var c = document.getElementById(canvasId);
  56. var ctx = c.getContext("2d");
  57. var space = 20; //间距
  58. var x = 0, y = 420;
  59. for (var i = 0; i < data_arr.length; i++) {
  60. x = x + 30 + space;
  61. ctx.beginPath();
  62. ctx.fillStyle = "#00aabb";
  63. ctx.rect(x, 420-data_arr[i]*0.2, 30, data_arr[i]*0.2);
  64. ctx.closePath();
  65. ctx.fill();
  66. ctx.font = 'bold 10px 微软雅黑'; //斜体 30像素 微软雅黑字体
  67. ctx.fillStyle = "#666666";
  68. ctx.fillText(text_arr[i]+"("+data_arr[i]+")", x+5, 410-data_arr[i]*0.2);
  69. }
  70. }
  71. </script>
  72. </head>
  73. <body>
  74. <div id="man_zone">
  75. <div class="dashboard">
  76. <h1 class="dashboardHead">数据看板</h1>
  77. <?php
  78. // 获取客户总数
  79. $result = mysqli_query($conn, "SELECT COUNT(DISTINCT cs_code) as CustomerTotal FROM customer");
  80. $row = mysqli_fetch_assoc($result);
  81. $tn = $row['CustomerTotal'];
  82. // 获取成交客户数
  83. $result = mysqli_query($conn, "SELECT COUNT(DISTINCT cs_code) as CustomerTotal FROM customer WHERE cs_deal=3");
  84. $row = mysqli_fetch_assoc($result);
  85. $tdn = $row['CustomerTotal'];
  86. // 获取客户类型数据
  87. $data_arr1 = [];
  88. $text_arr1 = [];
  89. $result = mysqli_query($conn, "SELECT businessType, COUNT(DISTINCT cs_code) as cc FROM customer
  90. LEFT JOIN clientType ON customer.cs_type=clientType.id
  91. GROUP BY businessType");
  92. while($row = mysqli_fetch_assoc($result)) {
  93. $data_arr1[] = number_format($row['cc']/$tn, 4);
  94. $text_arr1[] = $row['businessType'];
  95. }
  96. ?>
  97. <input type="hidden" id="data_arr1" value="<?= implode(',', $data_arr1) ?>">
  98. <input type="hidden" id="text_arr1" value="<?= implode(',', $text_arr1) ?>">
  99. <div class="dashPanel1">
  100. <h3>客户类型</h3>
  101. <canvas id="canvas_circle" width="720" height="360">浏览器不支持canvas</canvas>
  102. </div>
  103. <?php
  104. // 获取成交比例数据
  105. $data_arr2 = [];
  106. $result = mysqli_query($conn, "SELECT cs_deal, COUNT(DISTINCT cs_code) as cc
  107. FROM customer GROUP BY cs_deal ORDER BY cs_deal DESC");
  108. while($row = mysqli_fetch_assoc($result)) {
  109. $data_arr2[] = number_format($row['cc']/$tn, 4);
  110. }
  111. ?>
  112. <input type="hidden" id="data_arr2" value="<?= implode(',', $data_arr2) ?>">
  113. <input type="hidden" id="text_arr2" value="成交,明确需求,背景调查,无响应">
  114. <div class="dashPanel1">
  115. <h3>成交比例</h3>
  116. <canvas id="canvas_circle2" width="720" height="360">浏览器不支持canvas</canvas>
  117. </div>
  118. <?php
  119. // 获取客户来源数据
  120. $data_arr3 = [];
  121. $text_arr3 = [];
  122. $result = mysqli_query($conn, "SELECT ch_name, COUNT(DISTINCT cs_code) as cc
  123. FROM customer LEFT JOIN qudao ON customer.cs_from=qudao.id
  124. GROUP BY ch_name");
  125. while($row = mysqli_fetch_assoc($result)) {
  126. $data_arr3[] = number_format($row['cc']/$tn, 4);
  127. $text_arr3[] = $row['ch_name'];
  128. }
  129. ?>
  130. <input type="hidden" id="data_arr3" value="<?= implode(',', $data_arr3) ?>">
  131. <input type="hidden" id="text_arr3" value="<?= implode(',', $text_arr3) ?>">
  132. <div class="dashPanel1">
  133. <h3>客户来源</h3>
  134. <canvas id="canvas_circle3" width="720" height="360">浏览器不支持canvas</canvas>
  135. </div>
  136. <?php
  137. // 获取已成交客户分布(Top10)数据
  138. $data_arr5 = [];
  139. $text_arr5 = [];
  140. $tp = 1;
  141. $result = mysqli_query($conn, "SELECT countryName, COUNT(DISTINCT cs_code) as cc
  142. FROM customer LEFT JOIN country ON customer.cs_country=country.id
  143. WHERE cs_deal=3 GROUP BY countryName ORDER BY cc DESC LIMIT 9");
  144. while($row = mysqli_fetch_assoc($result)) {
  145. $value = number_format($row['cc']/$tdn, 4);
  146. $data_arr5[] = $value;
  147. $text_arr5[] = $row['countryName'];
  148. $tp -= $value;
  149. }
  150. $data_arr5[] = $tp;
  151. $text_arr5[] = "其他";
  152. ?>
  153. <input type="hidden" id="data_arr5" value="<?= implode(',', $data_arr5) ?>">
  154. <input type="hidden" id="text_arr5" value="<?= implode(',', $text_arr5) ?>">
  155. <div class="dashPanel1">
  156. <h3>已成交客户分布(Top10)</h3>
  157. <canvas id="canvas_circle5" width="720" height="360">浏览器不支持canvas</canvas>
  158. </div>
  159. <?php
  160. // 获取客户分布(Top10)数据
  161. $data_arr4 = [];
  162. $text_arr4 = [];
  163. $tp = 1;
  164. $result = mysqli_query($conn, "SELECT countryName, COUNT(DISTINCT cs_code) as cc
  165. FROM customer LEFT JOIN country ON customer.cs_country=country.id
  166. WHERE cs_deal=3 GROUP BY countryName ORDER BY cc DESC LIMIT 9");
  167. while($row = mysqli_fetch_assoc($result)) {
  168. $value = number_format($row['cc']/$tn, 4);
  169. $data_arr4[] = $value;
  170. $text_arr4[] = $row['countryName'];
  171. $tp -= $value;
  172. }
  173. $data_arr4[] = $tp;
  174. $text_arr4[] = "其他";
  175. ?>
  176. <input type="hidden" id="data_arr4" value="<?= implode(',', $data_arr4) ?>">
  177. <input type="hidden" id="text_arr4" value="<?= implode(',', $text_arr4) ?>">
  178. <div class="dashPanel1">
  179. <h3>客户分布(Top10)</h3>
  180. <canvas id="canvas_circle4" width="720" height="360">浏览器不支持canvas</canvas>
  181. </div>
  182. <?php
  183. // 获取各业务成交客户占比数据
  184. $data_arr6 = [];
  185. $text_arr6 = [];
  186. $result = mysqli_query($conn, "SELECT em_user, COUNT(DISTINCT cs_code) as cc
  187. FROM customer LEFT JOIN employee ON customer.cs_belong=employee.id
  188. WHERE cs_deal=3 GROUP BY em_user ORDER BY cc DESC");
  189. while($row = mysqli_fetch_assoc($result)) {
  190. $data_arr6[] = number_format($row['cc']/$tdn, 4);
  191. $text_arr6[] = $row['em_user'];
  192. }
  193. ?>
  194. <input type="hidden" id="data_arr6" value="<?= implode(',', $data_arr6) ?>">
  195. <input type="hidden" id="text_arr6" value="<?= implode(',', $text_arr6) ?>">
  196. <div class="dashPanel1">
  197. <h3>各业务成交客户占比</h3>
  198. <canvas id="canvas_circle6" width="720" height="360">浏览器不支持canvas</canvas>
  199. </div>
  200. <?php
  201. // 获取各业务客户占比数据
  202. $data_arr7 = [];
  203. $text_arr7 = [];
  204. $result = mysqli_query($conn, "SELECT em_user, COUNT(DISTINCT cs_code) as cc
  205. FROM customer LEFT JOIN employee ON customer.cs_belong=employee.id
  206. WHERE cs_deal>0 GROUP BY em_user ORDER BY cc DESC");
  207. while($row = mysqli_fetch_assoc($result)) {
  208. $data_arr7[] = $row['cc'];
  209. $text_arr7[] = $row['em_user'];
  210. }
  211. ?>
  212. <input type="hidden" id="data_arr7" value="<?= implode(',', $data_arr7) ?>">
  213. <input type="hidden" id="text_arr7" value="<?= implode(',', $text_arr7) ?>">
  214. <div class="dashPanel2">
  215. <h3>各业务客户占比(扣除无响应)</h3>
  216. <canvas id="canvas_circle7" width="1200" height="500">浏览器不支持canvas</canvas>
  217. </div>
  218. </div>
  219. <script>
  220. function init() {
  221. //客户类型
  222. var data_arr = $("#data_arr1").val().split(",");
  223. var color_arr = ["#00FF21", "#FFAA00", "#00AABB", "#FF4400","#009942","#02a0e9","#0168b7","#930784","#e5007f","#e50150","#ef0030","#eb6100","#f49600"];
  224. var text_arr = $("#text_arr1").val().split(",");
  225. //成交情况
  226. var data_arr2 = $("#data_arr2").val().split(",");
  227. var text_arr2 = $("#text_arr2").val().split(",");
  228. var data_arr3 = $("#data_arr3").val().split(",");
  229. var text_arr3 = $("#text_arr3").val().split(",");
  230. var data_arr4 = $("#data_arr4").val().split(",");
  231. var text_arr4 = $("#text_arr4").val().split(",");
  232. var data_arr5 = $("#data_arr5").val().split(",");
  233. var text_arr5 = $("#text_arr5").val().split(",");
  234. var data_arr6 = $("#data_arr6").val().split(",");
  235. var text_arr6 = $("#text_arr6").val().split(",");
  236. var data_arr7 = $("#data_arr7").val().split(",");
  237. var text_arr7 = $("#text_arr7").val().split(",");
  238. drawCircle("canvas_circle", data_arr, color_arr, text_arr);
  239. drawCircle("canvas_circle2", data_arr2, color_arr, text_arr2);
  240. drawCircle("canvas_circle3", data_arr3, color_arr, text_arr3);
  241. drawCircle("canvas_circle4", data_arr4, color_arr, text_arr4);
  242. drawCircle("canvas_circle5", data_arr5, color_arr, text_arr5);
  243. drawCircle("canvas_circle6", data_arr6, color_arr, text_arr6);
  244. drawRectangle("canvas_circle7", data_arr7, text_arr7);
  245. }
  246. window.onload = init;
  247. </script>
  248. </div>
  249. </body>
  250. </html>
  251. <?php mysqli_close($conn); ?>