dashboard.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. <style>
  73. body {
  74. margin: 0;
  75. padding: 20px;
  76. background: #fff;
  77. }
  78. #man_zone {
  79. margin-left: 0;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <div id="man_zone">
  85. <div class="dashboard">
  86. <h1 class="dashboardHead">数据看板</h1>
  87. <?php
  88. // 获取客户总数
  89. $result = mysqli_query($conn, "SELECT COUNT(DISTINCT cs_code) as CustomerTotal FROM customer");
  90. $row = mysqli_fetch_assoc($result);
  91. $tn = $row['CustomerTotal'];
  92. // 获取成交客户数
  93. $result = mysqli_query($conn, "SELECT COUNT(DISTINCT cs_code) as CustomerTotal FROM customer WHERE cs_deal=3");
  94. $row = mysqli_fetch_assoc($result);
  95. $tdn = $row['CustomerTotal'];
  96. // 获取客户类型数据
  97. $data_arr1 = [];
  98. $text_arr1 = [];
  99. $result = mysqli_query($conn, "SELECT businessType, COUNT(DISTINCT cs_code) as cc FROM customer
  100. LEFT JOIN clienttype ON customer.cs_type=clienttype.id
  101. GROUP BY businessType");
  102. while($row = mysqli_fetch_assoc($result)) {
  103. $data_arr1[] = number_format($row['cc']/$tn, 4);
  104. $text_arr1[] = $row['businessType'];
  105. }
  106. ?>
  107. <input type="hidden" id="data_arr1" value="<?= implode(',', $data_arr1) ?>">
  108. <input type="hidden" id="text_arr1" value="<?= implode(',', $text_arr1) ?>">
  109. <div class="dashPanel1">
  110. <h3>客户类型</h3>
  111. <canvas id="canvas_circle" width="720" height="360">浏览器不支持canvas</canvas>
  112. </div>
  113. <?php
  114. // 获取成交比例数据
  115. $data_arr2 = [];
  116. $result = mysqli_query($conn, "SELECT cs_deal, COUNT(DISTINCT cs_code) as cc
  117. FROM customer GROUP BY cs_deal ORDER BY cs_deal DESC");
  118. while($row = mysqli_fetch_assoc($result)) {
  119. $data_arr2[] = number_format($row['cc']/$tn, 4);
  120. }
  121. ?>
  122. <input type="hidden" id="data_arr2" value="<?= implode(',', $data_arr2) ?>">
  123. <input type="hidden" id="text_arr2" value="成交,明确需求,背景调查,无响应">
  124. <div class="dashPanel1">
  125. <h3>成交比例</h3>
  126. <canvas id="canvas_circle2" width="720" height="360">浏览器不支持canvas</canvas>
  127. </div>
  128. <?php
  129. // 获取客户来源数据
  130. $data_arr3 = [];
  131. $text_arr3 = [];
  132. $result = mysqli_query($conn, "SELECT ch_name, COUNT(DISTINCT cs_code) as cc
  133. FROM customer LEFT JOIN qudao ON customer.cs_from=qudao.id
  134. GROUP BY ch_name");
  135. while($row = mysqli_fetch_assoc($result)) {
  136. $data_arr3[] = number_format($row['cc']/$tn, 4);
  137. $text_arr3[] = $row['ch_name'];
  138. }
  139. ?>
  140. <input type="hidden" id="data_arr3" value="<?= implode(',', $data_arr3) ?>">
  141. <input type="hidden" id="text_arr3" value="<?= implode(',', $text_arr3) ?>">
  142. <div class="dashPanel1">
  143. <h3>客户来源</h3>
  144. <canvas id="canvas_circle3" width="720" height="360">浏览器不支持canvas</canvas>
  145. </div>
  146. <?php
  147. // 获取已成交客户分布(Top10)数据
  148. $data_arr5 = [];
  149. $text_arr5 = [];
  150. $tp = 1;
  151. $result = mysqli_query($conn, "SELECT countryName, COUNT(DISTINCT cs_code) as cc
  152. FROM customer LEFT JOIN country ON customer.cs_country=country.id
  153. WHERE cs_deal=3 GROUP BY countryName ORDER BY cc DESC LIMIT 9");
  154. while($row = mysqli_fetch_assoc($result)) {
  155. $value = number_format($row['cc']/$tdn, 4);
  156. $data_arr5[] = $value;
  157. $text_arr5[] = $row['countryName'];
  158. $tp -= $value;
  159. }
  160. $data_arr5[] = $tp;
  161. $text_arr5[] = "其他";
  162. ?>
  163. <input type="hidden" id="data_arr5" value="<?= implode(',', $data_arr5) ?>">
  164. <input type="hidden" id="text_arr5" value="<?= implode(',', $text_arr5) ?>">
  165. <div class="dashPanel1">
  166. <h3>已成交客户分布(Top10)</h3>
  167. <canvas id="canvas_circle5" width="720" height="360">浏览器不支持canvas</canvas>
  168. </div>
  169. <?php
  170. // 获取客户分布(Top10)数据
  171. $data_arr4 = [];
  172. $text_arr4 = [];
  173. $tp = 1;
  174. $result = mysqli_query($conn, "SELECT countryName, COUNT(DISTINCT cs_code) as cc
  175. FROM customer LEFT JOIN country ON customer.cs_country=country.id
  176. WHERE cs_deal=3 GROUP BY countryName ORDER BY cc DESC LIMIT 9");
  177. while($row = mysqli_fetch_assoc($result)) {
  178. $value = number_format($row['cc']/$tn, 4);
  179. $data_arr4[] = $value;
  180. $text_arr4[] = $row['countryName'];
  181. $tp -= $value;
  182. }
  183. $data_arr4[] = $tp;
  184. $text_arr4[] = "其他";
  185. ?>
  186. <input type="hidden" id="data_arr4" value="<?= implode(',', $data_arr4) ?>">
  187. <input type="hidden" id="text_arr4" value="<?= implode(',', $text_arr4) ?>">
  188. <div class="dashPanel1">
  189. <h3>客户分布(Top10)</h3>
  190. <canvas id="canvas_circle4" width="720" height="360">浏览器不支持canvas</canvas>
  191. </div>
  192. <?php
  193. // 获取各业务成交客户占比数据
  194. $data_arr6 = [];
  195. $text_arr6 = [];
  196. $result = mysqli_query($conn, "SELECT em_user, COUNT(DISTINCT cs_code) as cc
  197. FROM customer LEFT JOIN employee ON customer.cs_belong=employee.id
  198. WHERE cs_deal=3 GROUP BY em_user ORDER BY cc DESC");
  199. while($row = mysqli_fetch_assoc($result)) {
  200. $data_arr6[] = number_format($row['cc']/$tdn, 4);
  201. $text_arr6[] = $row['em_user'];
  202. }
  203. ?>
  204. <input type="hidden" id="data_arr6" value="<?= implode(',', $data_arr6) ?>">
  205. <input type="hidden" id="text_arr6" value="<?= implode(',', $text_arr6) ?>">
  206. <div class="dashPanel1">
  207. <h3>各业务成交客户占比</h3>
  208. <canvas id="canvas_circle6" width="720" height="360">浏览器不支持canvas</canvas>
  209. </div>
  210. <?php
  211. // 获取各业务客户占比数据
  212. $data_arr7 = [];
  213. $text_arr7 = [];
  214. $result = mysqli_query($conn, "SELECT em_user, COUNT(DISTINCT cs_code) as cc
  215. FROM customer LEFT JOIN employee ON customer.cs_belong=employee.id
  216. WHERE cs_deal>0 GROUP BY em_user ORDER BY cc DESC");
  217. while($row = mysqli_fetch_assoc($result)) {
  218. $data_arr7[] = $row['cc'];
  219. $text_arr7[] = $row['em_user'];
  220. }
  221. ?>
  222. <input type="hidden" id="data_arr7" value="<?= implode(',', $data_arr7) ?>">
  223. <input type="hidden" id="text_arr7" value="<?= implode(',', $text_arr7) ?>">
  224. <div class="dashPanel2">
  225. <h3>各业务客户占比(扣除无响应)</h3>
  226. <canvas id="canvas_circle7" width="1200" height="500">浏览器不支持canvas</canvas>
  227. </div>
  228. </div>
  229. <script>
  230. function init() {
  231. //客户类型
  232. var data_arr = $("#data_arr1").val().split(",");
  233. var color_arr = ["#00FF21", "#FFAA00", "#00AABB", "#FF4400","#009942","#02a0e9","#0168b7","#930784","#e5007f","#e50150","#ef0030","#eb6100","#f49600"];
  234. var text_arr = $("#text_arr1").val().split(",");
  235. //成交情况
  236. var data_arr2 = $("#data_arr2").val().split(",");
  237. var text_arr2 = $("#text_arr2").val().split(",");
  238. var data_arr3 = $("#data_arr3").val().split(",");
  239. var text_arr3 = $("#text_arr3").val().split(",");
  240. var data_arr4 = $("#data_arr4").val().split(",");
  241. var text_arr4 = $("#text_arr4").val().split(",");
  242. var data_arr5 = $("#data_arr5").val().split(",");
  243. var text_arr5 = $("#text_arr5").val().split(",");
  244. var data_arr6 = $("#data_arr6").val().split(",");
  245. var text_arr6 = $("#text_arr6").val().split(",");
  246. var data_arr7 = $("#data_arr7").val().split(",");
  247. var text_arr7 = $("#text_arr7").val().split(",");
  248. drawCircle("canvas_circle", data_arr, color_arr, text_arr);
  249. drawCircle("canvas_circle2", data_arr2, color_arr, text_arr2);
  250. drawCircle("canvas_circle3", data_arr3, color_arr, text_arr3);
  251. drawCircle("canvas_circle4", data_arr4, color_arr, text_arr4);
  252. drawCircle("canvas_circle5", data_arr5, color_arr, text_arr5);
  253. drawCircle("canvas_circle6", data_arr6, color_arr, text_arr6);
  254. drawRectangle("canvas_circle7", data_arr7, text_arr7);
  255. }
  256. window.onload = init;
  257. </script>
  258. </div>
  259. </body>
  260. </html>
  261. <?php mysqli_close($conn); ?>