人人商城

visit.mod.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. $params = array('date' => $today, 'uniacid' => $_W['uniacid'], 'module' => $module_name, 'type' => $type);
  19. $today_exist = table('statistics')->visitList($params, 'one');
  20. if (empty($today_exist)) {
  21. $insert_data = array(
  22. 'uniacid' => $_W['uniacid'],
  23. 'module' => $module_name,
  24. 'type' => $type,
  25. 'date' => $today,
  26. 'count' => 1
  27. );
  28. pdo_insert('stat_visit', $insert_data);
  29. } else {
  30. $data = array('count' => $today_exist['count'] + 1);
  31. pdo_update('stat_visit' , $data, array('id' => $today_exist['id']));
  32. }
  33. return true;
  34. }
  35. function visit_system_update($system_stat_visit, $displayorder = false) {
  36. global $_W;
  37. load()->model('user');
  38. load()->model('account');
  39. if (user_is_founder($_W['uid'])) {
  40. return true;
  41. }
  42. if (empty($system_stat_visit['uniacid']) && empty($system_stat_visit['modulename'])) {
  43. return true;
  44. }
  45. if (empty($system_stat_visit['uid'])) {
  46. return true;
  47. }
  48. $condition['uid'] = $_W['uid'];
  49. if (!empty($system_stat_visit['uniacid'])) {
  50. $own_uniacid = uni_owned($_W['uid'], false);
  51. $uniacids = !empty($own_uniacid) ? array_keys($own_uniacid) : array();
  52. if (empty($uniacids) || !in_array($system_stat_visit['uniacid'], $uniacids)) {
  53. return true;
  54. }
  55. $condition['uniacid'] = $system_stat_visit['uniacid'];
  56. }
  57. if (!empty($system_stat_visit['modulename'])) {
  58. $user_modules = user_modules($_W['uid']);
  59. $modules = !empty($user_modules) ? array_keys($user_modules) : array();
  60. if (empty($modules) || !in_array($system_stat_visit['modulename'], $modules)) {
  61. return true;
  62. }
  63. $condition['modulename'] = $system_stat_visit['modulename'];
  64. }
  65. $system_stat_info = pdo_get('system_stat_visit', $condition);
  66. if (empty($system_stat_info['createtime'])) {
  67. $system_stat_visit['createtime'] = TIMESTAMP;
  68. }
  69. if (empty($system_stat_visit['updatetime'])) {
  70. $system_stat_visit['updatetime'] = TIMESTAMP;
  71. }
  72. if (!empty($displayorder)) {
  73. $system_stat_max_order = pdo_fetchcolumn("SELECT MAX(displayorder) FROM " . tablename('system_stat_visit') . " WHERE uid = :uid", array(':uid' => $_W['uid']));
  74. $system_stat_visit['displayorder'] = ++$system_stat_max_order;
  75. }
  76. if (empty($system_stat_info)) {
  77. pdo_insert('system_stat_visit', $system_stat_visit);
  78. } else {
  79. $system_stat_visit['updatetime'] = TIMESTAMP;
  80. pdo_update('system_stat_visit', $system_stat_visit, array('id' => $system_stat_info['id']));
  81. }
  82. return true;
  83. }
  84. function visit_system_delete($uid) {
  85. load()->model('user');
  86. $user_modules = user_modules($uid);
  87. $modules = !empty($user_modules) ? array_keys($user_modules) : array();
  88. $old_modules = table('system_stat_visit')->getVistedModule($uid);
  89. if (empty($old_modules)) {
  90. return true;
  91. }
  92. $old_modules = array_column($old_modules, 'modulename');
  93. $delete_modules = array_diff($old_modules, $modules);
  94. if (!empty($modules)) {
  95. table('system_stat_visit')->deleteVisitRecord($uid, $delete_modules);
  96. return true;
  97. }
  98. table('system_stat_visit')->deleteVisitRecord($uid);
  99. return true;
  100. }