front-download.ctrl.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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', 'tominiprogram', 'del_tominiprogram');
  13. $do = in_array($do, $dos) ? $do : 'front_download';
  14. $wxapp_info = miniapp_fetch($_W['uniacid']);
  15. $is_module_wxapp = false;
  16. if (!empty($version_id)) {
  17. $is_single_module_wxapp = $version_info['type'] == WXAPP_CREATE_MODULE; }
  18. if ($do == 'entrychoose') {
  19. $entrys = $version_info['cover_entrys'];
  20. template('wxapp/version-front-download');
  21. }
  22. if ($do == 'set_wxapp_entry') {
  23. $entry_id = intval($_GPC['entry_id']);
  24. $result = miniapp_update_entry($version_id, $entry_id);
  25. iajax(0, '设置入口成功');
  26. }
  27. if ($do == 'custom') {
  28. $default_appjson = miniapp_code_current_appjson($version_id);
  29. $default_appjson = json_encode($default_appjson);
  30. template('wxapp/version-front-download');
  31. }
  32. if ($do == 'custom_default') {
  33. $result = miniapp_code_set_default_appjson($version_id);
  34. if ($result === false) {
  35. iajax(1, '操作失败,请重试!');
  36. } else {
  37. iajax(0, '设置成功!', url('wxapp/front-download/front_download', array('version_id' => $version_id)));
  38. }
  39. }
  40. if ($do == 'custom_save') {
  41. if (empty($version_info)) {
  42. iajax(1, '参数错误!');
  43. }
  44. $json = array();
  45. if (!empty($_GPC['json']['window'])) {
  46. $json['window'] = array(
  47. 'navigationBarTitleText' => safe_gpc_string($_GPC['json']['window']['navigationBarTitleText']),
  48. 'navigationBarTextStyle' => safe_gpc_string($_GPC['json']['window']['navigationBarTextStyle']),
  49. 'navigationBarBackgroundColor' => safe_gpc_string($_GPC['json']['window']['navigationBarBackgroundColor']),
  50. 'backgroundColor' => safe_gpc_string($_GPC['json']['window']['backgroundColor']),
  51. );
  52. }
  53. if (!empty($_GPC['json']['tabBar'])) {
  54. $json['tabBar'] = array(
  55. 'color' => safe_gpc_string($_GPC['json']['tabBar']['color']),
  56. 'selectedColor' => safe_gpc_string($_GPC['json']['tabBar']['selectedColor']),
  57. 'backgroundColor' => safe_gpc_string($_GPC['json']['tabBar']['backgroundColor']),
  58. 'borderStyle' => in_array($_GPC['json']['tabBar']['borderStyle'], array('black', 'white')) ? $_GPC['json']['tabBar']['borderStyle'] : '',
  59. );
  60. }
  61. $result = miniapp_code_save_appjson($version_id, $json);
  62. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  63. iajax(0, '设置成功!', url('wxapp/front-download/front_download', array('version_id' => $version_id)));
  64. }
  65. if ($do == 'custom_convert_img') {
  66. $attchid = intval($_GPC['att_id']);
  67. $filename = miniapp_code_path_convert($attchid);
  68. iajax(0, $filename);
  69. }
  70. if ($do == 'front_download') {
  71. permission_check_account_user('wxapp_profile_front_download');
  72. $appurl = $_W['siteroot'].'/app/index.php';
  73. $uptype = $_GPC['uptype'];
  74. $wxapp_versions_info = miniapp_version($version_id);
  75. if (!in_array($uptype, array('auto', 'normal'))) {
  76. $uptype = 'auto';
  77. }
  78. if (!empty($wxapp_versions_info['last_modules'])) {
  79. $last_modules = current($wxapp_versions_info['last_modules']);
  80. }
  81. $need_upload = false;
  82. $module = array();
  83. if (!empty($wxapp_versions_info['modules'])) {
  84. foreach ($wxapp_versions_info['modules'] as $item) {
  85. $module = module_fetch($item['name']);
  86. $need_upload = !empty($last_modules) && ($module['version'] != $last_modules['version']);
  87. }
  88. }
  89. if (!empty($wxapp_versions_info['version'])) {
  90. $user_version = explode('.', $wxapp_versions_info['version']);
  91. $user_version[count($user_version) - 1] += 1;
  92. $user_version = join('.', $user_version);
  93. }
  94. template('wxapp/version-front-download');
  95. }
  96. if ($do == 'upgrade_module') {
  97. $modules = pdo_getcolumn('wxapp_versions', array('id' => $version_id), 'modules');
  98. $modules = iunserializer($modules);
  99. if (!empty($modules)) {
  100. foreach ($modules as $name => $module) {
  101. $module_info = module_fetch($name);
  102. if (!empty($module_info['version'])) {
  103. $modules[$name]['version'] = $module_info['version'];
  104. }
  105. }
  106. $modules = iserializer($modules);
  107. pdo_update('wxapp_versions', array(
  108. 'modules' => $modules,
  109. 'last_modules' => $modules,
  110. 'version' => $_GPC['version'],
  111. 'description' => trim($_GPC['description']),
  112. 'upload_time' => TIMESTAMP,
  113. ), array('id' => $version_id));
  114. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  115. }
  116. exit;
  117. }
  118. if ($do == 'code_uuid') {
  119. $user_version = $_GPC['user_version'];
  120. $data = miniapp_code_generate($version_id, $user_version);
  121. echo json_encode($data);
  122. }
  123. if ($do == 'code_gen') {
  124. $code_uuid = $_GPC['code_uuid'];
  125. $data = miniapp_check_code_isgen($code_uuid);
  126. echo json_encode($data);
  127. }
  128. if ($do == 'code_token') {
  129. $tokendata = miniapp_code_token();
  130. echo json_encode($tokendata);
  131. }
  132. if ($do == 'qrcode') {
  133. $code_token = $_GPC['code_token'];
  134. header('Content-type: image/jpg'); echo miniapp_code_qrcode($code_token);
  135. exit;
  136. }
  137. if ($do == 'checkscan') {
  138. $code_token = $_GPC['code_token'];
  139. $last = $_GPC['last'];
  140. $data = miniapp_code_check_scan($code_token, $last);
  141. echo json_encode($data);
  142. }
  143. if ($do == 'preview') {
  144. $code_token = $_GPC['code_token'];
  145. $code_uuid = $_GPC['code_uuid'];
  146. $data = miniapp_code_preview_qrcode($code_uuid, $code_token);
  147. echo json_encode($data);
  148. }
  149. if ($do == 'commitcode') {
  150. $user_version = $_GPC['user_version'];
  151. $user_desc = $_GPC['user_desc'];
  152. $code_token = $_GPC['code_token'];
  153. $code_uuid = $_GPC['code_uuid'];
  154. $data = miniapp_code_commit($code_uuid, $code_token, $user_version, $user_desc);
  155. echo json_encode($data);
  156. }
  157. if ($do == 'tominiprogram') {
  158. $tomini_lists = iunserializer($version_info['tominiprogram']);
  159. if (!is_array($tomini_lists)) {
  160. $data = array('tominiprogram' => iserializer(array()));
  161. miniapp_version_update($version_id, $data);
  162. }
  163. if (checksubmit()) {
  164. $tominiprogram_data = array();
  165. $appid = safe_gpc_string(trim($_GPC['appid']));
  166. $app_name = safe_gpc_string(trim($_GPC['app_name']));
  167. $tominiprogram_data[$appid] = array('appid' => $appid, 'app_name' => $app_name);
  168. if (empty($appid)) {
  169. itoast('appid不可为空!', referer(), 'error');
  170. }
  171. if (empty($app_name)) {
  172. itoast('app_name不可为空!', referer(), 'error');
  173. }
  174. if (in_array($appid, array_keys($tomini_lists))) {
  175. itoast('该appid值已存在!', referer(), 'error');
  176. }
  177. if (count($tomini_lists) == 10) {
  178. itoast('要跳转的小程序不可超过10个!', referer(), 'error');
  179. }
  180. if (empty($tomini_lists)) {
  181. $data = array('tominiprogram' => iserializer($tominiprogram_data));
  182. } else {
  183. $tomini_lists[$appid] = array('appid' => $appid, 'app_name' => $app_name);
  184. $data = array('tominiprogram' => iserializer($tomini_lists));
  185. }
  186. miniapp_version_update($version_id, $data);
  187. itoast('保存成功!', referer(), 'success');
  188. }
  189. template('wxapp/version-front-download');
  190. }
  191. if ($do == 'del_tominiprogram') {
  192. $tomini_lists = iunserializer($version_info['tominiprogram']);
  193. $appid = safe_gpc_string(trim($_GPC['appid']));
  194. $app_name = safe_gpc_string(trim($_GPC['app_name']));
  195. if (!in_array($appid, array_keys($tomini_lists))) {
  196. itoast('不存在该appid', referer(), 'error');
  197. }
  198. $tomini_lists = array_diff($tomini_lists, array($appid));
  199. unset($tomini_lists[$appid]);
  200. $data = array('tominiprogram' => iserializer($tomini_lists));
  201. miniapp_version_update($version_id, $data);
  202. itoast('删除成功!', referer(), 'success');
  203. }
  204. if ($do == 'getpackage') {
  205. if (empty($version_id)) {
  206. itoast('参数错误!', '', '');
  207. }
  208. $account_wxapp_info = miniapp_fetch($version_info['uniacid'], $version_id);
  209. if (empty($account_wxapp_info)) {
  210. itoast('版本不存在!', referer(), 'error');
  211. }
  212. $siteurl = $_W['siteroot'].'app/index.php';
  213. if (!empty($account_wxapp_info['appdomain'])) {
  214. $siteurl = $account_wxapp_info['appdomain'];
  215. }
  216. $request_cloud_data = array(
  217. 'name' => $account_wxapp_info['name'],
  218. 'modules' => $account_wxapp_info['version']['modules'],
  219. 'support' => $_W['account']['type_sign'], 'siteInfo' => array(
  220. 'name' => $account_wxapp_info['name'],
  221. 'uniacid' => $account_wxapp_info['uniacid'],
  222. 'acid' => $account_wxapp_info['acid'],
  223. 'multiid' => $account_wxapp_info['version']['multiid'],
  224. 'version' => $account_wxapp_info['version']['version'],
  225. 'siteroot' => $siteurl,
  226. 'design_method' => $account_wxapp_info['version']['design_method'],
  227. ),
  228. );
  229. $result = miniapp_getpackage($request_cloud_data);
  230. if (is_error($result)) {
  231. itoast($result['message'], '', '');
  232. } else {
  233. header('content-type: application/zip');
  234. header('content-disposition: attachment; filename="'.$request_cloud_data['name'].'.zip"');
  235. echo $result;
  236. }
  237. exit;
  238. }