visit.mod.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function visit_update_today($type, $module_name = '') {
  8. global $_W;
  9. $module_name = trim($module_name);
  10. $type = trim($type);
  11. if (empty($type) || !in_array($type, array('app', 'web', 'api'))) {
  12. return false;
  13. }
  14. if ($type == 'app' && empty($module_name)) {
  15. return false;
  16. }
  17. $today = date('Ymd');
  18. $stat_visit_teble = table('stat_visit');
  19. $stat_visit_teble->searchWithDate($today);
  20. $stat_visit_teble->searchWithModule($module_name);
  21. $stat_visit_teble->searchWithUnacid($_W['uniacid']);
  22. $stat_visit_teble->searchWithType($type);
  23. $today_exist = $stat_visit_teble->get();
  24. if (empty($today_exist)) {
  25. $insert_data = array(
  26. 'uniacid' => $_W['uniacid'],
  27. 'module' => $module_name,
  28. 'type' => $type,
  29. 'date' => $today,
  30. 'count' => 1,
  31. 'ip_count' => 0
  32. );
  33. pdo_insert('stat_visit', $insert_data);
  34. $today_exist = $insert_data;
  35. $today_exist['id'] = pdo_insertid();
  36. } else {
  37. $data = array('count' => $today_exist['count'] + 1);
  38. pdo_update('stat_visit' , $data, array('id' => $today_exist['id']));
  39. }
  40. if (!empty($today_exist['id'])) {
  41. $ip = ip2long(getip());
  42. $stat_ip_visit_table = table('stat_visit_ip');
  43. $stat_ip_visit_table->searchWithIp($ip);
  44. $stat_ip_visit_table->searchWithDate($today);
  45. $ip_today_exist = $stat_ip_visit_table->get();
  46. if (empty($ip_today_exist)) {
  47. $ip_insert_data = array(
  48. 'ip' => $ip,
  49. 'uniacid' => $_W['uniacid'],
  50. 'module' => $module_name,
  51. 'type' => $type,
  52. 'date' => $today,
  53. );
  54. pdo_insert('stat_visit_ip', $ip_insert_data);
  55. pdo_update('stat_visit', array('ip_count' => $today_exist['ip_count'] + 1), array('id' => $today_exist['id']));
  56. }
  57. }
  58. return true;
  59. }
  60. function visit_system_update($system_stat_visit, $displayorder = false) {
  61. global $_W;
  62. load()->model('user');
  63. load()->model('account');
  64. if (user_is_founder($_W['uid'])) {
  65. return true;
  66. }
  67. if (empty($system_stat_visit['uniacid']) && empty($system_stat_visit['modulename'])) {
  68. return true;
  69. }
  70. if (empty($system_stat_visit['uid'])) {
  71. return true;
  72. }
  73. $condition['uid'] = $_W['uid'];
  74. if (!empty($system_stat_visit['uniacid'])) {
  75. $account_info = uni_fetch($system_stat_visit['uniacid']);
  76. $type = $account_info->typeSign;
  77. $own_uniacid = uni_owned($_W['uid'], false, $type);
  78. $uniacids = !empty($own_uniacid) ? array_keys($own_uniacid) : array();
  79. if (empty($uniacids) || !in_array($system_stat_visit['uniacid'], $uniacids)) {
  80. return true;
  81. }
  82. $condition['uniacid'] = $system_stat_visit['uniacid'];
  83. }
  84. if (!empty($system_stat_visit['modulename'])) {
  85. $user_modules = user_modules($_W['uid']);
  86. $modules = !empty($user_modules) ? array_keys($user_modules) : array();
  87. if (empty($modules) || !in_array($system_stat_visit['modulename'], $modules)) {
  88. return true;
  89. }
  90. $condition['modulename'] = $system_stat_visit['modulename'];
  91. }
  92. $system_stat_info = pdo_get('system_stat_visit', $condition);
  93. if (empty($system_stat_info['createtime'])) {
  94. $system_stat_visit['createtime'] = TIMESTAMP;
  95. }
  96. if (empty($system_stat_visit['updatetime'])) {
  97. $system_stat_visit['updatetime'] = TIMESTAMP;
  98. }
  99. if (!empty($displayorder)) {
  100. $system_stat_max_order = pdo_fetchcolumn("SELECT MAX(displayorder) FROM " . tablename('system_stat_visit') . " WHERE uid = :uid", array(':uid' => $_W['uid']));
  101. $system_stat_visit['displayorder'] = ++$system_stat_max_order;
  102. }
  103. if (empty($system_stat_info)) {
  104. pdo_insert('system_stat_visit', $system_stat_visit);
  105. } else {
  106. $system_stat_visit['updatetime'] = TIMESTAMP;
  107. pdo_update('system_stat_visit', $system_stat_visit, array('id' => $system_stat_info['id']));
  108. }
  109. return true;
  110. }
  111. function visit_system_delete($uid) {
  112. load()->model('user');
  113. $user_modules = user_modules($uid);
  114. $modules = !empty($user_modules) ? array_keys($user_modules) : array();
  115. $old_modules = table('system_stat_visit')->getVistedModule($uid);
  116. if (empty($old_modules)) {
  117. return true;
  118. }
  119. $old_modules = array_column($old_modules, 'modulename');
  120. $delete_modules = array_diff($old_modules, $modules);
  121. if (!empty($modules)) {
  122. table('system_stat_visit')->deleteVisitRecord($uid, $delete_modules);
  123. return true;
  124. }
  125. table('system_stat_visit')->deleteVisitRecord($uid);
  126. return true;
  127. }