app.mod.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 app_navs($type = 'home', $multiid = 0, $section = 0) {
  8. global $_W;
  9. $pos = array();
  10. $pos['home'] = 1;
  11. $pos['profile'] = 2;
  12. $pos['shortcut'] = 3;
  13. if (empty($multiid) && $type != 'profile') {
  14. load()->model('account');
  15. $setting = uni_setting($_W['uniacid'], array('default_site'));
  16. $multiid = $setting['default_site'];
  17. }
  18. $params = array(
  19. 'position' => $pos[$type],
  20. 'status' => 1,
  21. 'uniacid' => $_W['uniacid'],
  22. 'multiid' => $multiid
  23. );
  24. $navs = table('site')->siteNavList($params);
  25. if (!empty($navs)) {
  26. foreach ($navs as &$row) {
  27. if (!strexists($row['url'], 'tel:') && !strexists($row['url'], '://') && !strexists($row['url'], 'www') && !strexists($row['url'], 'i=')) {
  28. $row['url'] .= strexists($row['url'], '?') ? "&i={$_W['uniacid']}" : "?i={$_W['uniacid']}";
  29. }
  30. if (is_serialized($row['css'])) {
  31. $row['css'] = unserialize($row['css']);
  32. }
  33. if (empty($row['css']['icon']['icon'])) {
  34. $row['css']['icon']['icon'] = 'fa fa-external-link';
  35. }
  36. if ($row['position'] == '3') {
  37. if (!empty($row['css'])) {
  38. unset($row['css']['icon']['font-size']);
  39. }
  40. }
  41. $row['css']['icon']['style'] = "color:{$row['css']['icon']['color']};font-size:{$row['css']['icon']['font-size']}px;";
  42. $row['css']['name'] = "color:{$row['css']['name']['color']};";
  43. }
  44. unset($row);
  45. }
  46. return $navs;
  47. }
  48. function app_update_today_visit($module_name) {
  49. global $_W;
  50. $module_name = trim($module_name);
  51. if (empty($module_name) || !in_array($_W['account']['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  52. return false;
  53. }
  54. $today = date('Ymd');
  55. $statistics_table = table('statistics');
  56. $params = array(
  57. 'date' => $today,
  58. 'uniacid' => $_W['uniacid'],
  59. 'module' => $module_name,
  60. 'type' => 'app'
  61. );
  62. $today_exist = $statistics_table->visitList($params, 'one');
  63. if (empty($today_exist)) {
  64. $insert_data = array(
  65. 'uniacid' => $_W['uniacid'],
  66. 'module' => $module_name,
  67. 'type' => 'app',
  68. 'date' => $today,
  69. 'count' => 1
  70. );
  71. pdo_insert('stat_visit', $insert_data);
  72. } else {
  73. $data = array('count' => $today_exist['count'] + 1);
  74. pdo_update('stat_visit' , $data, array('id' => $today_exist['id']));
  75. }
  76. return true;
  77. }
  78. function app_pass_visit_limit($uniacid = 0) {
  79. global $_W;
  80. if ($_W['isajax'] || $_W['ispost'] || strpos($_W['siteurl'], 'c=utility&a=visit') !== false) {
  81. return false;
  82. }
  83. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  84. $limit = uni_setting_load('statistics', $uniacid);
  85. $limit = $limit['statistics'];
  86. if (empty($limit)) {
  87. return false;
  88. }
  89. $cachekey = cache_system_key("statistics:{$uniacid}");
  90. $cache = cache_load($cachekey);
  91. if (!empty($cache) && ($cache['time'] + $limit['interval'] > TIMESTAMP)) {
  92. return $cache['limit'];
  93. }
  94. $data = array('time'=> TIMESTAMP, 'limit' => false);
  95. $today_num = app_today_visit($uniacid);
  96. if (!empty($limit['founder'])) {
  97. $order_num = 0;
  98. $orders = table('store')->apiOrderWithUniacid($uniacid);
  99. if (!empty($orders)) {
  100. foreach ($orders as $order) {
  101. $order_num += $order['duration'] * $order['api_num'] * 10000;
  102. }
  103. }
  104. $before_num = app_month_visit_till_today($uniacid);
  105. $sum_num = intval($limit['founder']) + $order_num - intval($limit['use']);
  106. if ($sum_num <= 0) {
  107. $data['limit'] = true;
  108. cache_write($cachekey, $data);
  109. return true;
  110. }
  111. }
  112. if (!empty($limit['owner']) && $today_num > $limit['owner']) {
  113. $data['limit'] = true;
  114. cache_write($cachekey, $data);
  115. return true;
  116. }
  117. if (!empty($limit['founder']) && ($before_num + $today_num) > $limit['founder']) {
  118. $limit['use'] = !empty($limit['use']) ? (intval($limit['use']) + 1) : 1;
  119. uni_setting_save('statistics', $limit);
  120. }
  121. cache_write($cachekey, $data);
  122. return false;
  123. }
  124. function app_month_visit_till_today($uniacid = 0) {
  125. global $_W;
  126. $result = 0;
  127. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  128. $today = date('Ymd');
  129. $cachekey = cache_system_key("uniacid_visit:{$uniacid}:{$today}");
  130. $cache = cache_load($cachekey);
  131. if (!empty($cache)) {
  132. return $cache;
  133. }
  134. $start = date('Ym01', strtotime(date("Ymd")));
  135. $end = date('Ymd', strtotime('-1 day'));
  136. $params = array('date >=' => $start, 'date <=' => $end, 'uniacid' => $uniacid, 'type' => 'app');
  137. $visit = table('statistics')->visitList($params);
  138. if (!empty($visit)) {
  139. foreach ($visit as $val) {
  140. $result += $val['count'];
  141. }
  142. }
  143. cache_write($cachekey, $result);
  144. return $result;
  145. }
  146. function app_today_visit($uniacid = 0) {
  147. global $_W;
  148. $result = 0;
  149. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  150. $params = array('date' => date('Ymd'), 'uniacid' => $uniacid, 'type' => 'app');
  151. $today = table('statistics')->visitList($params);
  152. if (!empty($today)) {
  153. foreach ($today as $val) {
  154. $result += $val['count'];
  155. }
  156. }
  157. return $result;
  158. }
  159. function app_link_uniaicd_info($module_name) {
  160. global $_W;
  161. $result = 0;
  162. if (empty($module_name)) {
  163. return $result;
  164. }
  165. $module_info = module_fetch($module_name);
  166. if (empty($module_info)) {
  167. return $result;
  168. }
  169. $account_module = table('module')->uniAccountModuleInfo($module_name);
  170. if (!empty($account_module)) {
  171. $settings = (array)$account_module['settings'];
  172. $result = !empty($settings['link_uniacid']) ? intval($settings['link_uniacid']) : 0;
  173. }
  174. return $result;
  175. }