app.mod.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. $site_nav_table = table('site_nav');
  19. $site_nav_table->searchWithMultiid(intval($multiid));
  20. $site_nav_table->searchWithPosition($pos[$type]);
  21. $site_nav_table->searchWithStatus(1);
  22. $site_nav_table->searchWithUniacid($_W['uniacid']);
  23. $site_nav_table->orderby(array('displayorder' => 'DESC', 'id' => 'ASC'));
  24. $navs = $site_nav_table->getall();
  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'] = iunserializer($row['css']);
  32. }
  33. if (empty($row['css'])) {
  34. $row['css'] = array(
  35. 'icon' => array(
  36. 'icon' => 'fa fa-external-link',
  37. 'font-size' => '35px',
  38. 'color' => '',
  39. ),
  40. 'name' => array('color' => ''),
  41. );
  42. }
  43. if (empty($row['css']['icon']['icon'])) {
  44. $row['css']['icon']['icon'] = 'fa fa-external-link';
  45. }
  46. if ($row['position'] == '3') {
  47. if (!empty($row['css'])) {
  48. unset($row['css']['icon']['font-size']);
  49. }
  50. }
  51. $row['css']['icon']['style'] = "color:{$row['css']['icon']['color']};font-size:{$row['css']['icon']['font-size']}px;";
  52. $row['css']['name'] = "color:{$row['css']['name']['color']};";
  53. }
  54. unset($row);
  55. }
  56. return $navs;
  57. }
  58. function app_update_today_visit($module_name) {
  59. global $_W;
  60. $module_name = trim($module_name);
  61. if (empty($module_name) || !in_array($_W['account']['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH, ACCOUNT_TYPE_WEBAPP_NORMAL))) {
  62. return false;
  63. }
  64. $today = date('Ymd');
  65. $stat_visit_teble = table('stat_visit');
  66. $stat_visit_teble->searchWithDate($today);
  67. $stat_visit_teble->searchWithModule($module_name);
  68. $stat_visit_teble->searchWithType('app');
  69. $stat_visit_teble->searchWithUnacid($_W['uniacid']);
  70. $today_exist = $stat_visit_teble->get();
  71. if (empty($today_exist)) {
  72. $insert_data = array(
  73. 'uniacid' => $_W['uniacid'],
  74. 'module' => $module_name,
  75. 'type' => 'app',
  76. 'date' => $today,
  77. 'count' => 1,
  78. 'ip_count' => 0
  79. );
  80. pdo_insert('stat_visit', $insert_data);
  81. $today_exist = $insert_data;
  82. $today_exist['id'] = pdo_insertid();
  83. } else {
  84. $data = array('count' => $today_exist['count'] + 1);
  85. pdo_update('stat_visit' , $data, array('id' => $today_exist['id']));
  86. }
  87. $yestoday = date('Ymd', strtotime('-1 day'));
  88. $cache_key = cache_system_key('delete_visit_ip', array('date' => $yestoday));
  89. $is_delete_visit_ip = cache_load($cache_key);
  90. if (empty($is_delete_visit_ip)) {
  91. pdo_delete('stat_visit_ip', $yestoday);
  92. cache_write($cache_key, true);
  93. }
  94. if (!empty($today_exist['id'])) {
  95. $ip = ip2long(getip());
  96. $stat_ip_visit_table = table('stat_visit_ip');
  97. $stat_ip_visit_table->searchWithIp($ip);
  98. $stat_ip_visit_table->searchWithDate($today);
  99. $ip_today_exist = $stat_ip_visit_table->get();
  100. if (empty($ip_today_exist)) {
  101. $ip_insert_data = array(
  102. 'ip' => $ip,
  103. 'uniacid' => $_W['uniacid'],
  104. 'module' => $module_name,
  105. 'type' => 'app',
  106. 'date' => $today,
  107. );
  108. pdo_insert('stat_visit_ip', $ip_insert_data);
  109. pdo_update('stat_visit', array('ip_count' => $today_exist['ip_count'] + 1), array('id' => $today_exist['id']));
  110. }
  111. }
  112. return true;
  113. }
  114. function app_pass_visit_limit($uniacid = 0) {
  115. global $_W;
  116. if (strpos($_W['siteurl'], 'api.php?') === false && ($_W['isajax'] || $_W['ispost'] || strpos($_W['siteurl'], 'c=utility&a=visit') !== false)) {
  117. return false;
  118. }
  119. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  120. $limit = uni_setting_load('statistics', $uniacid);
  121. $limit = $limit['statistics'];
  122. if (empty($limit)) {
  123. return false;
  124. }
  125. $cachekey = cache_system_key('statistics', array('uniacid' => $uniacid));
  126. $cache = cache_load($cachekey);
  127. if (!empty($cache) && ($cache['time'] + $limit['interval'] > TIMESTAMP)) {
  128. return $cache['limit'];
  129. }
  130. $data = array('time'=> TIMESTAMP, 'limit' => false);
  131. $today_num = app_today_visit($uniacid);
  132. if (!empty($limit['founder'])) {
  133. $order_num = 0;
  134. $orders = table('store')->apiOrderWithUniacid($uniacid);
  135. if (!empty($orders)) {
  136. foreach ($orders as $order) {
  137. $order_num += $order['duration'] * $order['api_num'] * 10000;
  138. }
  139. }
  140. $before_num = app_month_visit_till_today($uniacid);
  141. if ($limit['founder'] + $order_num <= $before_num + $today_num) {
  142. $data['limit'] = true;
  143. cache_write($cachekey, $data);
  144. return true;
  145. }
  146. }
  147. if (!empty($limit['owner']) && $today_num > $limit['owner']) {
  148. $data['limit'] = true;
  149. cache_write($cachekey, $data);
  150. return true;
  151. }
  152. if (!empty($limit['founder']) && ($before_num + $today_num) > $limit['founder']) {
  153. $limit['use'] = !empty($limit['use']) ? (intval($limit['use']) + 1) : 1;
  154. uni_setting_save('statistics', $limit);
  155. }
  156. cache_write($cachekey, $data);
  157. return false;
  158. }
  159. function app_month_visit_till_today($uniacid = 0) {
  160. global $_W;
  161. $result = 0;
  162. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  163. $today = date('Ymd');
  164. $cachekey = cache_system_key('uniacid_visit', array('uniacid' => $uniacid, 'today' => $today));
  165. $cache = cache_load($cachekey);
  166. if (!empty($cache)) {
  167. return $cache;
  168. }
  169. $start = date('Ym01', strtotime(date("Ymd")));
  170. $end = date('Ymd', strtotime('-1 day'));
  171. $stat_visit_teble = table('stat_visit');
  172. $stat_visit_teble->searchWithGreaterThenDate($start);
  173. $stat_visit_teble->searchWithLessThenDate($end);
  174. $stat_visit_teble->searchWithType('app');
  175. $stat_visit_teble->searchWithUnacid($uniacid);
  176. $visit = $stat_visit_teble->getall();
  177. if (!empty($visit)) {
  178. foreach ($visit as $val) {
  179. $result += $val['count'];
  180. }
  181. }
  182. cache_write($cachekey, $result);
  183. return $result;
  184. }
  185. function app_today_visit($uniacid = 0) {
  186. global $_W;
  187. $result = 0;
  188. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  189. $stat_visit_teble = table('stat_visit');
  190. $stat_visit_teble->searchWithDate(date('Ymd'));
  191. $stat_visit_teble->searchWithType('app');
  192. $stat_visit_teble->searchWithUnacid($uniacid);
  193. $today = $stat_visit_teble->getall();
  194. if (!empty($today)) {
  195. foreach ($today as $val) {
  196. $result += $val['count'];
  197. }
  198. }
  199. return $result;
  200. }