人人商城

front-download.ctrl.php 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. load()->model('miniapp');
  8. load()->classs('cloudapi');
  9. load()->classs('uploadedfile');
  10. $dos = array('front_download', 'domainset', 'code_uuid', 'code_gen', 'code_token', 'qrcode', 'checkscan',
  11. 'commitcode', 'preview', 'getpackage', 'entrychoose', 'set_wxapp_entry',
  12. 'custom', 'custom_save', 'custom_default', 'custom_convert_img', 'upgrade_module');
  13. $do = in_array($do, $dos) ? $do : 'front_download';
  14. $_W['page']['title'] = '小程序下载 - 小程序 - 管理';
  15. $version_id = intval($_GPC['version_id']);
  16. $wxapp_info = miniapp_fetch($_W['uniacid']);
  17. $is_module_wxapp = false;
  18. if (!empty($version_id)) {
  19. $version_info = miniapp_version($version_id);
  20. $is_single_module_wxapp = $version_info['type'] == WXAPP_CREATE_MODULE; }
  21. if ($do == 'entrychoose') {
  22. $entrys = $version_info['cover_entrys'];
  23. template('wxapp/version-front-download');
  24. }
  25. if ($do == 'set_wxapp_entry') {
  26. $entry_id = intval($_GPC['entry_id']);
  27. $result = miniapp_update_entry($version_id, $entry_id);
  28. iajax(0, '设置入口成功');
  29. }
  30. if ($do == 'custom') {
  31. $default_appjson = miniapp_code_current_appjson($version_id);
  32. $default_appjson = json_encode($default_appjson);
  33. template('wxapp/version-front-download');
  34. }
  35. if ($do == 'custom_default') {
  36. $result = miniapp_code_set_default_appjson($version_id);
  37. if ($result === false) {
  38. iajax(1, '操作失败,请重试!');
  39. } else {
  40. iajax(0, '设置成功!', url('wxapp/front-download/front_download', array('version_id' => $version_id)));
  41. }
  42. }
  43. if ($do == 'custom_save') {
  44. if (empty($version_info)) {
  45. iajax(1, '参数错误!');
  46. }
  47. $json = array();
  48. if (!empty($_GPC['json']['window'])) {
  49. $json['window'] = array(
  50. 'navigationBarTitleText' => safe_gpc_string($_GPC['json']['window']['navigationBarTitleText']),
  51. 'navigationBarTextStyle' => safe_gpc_string($_GPC['json']['window']['navigationBarTextStyle']),
  52. 'navigationBarBackgroundColor' => safe_gpc_string($_GPC['json']['window']['navigationBarBackgroundColor']),
  53. 'backgroundColor' => safe_gpc_string($_GPC['json']['window']['backgroundColor']),
  54. );
  55. }
  56. if (!empty($_GPC['json']['tabBar'])) {
  57. $json['tabBar'] = array(
  58. 'color' => safe_gpc_string($_GPC['json']['tabBar']['color']),
  59. 'selectedColor' => safe_gpc_string($_GPC['json']['tabBar']['selectedColor']),
  60. 'backgroundColor' => safe_gpc_string($_GPC['json']['tabBar']['backgroundColor']),
  61. 'borderStyle' => in_array($_GPC['json']['tabBar']['borderStyle'], array('black', 'white')) ? $_GPC['json']['tabBar']['borderStyle'] : '',
  62. );
  63. }
  64. $result = miniapp_code_save_appjson($version_id, $json);
  65. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  66. iajax(0, '设置成功!', url('wxapp/front-download/front_download', array('version_id' => $version_id)));
  67. }
  68. if ($do == 'custom_convert_img') {
  69. $attchid = intval($_GPC['att_id']);
  70. $filename = miniapp_code_path_convert($attchid);
  71. iajax(0, $filename);
  72. }
  73. if ($do == 'domainset') {
  74. $appurl = $_W['siteroot'].'app/index.php';
  75. $uniacid = 0;
  76. if ($version_info) {
  77. $wxapp = pdo_get('account_wxapp', array('uniacid' => $version_info['uniacid']));
  78. if ($wxapp && !empty($wxapp['appdomain'])) {
  79. $appurl = $wxapp['appdomain'];
  80. }
  81. if (!starts_with($appurl, 'https')) { $appurl = str_replace('http', 'https', $appurl);
  82. }
  83. $uniacid = $version_info['uniacid'];
  84. }
  85. if ($_W['ispost']) {
  86. $files = UploadedFile::createFromGlobal();
  87. $appurl = $_GPC['appurl'];
  88. $file = isset($files['file']) ? $files['file'] : null;
  89. if ($file && $file->isOk() && $file->allowExt('txt')) {
  90. $file->moveTo(IA_ROOT.'/'.$file->getClientFilename()); }
  91. if ($version_info) {
  92. itoast('更新成功'); }
  93. }
  94. template('wxapp/version-front-download');
  95. }
  96. if ($do == 'front_download') {
  97. permission_check_account_user('wxapp_front_download_upload');
  98. $appurl = $_W['siteroot'].'/app/index.php';
  99. $uptype = $_GPC['uptype'];
  100. $wxapp_versions_info = miniapp_version($version_id);
  101. if (!in_array($uptype, array('auto', 'normal'))) {
  102. $uptype = 'auto';
  103. }
  104. if (!empty($wxapp_versions_info['last_modules'])) {
  105. $last_modules = current($wxapp_versions_info['last_modules']);
  106. }
  107. $need_upload = false;
  108. $module = array();
  109. if (!empty($wxapp_versions_info['modules'])) {
  110. foreach ($wxapp_versions_info['modules'] as $item) {
  111. $module = $item;
  112. $need_upload = !empty($last_modules) && ($module['version'] != $last_modules['version']);
  113. }
  114. }
  115. $user_version = explode('.', $wxapp_versions_info['version']);
  116. $user_version[count($user_version)-1] += 1;
  117. $user_version = join('.', $user_version);
  118. template('wxapp/version-front-download');
  119. }
  120. if ($do == 'upgrade_module') {
  121. $modules = pdo_getcolumn('wxapp_versions', array('id' => $version_id), 'modules');
  122. $modules = iunserializer($modules);
  123. if (!empty($modules)) {
  124. foreach ($modules as $name => $module) {
  125. $module_info = module_fetch($name);
  126. if (!empty($module_info['version'])) {
  127. $modules[$name]['version'] = $module_info['version'];
  128. }
  129. }
  130. $modules = iserializer($modules);
  131. pdo_update('wxapp_versions', array(
  132. 'modules' => $modules,
  133. 'last_modules' => $modules,
  134. 'version' => $_GPC['version'],
  135. 'description' => trim($_GPC['description']),
  136. ), array('id' => $version_id));
  137. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  138. }
  139. exit;
  140. }
  141. if ($do == 'code_uuid') {
  142. $user_version = $_GPC['user_version'];
  143. $data = miniapp_code_generate($version_id, $user_version);
  144. echo json_encode($data);
  145. }
  146. if ($do == 'code_gen') {
  147. $code_uuid = $_GPC['code_uuid'];
  148. $data = miniapp_check_code_isgen($code_uuid);
  149. echo json_encode($data);
  150. }
  151. if ($do == 'code_token') {
  152. $tokendata = miniapp_code_token();
  153. echo json_encode($tokendata);
  154. }
  155. if ($do == 'qrcode') {
  156. $code_token = $_GPC['code_token'];
  157. header('Content-type: image/jpg'); echo miniapp_code_qrcode($code_token);
  158. exit;
  159. }
  160. if ($do == 'checkscan') {
  161. $code_token = $_GPC['code_token'];
  162. $last = $_GPC['last'];
  163. $data = miniapp_code_check_scan($code_token, $last);
  164. echo json_encode($data);
  165. }
  166. if ($do == 'preview') {
  167. $code_token = $_GPC['code_token'];
  168. $code_uuid = $_GPC['code_uuid'];
  169. $data = miniapp_code_preview_qrcode($code_uuid, $code_token);
  170. echo json_encode($data);
  171. }
  172. if ($do == 'commitcode') {
  173. $user_version = $_GPC['user_version'];
  174. $user_desc = $_GPC['user_desc'];
  175. $code_token = $_GPC['code_token'];
  176. $code_uuid = $_GPC['code_uuid'];
  177. $data = miniapp_code_commit($code_uuid, $code_token, $user_version, $user_desc);
  178. echo json_encode($data);
  179. }
  180. if ($do == 'getpackage') {
  181. if (empty($version_id)) {
  182. itoast('参数错误!', '', '');
  183. }
  184. $siteurl = $_W['siteroot'].'app/index.php';
  185. if (!empty($account_wxapp_info['appdomain'])) {
  186. $siteurl = $account_wxapp_info['appdomain'];
  187. }
  188. $request_cloud_data = array(
  189. 'name' => $account_wxapp_info['name'],
  190. 'modules' => $account_wxapp_info['version']['modules'],
  191. 'siteInfo' => array(
  192. 'name' => $account_wxapp_info['name'],
  193. 'uniacid' => $account_wxapp_info['uniacid'],
  194. 'acid' => $account_wxapp_info['acid'],
  195. 'multiid' => $account_wxapp_info['version']['multiid'],
  196. 'version' => $account_wxapp_info['version']['version'],
  197. 'siteroot' => $siteurl,
  198. 'design_method' => $account_wxapp_info['version']['design_method'],
  199. ),
  200. );
  201. $result = miniapp_getpackage($request_cloud_data);
  202. if (is_error($result)) {
  203. itoast($result['message'], '', '');
  204. } else {
  205. header('content-type: application/zip');
  206. header('content-disposition: attachment; filename="'.$request_cloud_data['name'].'.zip"');
  207. echo $result;
  208. }
  209. exit;
  210. }