人人商城

app.mod.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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'] = 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. $statistics_table = table('statistics');
  66. $params = array(
  67. 'date' => $today,
  68. 'uniacid' => $_W['uniacid'],
  69. 'module' => $module_name,
  70. 'type' => 'app'
  71. );
  72. $today_exist = $statistics_table->visitList($params, 'one');
  73. if (empty($today_exist)) {
  74. $insert_data = array(
  75. 'uniacid' => $_W['uniacid'],
  76. 'module' => $module_name,
  77. 'type' => 'app',
  78. 'date' => $today,
  79. 'count' => 1
  80. );
  81. pdo_insert('stat_visit', $insert_data);
  82. } else {
  83. $data = array('count' => $today_exist['count'] + 1);
  84. pdo_update('stat_visit' , $data, array('id' => $today_exist['id']));
  85. }
  86. return true;
  87. }
  88. function app_pass_visit_limit($uniacid = 0) {
  89. global $_W;
  90. if ($_W['isajax'] || $_W['ispost'] || strpos($_W['siteurl'], 'c=utility&a=visit') !== false) {
  91. return false;
  92. }
  93. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  94. $limit = uni_setting_load('statistics', $uniacid);
  95. $limit = $limit['statistics'];
  96. if (empty($limit)) {
  97. return false;
  98. }
  99. $cachekey = cache_system_key('statistics', array('uniacid' => $uniacid));
  100. $cache = cache_load($cachekey);
  101. if (!empty($cache) && ($cache['time'] + $limit['interval'] > TIMESTAMP)) {
  102. return $cache['limit'];
  103. }
  104. $data = array('time'=> TIMESTAMP, 'limit' => false);
  105. $today_num = app_today_visit($uniacid);
  106. if (!empty($limit['founder'])) {
  107. $order_num = 0;
  108. $orders = table('store')->apiOrderWithUniacid($uniacid);
  109. if (!empty($orders)) {
  110. foreach ($orders as $order) {
  111. $order_num += $order['duration'] * $order['api_num'] * 10000;
  112. }
  113. }
  114. $before_num = app_month_visit_till_today($uniacid);
  115. $sum_num = intval($limit['founder']) + $order_num - intval($limit['use']);
  116. if ($sum_num <= 0) {
  117. $data['limit'] = true;
  118. cache_write($cachekey, $data);
  119. return true;
  120. }
  121. }
  122. if (!empty($limit['owner']) && $today_num > $limit['owner']) {
  123. $data['limit'] = true;
  124. cache_write($cachekey, $data);
  125. return true;
  126. }
  127. if (!empty($limit['founder']) && ($before_num + $today_num) > $limit['founder']) {
  128. $limit['use'] = !empty($limit['use']) ? (intval($limit['use']) + 1) : 1;
  129. uni_setting_save('statistics', $limit);
  130. }
  131. cache_write($cachekey, $data);
  132. return false;
  133. }
  134. function app_month_visit_till_today($uniacid = 0) {
  135. global $_W;
  136. $result = 0;
  137. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  138. $today = date('Ymd');
  139. $cachekey = cache_system_key('uniacid_visit', array('uniacid' => $uniacid, 'today' => $today));
  140. $cache = cache_load($cachekey);
  141. if (!empty($cache)) {
  142. return $cache;
  143. }
  144. $start = date('Ym01', strtotime(date("Ymd")));
  145. $end = date('Ymd', strtotime('-1 day'));
  146. $params = array('date >=' => $start, 'date <=' => $end, 'uniacid' => $uniacid, 'type' => 'app');
  147. $visit = table('statistics')->visitList($params);
  148. if (!empty($visit)) {
  149. foreach ($visit as $val) {
  150. $result += $val['count'];
  151. }
  152. }
  153. cache_write($cachekey, $result);
  154. return $result;
  155. }
  156. function app_today_visit($uniacid = 0) {
  157. global $_W;
  158. $result = 0;
  159. $uniacid = intval($uniacid) > 0 ? intval($uniacid) : $_W['uniacid'];
  160. $params = array('date' => date('Ymd'), 'uniacid' => $uniacid, 'type' => 'app');
  161. $today = table('statistics')->visitList($params);
  162. if (!empty($today)) {
  163. foreach ($today as $val) {
  164. $result += $val['count'];
  165. }
  166. }
  167. return $result;
  168. }
  169. function app_link_uniaicd_info($module_name) {
  170. global $_W;
  171. $result = 0;
  172. if (empty($module_name)) {
  173. return $result;
  174. }
  175. $module_info = module_fetch($module_name);
  176. if (empty($module_info)) {
  177. return $result;
  178. }
  179. if (!empty($module_info['config'])) {
  180. $settings = (array)$module_info['config'];
  181. $result = !empty($settings['link_uniacid']) ? intval($settings['link_uniacid']) : 0;
  182. }
  183. return $result;
  184. }