dashboard.php 11 KB

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