index.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. session_start();
  3. if (isset($_SESSION["username"])) {
  4. ?>
  5. <?php
  6. header("Content-type:text/html;charset=UTF-8");
  7. include_once("../../untils/conn.php");
  8. mysqli_query($con, "set names utf8");
  9. if ($con) {
  10. if ($db) {
  11. //获取数据总行数
  12. $sortsql = "select count(*) from oder";
  13. $sortdata = mysqli_query($con, $sortsql);
  14. $sortresult = mysqli_fetch_row($sortdata);
  15. $listsql = "select count(*) from list";
  16. $listdata = mysqli_query($con, $listsql);
  17. $listresult = mysqli_fetch_row($listdata);
  18. $sql = "select * from list limit 0,8";
  19. $data = mysqli_query($con, $sql);
  20. $channelsql = "select count(*) from channel";
  21. $channeltdata = mysqli_query($con, $channelsql);
  22. $channelresult = mysqli_fetch_row($channeltdata);
  23. $totalPrice = "SELECT SUM(price) AS total FROM oder WHERE card_sta = 1";
  24. $totalData = mysqli_query($con, $totalPrice);
  25. $totalResult = mysqli_fetch_assoc($totalData);
  26. $sum = $totalResult['total'];
  27. //查询代理总数
  28. $proxySql = "SELECT COUNT(*) FROM proxy";
  29. $proxyData = mysqli_query($con, $proxySql);
  30. $proxyResult = mysqli_fetch_row($proxyData);
  31. $proxyCount = $proxyResult[0];
  32. // 获取当前月份的时间戳范围
  33. $currentMonthStart = strtotime(date('Y-m-01 00:00:00'));
  34. $currentMonthEnd = strtotime(date('Y-m-t 23:59:59'));
  35. // 查询当前月份新增代理数量
  36. $newProxySql = "SELECT COUNT(*) FROM proxy WHERE cr_time BETWEEN '$currentMonthStart' AND '$currentMonthEnd'";
  37. $newProxyData = mysqli_query($con, $newProxySql);
  38. $newProxyResult = mysqli_fetch_row($newProxyData);
  39. $newProxyCount = $newProxyResult[0];
  40. //查询所有uid即作为用户
  41. $sql = "SELECT COUNT(DISTINCT uid) AS unique_uid_count FROM oder";
  42. $data = mysqli_query($con, $sql);
  43. $result = mysqli_fetch_assoc($data);
  44. $uniqueUidCount = $result['unique_uid_count'];
  45. // 计算新增的用户
  46. // 获取当前月份的时间戳范围
  47. $startTime = strtotime(date('Y-m-01'));
  48. $endTime = strtotime(date('Y-m-01', strtotime('+1 month')));
  49. // 查询本月新增的数据数量
  50. $sql = "SELECT COUNT(DISTINCT uid) AS unique_uid_count FROM oder WHERE time >= $startTime AND time < $endTime";
  51. $data = mysqli_query($con, $sql);
  52. $result = mysqli_fetch_assoc($data);
  53. $uniqueUidCountThisMonth = $result['unique_uid_count'];
  54. $type = "web_config";
  55. $menu_name = '运营平台'; // 设置默认菜单名
  56. $sql = "SELECT * FROM foundation WHERE type='$type'";
  57. $data = mysqli_query($con, $sql);
  58. $result = mysqli_fetch_assoc($data);
  59. $site_name = $result['site_name'];
  60. }
  61. }
  62. ?>
  63. <!DOCTYPE html>
  64. <html lang="en">
  65. <head>
  66. <meta charset="UTF-8">
  67. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  68. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  69. <title><?php echo $site_name ?> - 可视化大数据监控大屏</title>
  70. <link rel="stylesheet" href="./css/index.css">
  71. <link rel="stylesheet" href="./fonts/icomoon.css">
  72. </head>
  73. <body>
  74. <div class="viewport">
  75. <div class="column">
  76. <!--概览-->
  77. <div class="overview panel">
  78. <div class="inner">
  79. <div class="item">
  80. <h4><?php echo $sum ?></h4>
  81. <span>
  82. <i class="icon-dot" style="color: #006cff"></i>
  83. 平台总金额
  84. </span>
  85. </div>
  86. <div class="item">
  87. <h4><?php echo $sortresult[0] ?></h4>
  88. <span>
  89. <i class="icon-dot" style="color: #6acca3"></i>
  90. 订单总数
  91. </span>
  92. </div>
  93. <div class="item">
  94. <h4><?php echo $listresult[0] ?></h4>
  95. <span>
  96. <i class="icon-dot" style="color: #6acca3"></i>
  97. 产品总数
  98. </span>
  99. </div>
  100. <div class="item">
  101. <h4><?php echo $proxyCount ?></h4>
  102. <span>
  103. <i class="icon-dot" style="color: #ed3f35"></i>
  104. 代理总数
  105. </span>
  106. </div>
  107. </div>
  108. </div>
  109. <!--监控-->
  110. <?php
  111. include_once("../../untils/conn.php");
  112. mysqli_query($con, "set names utf8");
  113. $sql = "SELECT time, sf, city, xian, dizhi, beizhu FROM oder WHERE status=4";
  114. $result = $con->query($sql); // 执行查询
  115. $rows = array(); // 存储每行数据的数组
  116. if ($result->num_rows > 0) {
  117. // 将每行数据存储到数组中
  118. while($row = $result->fetch_assoc()) {
  119. $rows[] = $row;
  120. }
  121. } else {
  122. // echo "未找到匹配数据";
  123. }
  124. ?>
  125. <div class="monitor panel">
  126. <div class="inner">
  127. <div class="tabs">
  128. <a href="javascript:;" data-index="0" class="active">开卡异常用户监控</a>
  129. <a>数据将在 <span id="countdown">10</span> 秒后自动刷新</a>
  130. </div>
  131. <div class="content" style="display: block;">
  132. <div class="head">
  133. <span class="col">异常时间</span>
  134. <span class="col">用户地址</span>
  135. <span class="col">异常原因</span>
  136. </div>
  137. <div class="marquee-view">
  138. <div class="marquee">
  139. <?php
  140. // 使用循环轮流输出每行数据
  141. for ($i=0; $i<count($rows); $i++) {
  142. $time = $rows[$i]["time"];
  143. $sf = $rows[$i]["sf"];
  144. $city = $rows[$i]["city"];
  145. $xian = $rows[$i]["xian"];
  146. $dizhi = $rows[$i]["dizhi"];
  147. $beizhu = $rows[$i]["beizhu"];
  148. $address = $sf . $city . $xian . $dizhi;
  149. $timestamp = $time;
  150. $date = date('Y-m-d', $timestamp);
  151. ?>
  152. <div class="row">
  153. <span class="col"><?php echo $date ?></span>
  154. <span class="col"><?php echo $address ?></span>
  155. <span class="col"><?php echo strlen($beizhu) > 30 ? substr($beizhu, 0, 30) . '...' : $beizhu ?></span>
  156. <span class="icon-dot"></span>
  157. </div>
  158. <?php
  159. }
  160. ?>
  161. </div>
  162. </div>
  163. </div>
  164. <!--<div class="content">-->
  165. <!-- <div class="head">-->
  166. <!-- <span class="col">异常时间</span>-->
  167. <!-- <span class="col">异常IP地址</span>-->
  168. <!-- <span class="col">异常原因</span>-->
  169. <!-- </div>-->
  170. <!-- <div class="marquee-view">-->
  171. <!-- <div class="marquee">-->
  172. <!-- <div class="row">-->
  173. <!-- <span class="col">20190701</span>-->
  174. <!-- <span class="col">北京市昌平区建材城西路金燕龙写字楼</span>-->
  175. <!-- <span class="col">1000001</span>-->
  176. <!-- <span class="icon-dot"></span>-->
  177. <!-- </div>-->
  178. <!-- </div>-->
  179. <!-- </div>-->
  180. <!--</div>-->
  181. </div>
  182. </div>
  183. <!--点位-->
  184. <div class="point panel">
  185. <div class="inner">
  186. <h3>代理地区分布统计</h3>
  187. <div class="chart">
  188. <div class="pie"></div>
  189. <div class="data">
  190. <div class="item">
  191. <h4><?php echo $proxyCount ?></h4>
  192. <span>
  193. <i class="icon-dot" style="color: #ed3f35"></i>
  194. 代理总数
  195. </span>
  196. </div>
  197. <div class="item">
  198. <h4><?php echo $newProxyCount ?></h4>
  199. <span>
  200. <i class="icon-dot" style="color: #eacf19"></i>
  201. 本月新增
  202. </span>
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. </div>
  209. <div class="column">
  210. <!-- 地图 -->
  211. <div class="map">
  212. <h3>
  213. <span class="icon-cube"></span>
  214. 用户分布数据统计
  215. </h3>
  216. <div class="chart">
  217. <div class="geo"></div>
  218. </div>
  219. </div>
  220. <!-- 用户 -->
  221. <?php
  222. include_once("../../untils/conn.php");
  223. mysqli_query($con, "set names utf8");
  224. $cities = array();
  225. $result = mysqli_query($con, "SELECT DISTINCT city FROM oder");
  226. while ($row = mysqli_fetch_assoc($result)) {
  227. array_push($cities, $row["city"]);
  228. }
  229. $orderCounts = array();
  230. $sql = "SELECT COUNT(*) as count FROM oder GROUP BY city";
  231. $result = mysqli_query($con, $sql);
  232. while ($row = mysqli_fetch_assoc($result)) {
  233. array_push($orderCounts, $row["count"]);
  234. }
  235. ?>
  236. <div class="users panel">
  237. <div class="inner">
  238. <h3>全国客户总量统计</h3>
  239. <div class="chart">
  240. <div class="bar"></div>
  241. <div class="data">
  242. <div class="item">
  243. <h4><?php echo $uniqueUidCount ?></h4>
  244. <span>
  245. <i class="icon-dot" style="color: #ed3f35"></i>
  246. 用户总量
  247. </span>
  248. </div>
  249. <div class="item">
  250. <h4><?php echo $uniqueUidCountThisMonth ?></h4>
  251. <span>
  252. <i class="icon-dot" style="color: #eacf19"></i>
  253. 本月新增
  254. </span>
  255. </div>
  256. </div>
  257. </div>
  258. </div>
  259. </div>
  260. </div>
  261. <div class="column">
  262. <!-- 订单 -->
  263. <?php
  264. include_once("../../untils/conn.php");
  265. mysqli_query($con, "set names utf8");
  266. session_start();
  267. // 获取上次请求时的订单数量和总价
  268. $num_today_order_last = isset($_SESSION['num_today_order']) ? $_SESSION['num_today_order']['num'] : 0;
  269. $total_price_today_order_last = isset($_SESSION['num_today_order']) ? $_SESSION['num_today_order']['total_price'] : 0;
  270. // 获取今天的日期
  271. $today = date('Y-m-d');
  272. // 查询今天的订单数量和总价
  273. $sql = "SELECT COUNT(*) as num, SUM(price) as total_price FROM oder WHERE DATE(FROM_UNIXTIME(`time`))='{$today}'";
  274. $result = mysqli_query($con, $sql);
  275. if ($result === false) {
  276. echo "SQL执行失败,错误信息为:" . mysqli_error($con);
  277. } else {
  278. $row = mysqli_fetch_assoc($result);
  279. $num_today_order = $row['num'];
  280. $total_price_today_order = $row['total_price'];
  281. // 比较两次订单数量,如果数量增加了1,则播放音乐
  282. if ($num_today_order_last < $num_today_order && $num_today_order - $num_today_order_last === 1) {
  283. // 播放音乐的逻辑
  284. echo '<audio src="https://cdn.qiniu.junes.cn/upload/2023/06/news.mp3" autoplay></audio>';
  285. }
  286. // 将当前订单数量和总价保存到 session
  287. $_SESSION['num_today_order'] = array(
  288. 'num' => $num_today_order,
  289. 'total_price' => $total_price_today_order
  290. );
  291. }
  292. ?>
  293. <div class="order panel">
  294. <div class="inner">
  295. <div class="filter">
  296. <a href="#">今日实时订单佣金数据记录</a>
  297. </div>
  298. <!-- 数据 -->
  299. <div class="data">
  300. <div class="item">
  301. <h4><?php echo $num_today_order ?></h4>
  302. <span>
  303. <i class="icon-dot" style="color: #ed3f35;"></i>
  304. 今日订单
  305. </span>
  306. </div>
  307. <div class="item">
  308. <h4><?php echo isset($total_price_today_order) ? $total_price_today_order : 0; ?></h4>
  309. <span>
  310. <i class="icon-dot" style="color: #eacf19;"></i>
  311. 今日预估佣金(元)
  312. </span>
  313. </div>
  314. </div>
  315. </div>
  316. </div>
  317. <!-- 销售额 -->
  318. <div class="sales panel">
  319. <div class="inner">
  320. <div class="caption">
  321. <h3>佣金统计</h3>
  322. <a href="javascript:;" class="active" data-type="year">年</a>
  323. <a href="javascript:;" data-type="quarter">季</a>
  324. <a href="javascript:;" data-type="month">月</a>
  325. <a href="javascript:;" data-type="week">周</a>
  326. </div>
  327. <div class="chart">
  328. <div class="label">单位:元</div>
  329. <div class="line"></div>
  330. </div>
  331. </div>
  332. </div>
  333. <!-- 渠道 季度 -->
  334. <?php
  335. include_once("../../untils/conn.php");
  336. mysqli_query($con, "set names utf8");
  337. // 查询渠道表
  338. $sql = "SELECT * FROM channel";
  339. $result = mysqli_query($con, $sql);
  340. // 计算三个月前的时间戳
  341. $date = date('Y-m-d H:i:s', strtotime('-3 months'));
  342. $timestamp = strtotime($date);
  343. // 初始化订单总数变量
  344. $total_orders = 0;
  345. // 循环遍历渠道信息
  346. while ($channel = mysqli_fetch_array($result)) {
  347. $channel_id = $channel['channel_id'];
  348. $channel_name = $channel['channel_name'];
  349. // 查询该渠道三个月内的订单数量
  350. $sql = "SELECT COUNT(*) as num FROM oder WHERE `time` >= {$timestamp} AND `channel` = {$channel_id}";
  351. $result2 = mysqli_query($con, $sql);
  352. $orders = mysqli_fetch_array($result2)['num'];
  353. // 累加订单数量到总数
  354. $total_orders += $orders;
  355. }
  356. // 初始化渠道占比信息数组
  357. $channel_ratios = array();
  358. // 循环遍历渠道信息,计算每个渠道订单数量占比,并保存到数组中
  359. mysqli_data_seek($result, 0); // 将查询结果句柄指针重置
  360. while ($channel = mysqli_fetch_array($result)) {
  361. $channel_id = $channel['channel_id'];
  362. $channel_name = $channel['channel_name'];
  363. // 查询该渠道三个月内的订单数量
  364. $sql = "SELECT COUNT(*) as num FROM oder WHERE `time` >= {$timestamp} AND `channel` = {$channel_id}";
  365. $result2 = mysqli_query($con, $sql);
  366. $orders = mysqli_fetch_array($result2)['num'];
  367. // 计算该渠道订单数量占比
  368. $ratio = ($total_orders > 0) ? round($orders/$total_orders*100) : 0;
  369. // 将占比信息保存到数组中
  370. $channel_ratios[] = array('name'=>$channel_name, 'ratio'=>$ratio);
  371. }
  372. ?>
  373. <div class="wrap">
  374. <div class="channel panel">
  375. <div class="inner">
  376. <h3>渠道分布</h3>
  377. <?php for ($i = 0; $i < count($channel_ratios); $i += 2) { ?>
  378. <div class="data">
  379. <div class="item">
  380. <h4><?php echo $channel_ratios[$i]['ratio'] ?> <small>%</small></h4>
  381. <span>
  382. <i class="icon-dot"></i>
  383. <?php echo $channel_ratios[$i]['name']?>
  384. </span>
  385. </div>
  386. <?php if (isset($channel_ratios[$i+1])) { ?>
  387. <div class="item">
  388. <h4><?php echo $channel_ratios[$i+1]['ratio'] ?> <small>%</small></h4>
  389. <span>
  390. <i class="icon-dot"></i>
  391. <?php echo $channel_ratios[$i+1]['name'] ?>
  392. </span>
  393. </div>
  394. <?php } ?>
  395. </div>
  396. <?php } ?>
  397. </div>
  398. </div>
  399. <?php
  400. // 三个月前的日期
  401. include_once("../../untils/conn.php");
  402. mysqli_query($con, "set names utf8");
  403. $date = date('Y-m-d', strtotime('-3 month'));
  404. $sql = "SELECT COUNT(*) as jidu FROM oder WHERE `time` >= UNIX_TIMESTAMP('{$date}')";
  405. $result = mysqli_query($con, $sql);
  406. if ($result === false) {
  407. die(mysqli_error($con)); // 如果查询出错则输出错误信息
  408. }
  409. $row = mysqli_fetch_assoc($result);
  410. $jidu = $row['jidu'];
  411. ?>
  412. <div class="quarter panel">
  413. <div class="inner">
  414. <h3>季度佣金进度</h3>
  415. <div class="chart">
  416. <div class="box">
  417. <div class="gauge"></div>
  418. <div class="label">70<small> %</small></div>
  419. </div>
  420. <div class="data">
  421. <div class="item">
  422. <h4><?php echo $jidu *110 ?></h4>
  423. <span>
  424. <i class="icon-dot" style="color: #6acca3"></i>
  425. 佣金(元)
  426. </span>
  427. </div>
  428. <div class="item">
  429. <h4>150%</h4>
  430. <span>
  431. <i class="icon-dot" style="color: #ed3f35"></i>
  432. 同比增长
  433. </span>
  434. </div>
  435. </div>
  436. </div>
  437. </div>
  438. </div>
  439. </div>
  440. <!-- 排行榜 -->
  441. <?php
  442. include_once("../../untils/conn.php");
  443. mysqli_query($con, "set names utf8");
  444. $sql = "SELECT goods, COUNT(*) AS count FROM oder GROUP BY goods ORDER BY count DESC LIMIT 3";
  445. $result = $con->query($sql);
  446. $rows = array();
  447. if ($result->num_rows > 0) {
  448. while($row = $result->fetch_assoc()) {
  449. $rows[] = $row;
  450. }
  451. } else {
  452. echo "未找到匹配数据";
  453. }
  454. ?>
  455. <div class="top panel">
  456. <div class="inner">
  457. <div class="all">
  458. <h3>全国热榜</h3>
  459. <ul>
  460. <?php
  461. $icons = array('icon-cup1', 'icon-cup2', 'icon-cup3');
  462. for($i=0; $i<count($rows); $i++) {
  463. $row = $rows[$i];
  464. echo '<li class="item-' . ($i+1) . '"><i class="' . $icons[$i] . '" style="color: #d93f36;"></i>';
  465. echo $row['goods']; // 输出商品名
  466. echo '</li>';
  467. }
  468. ?>
  469. </ul>
  470. </div>
  471. <?php
  472. // 连接数据库
  473. include_once("../../untils/conn.php");
  474. mysqli_query($con, "set names utf8");
  475. // 查询sf列中出现最多城市及销量
  476. $sql = "SELECT sf, COUNT(*) as count FROM oder GROUP BY sf ORDER BY COUNT(*) DESC";
  477. $result = mysqli_query($con, $sql);
  478. // 检查查询结果是否存在错误
  479. if (!$result) {
  480. printf("Error: %s\n", mysqli_error($con));
  481. exit();
  482. }
  483. ?>
  484. <div class="province">
  485. <h3>各省热销 <i class="date">// 近30日 //</i></h3>
  486. <div class="data">
  487. <ul class="sup">
  488. <?php
  489. while ($row = mysqli_fetch_assoc($result)) {
  490. ?>
  491. <li>
  492. <span><?php echo $row['sf']; ?></span>
  493. <span><?php echo number_format($row['count']); ?> <s class="icon-up"></s></span>
  494. </li>
  495. <?php
  496. }
  497. ?>
  498. </ul>
  499. <ul class="sub">
  500. <!-- <li><span>数据</span><span> 数据<s class="icon-up"></s></span></li> -->
  501. </ul>
  502. </div>
  503. </div>
  504. </div>
  505. </div>
  506. </div>
  507. </div>
  508. </body>
  509. <script type="text/javascript">
  510. var cityData = <?php echo json_encode($cities); ?>;
  511. var orderData = <?php echo json_encode($orderCounts); ?>;
  512. // 在控制台打印城市信息
  513. console.log(cityData);
  514. console.log(orderData);
  515. </script>
  516. <script type="text/javascript">
  517. var timeLeft = 10;
  518. var countdown = setInterval(function() {
  519. timeLeft--;
  520. document.getElementById("countdown").textContent = timeLeft;
  521. if (timeLeft <= 0) {
  522. clearInterval(countdown);
  523. window.location.reload();
  524. }
  525. }, 1000);
  526. </script>
  527. <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
  528. <script src="https://www.jq22.com/jquery/echarts-4.2.1.min.js"></script>
  529. <script src="./js/index.js"></script>
  530. <script src="./js/china.js"></script>
  531. <script src="./js/mymap.js"></script>
  532. </html>
  533. <?php
  534. } else {
  535. echo "<script>alert('您尚未登录,没有权限访问该页面');location.href='../login.php';</script>";
  536. }