Index.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Hook;
  4. use think\Db;
  5. class Index extends Base
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function login()
  12. {
  13. if (Request()->isPost()) {
  14. $data = input('post.');
  15. $res = model('Admin')->login($data);
  16. if ($res['code'] > 1) {
  17. return $this->error($res['msg']);
  18. }
  19. return $this->success($res['msg']);
  20. }
  21. Hook::listen("admin_login_init", $this->request);
  22. return $this->fetch('admin@index/login');
  23. }
  24. public function logout()
  25. {
  26. $res = model('Admin')->logout();
  27. $this->redirect('index/login');
  28. }
  29. public function index()
  30. {
  31. $menus = @include MAC_ADMIN_COMM . 'auth.php';
  32. $version = config('version');
  33. foreach ($menus as $k1 => $v1) {
  34. foreach ($v1['sub'] as $k2 => $v2) {
  35. if ($v2['show'] == 1) {
  36. if (strpos($v2['action'], 'javascript') !== false) {
  37. $url = $v2['action'];
  38. } else {
  39. $url = url('admin/' . $v2['controller'] . '/' . $v2['action']);
  40. }
  41. if (!empty($v2['param'])) {
  42. $url .= '?' . $v2['param'];
  43. }
  44. if ($this->check_auth($v2['controller'], $v2['action'])) {
  45. $menus[$k1]['sub'][$k2]['url'] = $url;
  46. } else {
  47. unset($menus[$k1]['sub'][$k2]);
  48. }
  49. } else {
  50. unset($menus[$k1]['sub'][$k2]);
  51. }
  52. }
  53. if (empty($menus[$k1]['sub'])) {
  54. unset($menus[$k1]);
  55. }
  56. }
  57. $quickmenu = config('quickmenu');
  58. if (empty($quickmenu)) {
  59. $quickmenu = mac_read_file(APP_PATH . 'data/config/quickmenu.txt');
  60. $quickmenu = explode(chr(13), $quickmenu);
  61. }
  62. if (!empty($quickmenu)) {
  63. $menus[1]['sub'][13] = ['name' => lang('admin/index/quick_tit'), 'url' => 'javascript:void(0);return false;', 'controller' => '', 'action' => ''];
  64. foreach ($quickmenu as $k => $v) {
  65. if (empty($v)) {
  66. continue;
  67. }
  68. $one = explode(',', trim($v));
  69. if (substr($one[1], 0, 4) == 'http' || substr($one[1], 0, 2) == '//') {
  70. } elseif (substr($one[1], 0, 1) == '/') {
  71. } elseif (strpos($one[1], '###') !== false || strpos($one[1], 'javascript:') !== false) {
  72. } else {
  73. $one[1] = url($one[1]);
  74. }
  75. $menus[1]['sub'][14 + $k] = ['name' => $one[0], 'url' => $one[1], 'controller' => '', 'action' => ''];
  76. }
  77. }
  78. $langs = glob('./application/lang/*.php');
  79. foreach ($langs as $k => &$v) {
  80. $v = str_replace(['./application/lang/','.php'],['',''],$v);
  81. }
  82. $config = config('maccms');
  83. $this->assign('config', $config);
  84. $this->assign('langs', $langs);
  85. $this->assign('version', $version);
  86. $this->assign('menus', $menus);
  87. $this->assign('title', lang('admin/index/title'));
  88. return $this->fetch('admin@index/index');
  89. }
  90. public function welcome()
  91. {
  92. $version = config('version');
  93. $update_sql = file_exists('./application/data/update/database.php');
  94. $this->assign('spider_data', $this->botlist());
  95. $this->assign('os_data', $this->get_system_status());
  96. $this->assign('version', $version);
  97. $this->assign('update_sql', $update_sql);
  98. $this->assign('mac_lang', config('default_lang'));
  99. $this->assign('dashboard_data', $this->getAdminDashboardData());
  100. $this->assign('admin', $this->_admin);
  101. $this->assign('title', lang('admin/index/welcome/title'));
  102. return $this->fetch('admin@index/welcome');
  103. }
  104. public function quickmenu()
  105. {
  106. if (Request()->isPost()) {
  107. $param = input();
  108. $validate = \think\Loader::validate('Token');
  109. if (!$validate->check($param)) {
  110. return $this->error($validate->getError());
  111. }
  112. $quickmenu = input('post.quickmenu');
  113. $quickmenu = str_replace(chr(10), '', $quickmenu);
  114. $menu_arr = explode(chr(13), $quickmenu);
  115. $res = mac_arr2file(APP_PATH . 'extra/quickmenu.php', $menu_arr);
  116. if ($res === false) {
  117. return $this->error(lang('save_err'));
  118. }
  119. return $this->success(lang('save_ok'));
  120. } else {
  121. $config_menu = config('quickmenu');
  122. if (empty($config_menu)) {
  123. $quickmenu = mac_read_file(APP_PATH . 'data/config/quickmenu.txt');
  124. } else {
  125. $quickmenu = array_values($config_menu);
  126. $quickmenu = join(chr(13), $quickmenu);
  127. }
  128. $this->assign('quickmenu', $quickmenu);
  129. $this->assign('title', lang('admin/index/quickmenu/title'));
  130. return $this->fetch('admin@index/quickmenu');
  131. }
  132. }
  133. public function checkcache()
  134. {
  135. $res = 'no';
  136. $r = cache('cache_data');
  137. if ($r == '1') {
  138. $res = 'haved';
  139. }
  140. echo $res;
  141. }
  142. public function clear()
  143. {
  144. $res = $this->_cache_clear();
  145. //运行缓存
  146. if (!$res) {
  147. $this->error(lang('admin/index/clear_err'));
  148. }
  149. // 搜索缓存结果清理
  150. model('VodSearch')->clearOldResult(true);
  151. return $this->success(lang('admin/index/clear_ok'));
  152. }
  153. public function iframe()
  154. {
  155. $val = input('post.val', 0);
  156. if ($val != 0 && $val != 1) {
  157. return $this->error(lang('admin/index/clear_ok'));
  158. }
  159. if ($val == 1) {
  160. cookie('is_iframe', 'yes');
  161. } else {
  162. cookie('is_iframe', null);
  163. }
  164. return $this->success(lang('admin/index/iframe'));
  165. }
  166. public function unlocked()
  167. {
  168. $param = input();
  169. $password = $param['password'];
  170. if ($this->_admin['admin_pwd'] != md5($password)) {
  171. return $this->error(lang('admin/index/pass_err'));
  172. }
  173. return $this->success(lang('admin/index/unlock_ok'));
  174. }
  175. public function check_back_link()
  176. {
  177. $param = input();
  178. $res = mac_check_back_link($param['url']);
  179. return json($res);
  180. }
  181. public function select()
  182. {
  183. $param = input();
  184. $tpl = $param['tpl'];
  185. $tab = $param['tab'];
  186. $col = $param['col'];
  187. $ids = $param['ids'];
  188. $url = $param['url'];
  189. $val = $param['val'];
  190. $refresh = $param['refresh'];
  191. if (empty($tpl) || empty($tab) || empty($col) || empty($ids) || empty($url)) {
  192. return $this->error(lang('param_err'));
  193. }
  194. if (is_array($ids)) {
  195. $ids = join(',', $ids);
  196. }
  197. if (empty($refresh)) {
  198. $refresh = 'yes';
  199. }
  200. $url = url($url);
  201. $mid = 1;
  202. if ($tab == 'art') {
  203. $mid = 2;
  204. } elseif ($tab == 'actor') {
  205. $mid = 8;
  206. } elseif ($tab == 'website') {
  207. $mid = 11;
  208. }
  209. $this->assign('mid', $mid);
  210. if ($tpl == 'select_type') {
  211. $type_tree = model('Type')->getCache('type_tree');
  212. $this->assign('type_tree', $type_tree);
  213. } elseif ($tpl == 'select_level') {
  214. $level_list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  215. $this->assign('level_list', $level_list);
  216. }
  217. $this->assign('refresh', $refresh);
  218. $this->assign('url', $url);
  219. $this->assign('tab', $tab);
  220. $this->assign('col', $col);
  221. $this->assign('ids', $ids);
  222. $this->assign('val', $val);
  223. return $this->fetch('admin@public/' . $tpl);
  224. }
  225. public function get_system_status()
  226. {
  227. //判斷系統
  228. $os_name = strtoupper(substr(PHP_OS, 0, 3));
  229. $os_data = [];
  230. $os_data['os_name'] = '';
  231. if ($os_name == 'WIN') {
  232. $os_data['os_name'] = 'WINDOWS';
  233. $os_data['disk_datas'] = $this->get_spec_disk('all');
  234. $os_data['cpu_usage'] = $this->getCpuUsage();
  235. $mem_arr = $this->getMemoryUsage();
  236. $os_data['mem_usage'] = $mem_arr['usage'];
  237. $os_data['mem_total'] = round($mem_arr['TotalVisibleMemorySize'] / 1024, 2);
  238. $os_data['mem_used'] = $os_data['mem_total'] - round($mem_arr['FreePhysicalMemory'] / 1024, 2);
  239. } else if ($os_name == 'LIN') {
  240. $os_data['os_name'] = 'LINUX';
  241. $totalSpace = disk_total_space('/'); // 获取根目录的总容量
  242. $freeSpace = disk_free_space('/'); // 获取根目录的可用容量
  243. $totalSpaceGB = $totalSpace / (1024 * 1024 * 1024); // 将总容量转换为GB
  244. $freeSpaceGB = $freeSpace / (1024 * 1024 * 1024); // 将可用容量转换为GB
  245. $tmp_disk_data = [];
  246. $tmp_disk_data[0] = $totalSpaceGB - $freeSpaceGB;
  247. $tmp_disk_data[1] = $totalSpaceGB;
  248. if ($totalSpaceGB != 0) {
  249. $tmp_disk_data[2] = (100 - round(($freeSpaceGB / $totalSpaceGB) * 100, 2));
  250. } else {
  251. $tmp_disk_data[2] = 0;
  252. }
  253. $os_data['disk_datas']['/'] = $tmp_disk_data;
  254. $mem_arr = $this->get_linux_server_memory_usage();
  255. $os_data['mem_usage'] = $mem_arr['usage'];
  256. $os_data['mem_used'] = $mem_arr['used'];
  257. $os_data['mem_total'] = $mem_arr['total'];
  258. $os_data['cpu_usage'] = $this->get_linux_server_cpu_usage()['usage'];
  259. // if (is_readable("/proc/stat")) {
  260. // $statData1 = $this->_getServerLoadLinuxData();
  261. // sleep(0.5);
  262. // $statData2 = $this->_getServerLoadLinuxData();
  263. // if (
  264. // (!is_null($statData1)) &&
  265. // (!is_null($statData2))
  266. // ) {
  267. // $statData2[0] -= $statData1[0];
  268. // $statData2[1] -= $statData1[1];
  269. // $statData2[2] -= $statData1[2];
  270. // $statData2[3] -= $statData1[3];
  271. // $cpuTime = $statData2[0] + $statData2[1] + $statData2[2] + $statData2[3];
  272. // if ($cpuTime > 0) {
  273. // $os_data['cpu_usage'] = 100 - ($statData2[3] * 100 / $cpuTime);
  274. // } else {
  275. // $os_data['cpu_usage'] = 0;
  276. // }
  277. // }
  278. // }
  279. }
  280. return $os_data;
  281. }
  282. private function byte_format($size, $dec = 2)
  283. {
  284. if ($size == 0) {
  285. return "0 B";
  286. }
  287. $a = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  288. $pos = 0;
  289. while ($size >= 1024) {
  290. $size /= 1024;
  291. $pos++;
  292. }
  293. return round($size, $dec);
  294. }
  295. private function get_disk_space($letter)
  296. {
  297. //获取磁盘信息
  298. $diskct = 0;
  299. $disk = array();
  300. $diskz = 0; //磁盘总容量
  301. $diskk = 0; //磁盘剩余容量
  302. $is_disk = $letter . ':';
  303. if (@disk_total_space($is_disk) != NULL) {
  304. $diskct++;
  305. $disk[$letter][0] = $this->byte_format(@disk_free_space($is_disk));
  306. $disk[$letter][1] = $this->byte_format(@disk_total_space($is_disk));
  307. // $disk[$letter][2] = (100-round(((@disk_free_space($is_disk)/(1024*1024*1024))/(@disk_total_space($is_disk)/(1024*1024*1024)))*100,2));
  308. if (@disk_total_space($is_disk) != 0) {
  309. $disk[$letter][2] = (round(100 - round(((@disk_free_space($is_disk) / (1024 * 1024 * 1024)) / (@disk_total_space($is_disk) / (1024 * 1024 * 1024))) * 100, 2), 2));
  310. } else {
  311. $disk[$letter][2] = 0;
  312. }
  313. $diskk += $this->byte_format(@disk_free_space($is_disk));
  314. $diskz += $this->byte_format(@disk_total_space($is_disk));
  315. }
  316. return $disk;
  317. }
  318. private function get_spec_disk($type = 'system')
  319. {
  320. $disk = array();
  321. switch ($type) {
  322. case 'system':
  323. //strrev(array_pop(explode(':',strrev(getenv_info('SystemRoot')))));//取得系统盘符
  324. $disk = $this->get_disk_space(strrev(array_pop(explode(':', strrev(getenv('SystemRoot'))))));
  325. break;
  326. case 'all':
  327. foreach (range('b', 'z') as $letter) {
  328. $disk = array_merge($disk, $this->get_disk_space(strtoupper($letter)));
  329. }
  330. break;
  331. default:
  332. $disk = $this->get_disk_space($type);
  333. break;
  334. }
  335. return $disk;
  336. }
  337. private function getFilePath($fileName, $content)
  338. {
  339. $path = dirname(__FILE__) . "\\$fileName";
  340. if (!file_exists($path)) {
  341. file_put_contents($path, $content);
  342. }
  343. return $path;
  344. }
  345. /**
  346. * 获得cpu使用率vbs文件生成函数
  347. * @return string 返回vbs文件路径
  348. */
  349. private function getCupUsageVbsPath()
  350. {
  351. return $this->getFilePath(
  352. 'cpu_usage.vbs',
  353. "On Error Resume Next
  354. Set objProc = GetObject(\"winmgmts:\\\\.\\root\cimv2:win32_processor='cpu0'\")
  355. WScript.Echo(objProc.LoadPercentage)"
  356. );
  357. }
  358. /**
  359. * 获得总内存及可用物理内存JSON vbs文件生成函数
  360. * @return string 返回vbs文件路径
  361. */
  362. private function getMemoryUsageVbsPath()
  363. {
  364. return $this->getFilePath(
  365. 'memory_usage.vbs',
  366. "On Error Resume Next
  367. Set objWMI = GetObject(\"winmgmts:\\\\.\\root\cimv2\")
  368. Set colOS = objWMI.InstancesOf(\"Win32_OperatingSystem\")
  369. For Each objOS in colOS
  370. Wscript.Echo(\"{\"\"TotalVisibleMemorySize\"\":\" & objOS.TotalVisibleMemorySize & \",\"\"FreePhysicalMemory\"\":\" & objOS.FreePhysicalMemory & \"}\")
  371. Next"
  372. );
  373. }
  374. /**
  375. * 获得CPU使用率
  376. * @return Number
  377. */
  378. private function getCpuUsage()
  379. {
  380. $path = $this->getCupUsageVbsPath();
  381. exec("cscript -nologo $path", $usage);
  382. return $usage[0];
  383. }
  384. /**
  385. * 获得内存使用率数组
  386. * @return array
  387. */
  388. private function getMemoryUsage()
  389. {
  390. $path = $this->getMemoryUsageVbsPath();
  391. exec("cscript -nologo $path", $usage);
  392. $memory = json_decode($usage[0], true);
  393. if ($memory['TotalVisibleMemorySize'] != 0) {
  394. $memory['usage'] = Round((($memory['TotalVisibleMemorySize'] - $memory['FreePhysicalMemory']) / $memory['TotalVisibleMemorySize']) * 100);
  395. } else {
  396. $memory['usage'] = 0;
  397. }
  398. return $memory;
  399. }
  400. private function get_linux_server_memory_usage()
  401. {
  402. $free = shell_exec('free');
  403. $free = (string)trim($free);
  404. $free_arr = explode("\n", $free);
  405. $mem = explode(" ", $free_arr[1]);
  406. $mem = array_filter($mem);
  407. $mem = array_merge($mem);
  408. $memory_usage = 0;
  409. if ($mem[1] != 0) {
  410. $memory_usage = $mem[2] / $mem[1] * 100;
  411. }
  412. $mem_array = [];
  413. $mem_array['total'] = round($mem[1] / 1024, 2);
  414. $mem_array['used'] = round($mem[2] / 1024, 2);
  415. $mem_array['usage'] = round($memory_usage, 2);
  416. return $mem_array;
  417. }
  418. private function get_linux_server_cpu_usage()
  419. {
  420. $cpu_load = shell_exec("top -bn1 | grep 'Cpu(s)'");
  421. if (empty($cpu_load)) {
  422. return ['error' => 'Failed to retrieve CPU usage.'];
  423. }
  424. preg_match('/\s([\d.]+)\s*us/', $cpu_load, $matches);
  425. if (isset($matches[1]) && is_numeric($matches[1])) {
  426. $cpu_usage = (float)$matches[1];
  427. } else {
  428. return ['error' => 'Failed to parse CPU usage.'];
  429. }
  430. return [
  431. 'usage' => round($cpu_usage, 2)
  432. ];
  433. }
  434. private function _getServerLoadLinuxData()
  435. {
  436. if (is_readable("/proc/stat")) {
  437. $stats = @file_get_contents("/proc/stat");
  438. if ($stats !== false) {
  439. // Remove double spaces to make it easier to extract values with explode()
  440. $stats = preg_replace("/[[:blank:]]+/", " ", $stats);
  441. // Separate lines
  442. $stats = str_replace(array("\r\n", "\n\r", "\r"), "\n", $stats);
  443. $stats = explode("\n", $stats);
  444. // Separate values and find line for main CPU load
  445. foreach ($stats as $statLine) {
  446. $statLineData = explode(" ", trim($statLine));
  447. // Found!
  448. if (
  449. (count($statLineData) >= 5) &&
  450. ($statLineData[0] == "cpu")
  451. ) {
  452. return array(
  453. $statLineData[1],
  454. $statLineData[2],
  455. $statLineData[3],
  456. $statLineData[4],
  457. );
  458. }
  459. }
  460. }
  461. }
  462. return null;
  463. }
  464. private function getAdminDashboardData()
  465. {
  466. $result = [];
  467. //已注册总用户数量
  468. $result['user_count'] = model('User')->count();
  469. $result['user_count'] = number_format($result['user_count'], 0, '.', ',');
  470. //已审核用户数量
  471. $result['user_active_count'] = model('User')->where('user_status', 1)->count();
  472. $result['user_active_count'] = number_format($result['user_active_count'], 0, '.', ',');
  473. $today_start = strtotime(date('Y-m-d 00:00:00'));
  474. $today_end = $today_start + 86399;
  475. //本日来客量
  476. $result['today_visit_count'] = model('Visit')->where('visit_time', 'between', $today_start . ',' . $today_end)->count();
  477. $result['today_visit_count'] = number_format($result['today_visit_count'], 0, '.', ',');
  478. //本日总入金
  479. $result['today_money_get'] = model('Order')->where('order_time', 'between', $today_start . ',' . $today_end)->where('order_status', 1)->sum('order_price');
  480. $result['today_money_get'] = number_format($result['today_money_get'], 2, '.', ',');
  481. //前七天 每日用户访问数
  482. $tmp_arr = Db::query("select FROM_UNIXTIME(visit_time, '%Y-%c-%d' ) days,count(*) count from (SELECT * from mac_visit where visit_time >= (unix_timestamp(CURDATE())-604800)) as temp group by days");
  483. $result['seven_day_visit_day'] = [];
  484. $result['seven_day_visit_count'] = [];
  485. $result['raise_visit_user_today'] = 0;
  486. if (is_array($tmp_arr) && count($tmp_arr) > 1 && (strtotime(end($tmp_arr)['days']) == strtotime(date('Y-m-d')))) {
  487. $yesterday_visit_count = $tmp_arr[count($tmp_arr) - 2]['count'];
  488. $lastday_visit_count = end($tmp_arr)['count'];
  489. if ($yesterday_visit_count != 0) {
  490. $result['raise_visit_user_today'] = number_format((($lastday_visit_count - $yesterday_visit_count) / $yesterday_visit_count) * 100, 2, '.', ',');
  491. } else {
  492. $result['raise_visit_user_today'] = 0;
  493. }
  494. }
  495. foreach ($tmp_arr as $data) {
  496. array_push($result['seven_day_visit_day'], $data['days']);
  497. array_push($result['seven_day_visit_count'], $data['count']);
  498. }
  499. //近七日用户访问总量
  500. $result['seven_day_visit_total_count'] = 0;
  501. foreach ($result['seven_day_visit_data'] as $k => $value) {
  502. $result['seven_day_visit_total_count'] = $result['seven_day_visit_total_count'] + $value['count'];
  503. }
  504. $result['seven_day_visit_total_count'] = number_format($result['seven_day_visit_total_count'], 0, '.', ',');
  505. //前七天 每日用户注册数
  506. $result['seven_day_reg_data'] = Db::query("select FROM_UNIXTIME(user_reg_time, '%Y-%c-%d' ) days,count(*) count from (SELECT * from mac_user where user_reg_time >= (unix_timestamp(CURDATE())-604800)) as tmp group by days");
  507. //近七日用户注册总量
  508. $result['seven_day_reg_total_count'] = 0;
  509. $result['seven_day_reg_day'] = [];
  510. $result['seven_day_reg_count'] = [];
  511. foreach ($result['seven_day_reg_data'] as $k => $value) {
  512. array_push($result['seven_day_reg_day'], $value['days']);
  513. array_push($result['seven_day_reg_count'], $value['count']);
  514. $result['seven_day_reg_total_count'] = $result['seven_day_reg_total_count'] + $value['count'];
  515. }
  516. //比較前一天的註冊量漲幅
  517. $result['raise_reg_user_today'] = 0;
  518. if (is_array($result['seven_day_reg_data']) && count($result['seven_day_reg_data']) > 1 && (strtotime(end($result['seven_day_reg_data'])['days']) == strtotime(date('Y-m-d')))) {
  519. $yesterday_reg_count = $result['seven_day_reg_data'][count($result['seven_day_reg_data']) - 2]['count'];
  520. $lastday_reg_count = end($result['seven_day_reg_data'])['count'];
  521. if ($yesterday_reg_count != 0) {
  522. $result['raise_reg_user_today'] = number_format((($lastday_reg_count - $yesterday_reg_count) / $yesterday_reg_count) * 100, 2, '.', ',');
  523. } else {
  524. $result['raise_reg_user_today'] = 0;
  525. }
  526. }
  527. $result['seven_day_reg_total_count'] = number_format($result['seven_day_reg_total_count'], 0, '.', ',');
  528. return $result;
  529. }
  530. public function rangeDateDailyVisit()
  531. {
  532. $range_daily_visit_data = Db::query("select FROM_UNIXTIME(visit_time, '%Y-%c-%d' ) days,count(*) count from (SELECT * from mac_visit where visit_time >= " . strtotime($_POST['startDate']) . "&& visit_time <= " . strtotime($_POST['endDate']) . " ) as temp group by days");
  533. $result = [];
  534. $range_visit_day = [];
  535. $range_visit_count = [];
  536. $range_visit_sum = 0;
  537. foreach ($range_daily_visit_data as $data) {
  538. $range_visit_sum = $range_visit_sum + $data['count'];
  539. array_push($range_visit_day, $data['days']);
  540. array_push($range_visit_count, $data['count']);
  541. }
  542. $result['days'] = $range_visit_day;
  543. $result['count'] = $range_visit_count;
  544. $result['sum'] = $range_visit_sum;
  545. return json_encode($result);
  546. }
  547. public function botlist()
  548. {
  549. $day_arr = [];
  550. //列出最近10天的日期
  551. for ($i = 0; $i < 7; $i++) {
  552. $day_arr[$i] = date('Y-m-d', time() - $i * 60 * 60 * 24);
  553. }
  554. $google_arr = [];
  555. $baidu_arr = [];
  556. $sogou_arr = [];
  557. $soso_arr = [];
  558. $yahoo_arr = [];
  559. $msn_arr = [];
  560. $msn_bot_arr = [];
  561. $sohu_arr = [];
  562. $yodao_arr = [];
  563. $twiceler_arr = [];
  564. $alexa_arr = [];
  565. $bot_list = [];
  566. foreach ($day_arr as $day_vo) {
  567. if (file_exists(ROOT_PATH . 'runtime/log/bot/' . $day_vo . '.txt')) {
  568. $bot_content = file_get_contents(ROOT_PATH . 'runtime/log/bot/' . $day_vo . '.txt');
  569. } else {
  570. $bot_content = '';
  571. }
  572. $google_arr[$day_vo] = substr_count($bot_content, 'Google');
  573. $baidu_arr[$day_vo] = substr_count($bot_content, 'Baidu');
  574. $sogou_arr[$day_vo] = substr_count($bot_content, 'Sogou');
  575. $soso_arr[$day_vo] = substr_count($bot_content, 'SOSO');
  576. $yahoo_arr[$day_vo] = substr_count($bot_content, 'Yahoo');
  577. $msn_arr[$day_vo] = substr_count($bot_content, 'MSN');
  578. $msn_bot_arr[$day_vo] = substr_count($bot_content, 'msnbot');
  579. $sohu_arr[$day_vo] = substr_count($bot_content, 'Sohu');
  580. $yodao_arr[$day_vo] = substr_count($bot_content, 'Yodao');
  581. $twiceler_arr[$day_vo] = substr_count($bot_content, 'Twiceler');
  582. $alexa_arr[$day_vo] = substr_count($bot_content, 'Alexa');
  583. }
  584. $bot_list['Google']['key'] = array_keys($google_arr);
  585. $bot_list['Google']['values'] = array_values($google_arr);
  586. $bot_list['Baidu']['keys'] = array_keys($baidu_arr);
  587. $bot_list['Baidu']['values'] = array_values($baidu_arr);
  588. $bot_list['Sogou']['keys'] = array_keys($sogou_arr);
  589. $bot_list['Sogou']['values'] = array_values($sogou_arr);
  590. $bot_list['SOSO']['keys'] = array_keys($soso_arr);
  591. $bot_list['SOSO']['values'] = array_values($soso_arr);
  592. $bot_list['Yahoo']['keys'] = array_keys($yahoo_arr);
  593. $bot_list['Yahoo']['values'] = array_values($yahoo_arr);
  594. $bot_list['MSN']['keys'] = array_keys($msn_arr);
  595. $bot_list['MSN']['values'] = array_values($msn_arr);
  596. $bot_list['msnbot']['keys'] = array_keys($msn_bot_arr);
  597. $bot_list['msnbot']['values'] = array_values($msn_bot_arr);
  598. $bot_list['Sohu']['keys'] = array_keys($sohu_arr);
  599. $bot_list['Sohu']['values'] = array_values($sohu_arr);
  600. $bot_list['Yodao']['keys'] = array_keys($yodao_arr);
  601. $bot_list['Yodao']['values'] = array_values($yodao_arr);
  602. $bot_list['Twiceler']['keys'] = array_keys($twiceler_arr);
  603. $bot_list['Twiceler']['values'] = array_values($twiceler_arr);
  604. $bot_list['Alexa']['keys'] = array_keys($alexa_arr);
  605. $bot_list['Alexa']['values'] = array_values($alexa_arr);
  606. if (!empty($_POST['category'])) {
  607. return $bot_list[$_POST['category']];
  608. } else {
  609. return $bot_list;
  610. }
  611. }
  612. public function botlog()
  613. {
  614. $parm = input();
  615. $data = $parm['data'];
  616. $bot_content = file_get_contents(ROOT_PATH . 'runtime/log/bot/' . $data . '.txt');
  617. $bot_list = array_slice(array_reverse(explode("\r\n", trim($bot_content))), 0, 20);
  618. $this->assign('bot_list', $bot_list);
  619. return $this->fetch('admin@others/botlog');
  620. }
  621. }