人人商城

phoneapp.mod.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. defined('IN_IA') or exit('Access Denied');
  3. function phoneapp_support_modules() {
  4. global $_W;
  5. load()->model('user');
  6. $modules = user_modules($_W['uid']);
  7. $phoneapp_modules = array();
  8. if (!empty($modules)) {
  9. foreach ($modules as $module) {
  10. if ($module['phoneapp_support'] == MODULE_SUPPORT_PHONEAPP) {
  11. $phoneapp_modules[$module['name']] = $module;
  12. }
  13. }
  14. }
  15. return $phoneapp_modules;
  16. }
  17. function phoneapp_get_some_lastversions($uniacid) {
  18. $version_lasts = array();
  19. $uniacid = intval($uniacid);
  20. if (empty($uniacid)) {
  21. return $version_lasts;
  22. }
  23. $version_lasts = table('phoneappversions')->phoneappLatestVersion($uniacid);
  24. $last_switch_version = phoneapp_last_switch_version();
  25. if (!empty($last_switch_version[$uniacid]) && !empty($version_lasts[$last_switch_version[$uniacid]['version_id']])) {
  26. $version_lasts[$last_switch_version[$uniacid]['version_id']]['current'] = true;
  27. } else {
  28. reset($version_lasts);
  29. $firstkey = key($version_lasts);
  30. $version_lasts[$firstkey]['current'] = true;
  31. }
  32. return $version_lasts;
  33. }
  34. function phoneapp_last_switch_version() {
  35. global $_GPC;
  36. static $phoneapp_cookie_uniacids;
  37. if (empty($phoneapp_cookie_uniacids) && !empty($_GPC['__phoneappversionids'])) {
  38. $phoneapp_cookie_uniacids = json_decode(htmlspecialchars_decode($_GPC['__phoneappversionids']), true);
  39. }
  40. return $phoneapp_cookie_uniacids;
  41. }
  42. function phoneapp_fetch($uniacid, $version_id = '') {
  43. global $_GPC;
  44. load()->model('extension');
  45. $phoneapp_info = array();
  46. $uniacid = intval($uniacid);
  47. if (empty($uniacid)) {
  48. return $phoneapp_info;
  49. }
  50. if (!empty($version_id)) {
  51. $version_id = intval($version_id);
  52. }
  53. $phonaeapp_table = table('phoneapp');
  54. $phoneapp_info = $phonaeapp_table->searchWithUniacid($uniacid)->phoneappAccountInfo();
  55. if (empty($phoneapp_info)) {
  56. return $phoneapp_info;
  57. }
  58. if (empty($version_id)) {
  59. $phoneapp_cookie_uniacids = array();
  60. if (!empty($_GPC['__phoneappversionids'])) {
  61. $phoneappversionids = json_decode(htmlspecialchars_decode($_GPC['__phoneappversionids']), true);
  62. foreach ($phoneappversionids as $version_val) {
  63. $phoneapp_cookie_uniacids[] = $version_val['uniacid'];
  64. }
  65. }
  66. if (in_array($uniacid, $phoneapp_cookie_uniacids)) {
  67. $phoneapp_version_info = phoneapp_version($phoneappversionids[$uniacid]['version_id']);
  68. }
  69. if (empty($phoneapp_version_info)) {
  70. $phoneapp_version_info = table('phoneappversions')->phoneappLastVersion($uniacid);
  71. }
  72. } else {
  73. $phoneapp_version_info = table('phoneappversions')->getById($version_id);
  74. }
  75. if (!empty($phoneapp_version_info) && !empty($phoneapp_version_info['modules'])) {
  76. $phoneapp_version_info['modules'] = iunserializer($phoneapp_version_info['modules']);
  77. }
  78. $phoneapp_info['version'] = $phoneapp_version_info;
  79. $phoneapp_info['version_num'] = explode('.', $phoneapp_version_info['version']);
  80. return $phoneapp_info;
  81. }
  82. function phoneapp_version($version_id) {
  83. $version_info = array();
  84. $version_id = intval($version_id);
  85. if (empty($version_id)) {
  86. return $version_info;
  87. }
  88. $version_info = table('phoneappversions')->getById($version_id);
  89. $version_info['modules'] = iunserializer($version_info['modules']);
  90. return $version_info;
  91. }
  92. function phoneapp_update_last_use_version($uniacid, $version_id) {
  93. global $_GPC;
  94. $uniacid = intval($uniacid);
  95. $version_id = intval($version_id);
  96. if (empty($uniacid) || empty($version_id)) {
  97. return false;
  98. }
  99. if (!empty($_GPC['__phoneappversionids'])) {
  100. $phoneapp_uniacids = array();
  101. $cookie_val = json_decode(htmlspecialchars_decode($_GPC['__phoneappversionids']), true);
  102. if (!empty($cookie_val)) {
  103. foreach ($cookie_val as &$version) {
  104. $phoneapp_uniacids[] = $version['uniacid'];
  105. if ($version['uniacid'] == $uniacid) {
  106. $version['version_id'] = $version_id;
  107. $phoneapp_uniacids = array();
  108. break;
  109. }
  110. }
  111. unset($version);
  112. }
  113. if (!empty($phoneapp_uniacids) && !in_array($uniacid, $phoneapp_uniacids)) {
  114. $cookie_val[$uniacid] = array('uniacid' => $uniacid, 'version_id' => $version_id);
  115. }
  116. } else {
  117. $cookie_val = array(
  118. $uniacid => array('uniacid' => $uniacid, 'version_id' => $version_id),
  119. );
  120. }
  121. isetcookie('__uniacid', $uniacid, 7 * 86400);
  122. isetcookie('__phoneappversionids', json_encode($cookie_val), 7 * 86400);
  123. return true;
  124. }
  125. function phoneapp_getpackage($data, $if_single = false) {
  126. load()->classs('cloudapi');
  127. $api = new CloudApi();
  128. $response = $api->post('phoneapp', 'download', $data, 'binary');
  129. if ($response['code'] == 200) {
  130. return error(0, $response['content']);
  131. }
  132. return error(1, $response['content']);
  133. }
  134. function phoneapp_version_all($uniacid) {
  135. load()->model('module');
  136. $phoneapp_versions = array();
  137. $uniacid = intval($uniacid);
  138. if (empty($uniacid)) {
  139. return $phoneapp_versions;
  140. }
  141. $phoneapp_versions = table('phoneappversions')->phoneappAllVersion($uniacid);
  142. if (!empty($phoneapp_versions)) {
  143. foreach ($phoneapp_versions as &$version) {
  144. $version = phoneapp_version($version['id']);
  145. }
  146. }
  147. return $phoneapp_versions;
  148. }