123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- function visit_update_today($type, $module_name = '') {
- global $_W;
- $module_name = trim($module_name);
- $type = trim($type);
- if (empty($type) || !in_array($type, array('app', 'web', 'api'))) {
- return false;
- }
- if ($type == 'app' && empty($module_name)) {
- return false;
- }
- $today = date('Ymd');
- $stat_visit_teble = table('stat_visit');
- $stat_visit_teble->searchWithDate($today);
- $stat_visit_teble->searchWithModule($module_name);
- $stat_visit_teble->searchWithUnacid($_W['uniacid']);
- $stat_visit_teble->searchWithType($type);
- $today_exist = $stat_visit_teble->get();
- if (empty($today_exist)) {
- $insert_data = array(
- 'uniacid' => $_W['uniacid'],
- 'module' => $module_name,
- 'type' => $type,
- 'date' => $today,
- 'count' => 1,
- 'ip_count' => 0
- );
- pdo_insert('stat_visit', $insert_data);
- $today_exist = $insert_data;
- $today_exist['id'] = pdo_insertid();
- } else {
- $data = array('count' => $today_exist['count'] + 1);
- pdo_update('stat_visit' , $data, array('id' => $today_exist['id']));
- }
- if (!empty($today_exist['id'])) {
- $ip = ip2long(getip());
- $stat_ip_visit_table = table('stat_visit_ip');
- $stat_ip_visit_table->searchWithIp($ip);
- $stat_ip_visit_table->searchWithDate($today);
- $ip_today_exist = $stat_ip_visit_table->get();
- if (empty($ip_today_exist)) {
- $ip_insert_data = array(
- 'ip' => $ip,
- 'uniacid' => $_W['uniacid'],
- 'module' => $module_name,
- 'type' => $type,
- 'date' => $today,
- );
- pdo_insert('stat_visit_ip', $ip_insert_data);
- pdo_update('stat_visit', array('ip_count' => $today_exist['ip_count'] + 1), array('id' => $today_exist['id']));
- }
- }
- return true;
- }
- function visit_system_update($system_stat_visit, $displayorder = false) {
- global $_W;
- load()->model('user');
- load()->model('account');
- if (user_is_founder($_W['uid'])) {
- return true;
- }
- if (empty($system_stat_visit['uniacid']) && empty($system_stat_visit['modulename'])) {
- return true;
- }
- if (empty($system_stat_visit['uid'])) {
- return true;
- }
- $condition['uid'] = $_W['uid'];
- if (!empty($system_stat_visit['uniacid'])) {
- $account_info = uni_fetch($system_stat_visit['uniacid']);
- $type = $account_info->typeSign;
- $own_uniacid = uni_owned($_W['uid'], false, $type);
- $uniacids = !empty($own_uniacid) ? array_keys($own_uniacid) : array();
- if (empty($uniacids) || !in_array($system_stat_visit['uniacid'], $uniacids)) {
- return true;
- }
- $condition['uniacid'] = $system_stat_visit['uniacid'];
- }
- if (!empty($system_stat_visit['modulename'])) {
- $user_modules = user_modules($_W['uid']);
- $modules = !empty($user_modules) ? array_keys($user_modules) : array();
- if (empty($modules) || !in_array($system_stat_visit['modulename'], $modules)) {
- return true;
- }
- $condition['modulename'] = $system_stat_visit['modulename'];
- }
- $system_stat_info = pdo_get('system_stat_visit', $condition);
- if (empty($system_stat_info['createtime'])) {
- $system_stat_visit['createtime'] = TIMESTAMP;
- }
- if (empty($system_stat_visit['updatetime'])) {
- $system_stat_visit['updatetime'] = TIMESTAMP;
- }
- if (!empty($displayorder)) {
- $system_stat_max_order = pdo_fetchcolumn("SELECT MAX(displayorder) FROM " . tablename('system_stat_visit') . " WHERE uid = :uid", array(':uid' => $_W['uid']));
- $system_stat_visit['displayorder'] = ++$system_stat_max_order;
- }
- if (empty($system_stat_info)) {
- pdo_insert('system_stat_visit', $system_stat_visit);
- } else {
- $system_stat_visit['updatetime'] = TIMESTAMP;
- pdo_update('system_stat_visit', $system_stat_visit, array('id' => $system_stat_info['id']));
- }
- return true;
- }
- function visit_system_delete($uid) {
- load()->model('user');
- $user_modules = user_modules($uid);
- $modules = !empty($user_modules) ? array_keys($user_modules) : array();
- $old_modules = table('system_stat_visit')->getVistedModule($uid);
- if (empty($old_modules)) {
- return true;
- }
- $old_modules = array_column($old_modules, 'modulename');
- $delete_modules = array_diff($old_modules, $modules);
- if (!empty($modules)) {
- table('system_stat_visit')->deleteVisitRecord($uid, $delete_modules);
- return true;
- }
- table('system_stat_visit')->deleteVisitRecord($uid);
- return true;
- }
|