人人商城

post.ctrl.php 7.0KB

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. load()->model('permission');
  8. load()->model('module');
  9. load()->func('communication');
  10. load()->classs('wxapp.platform');
  11. $dos = array('design_method', 'post', 'get_wxapp_modules', 'module_binding');
  12. $do = in_array($do, $dos) ? $do : 'post';
  13. $_W['page']['title'] = '小程序 - 新建版本';
  14. $account_info = permission_user_account_num($_W['uid']);
  15. if ($do == 'design_method') {
  16. $choose = isset($_GPC['choose_type']) ? intval($_GPC['choose_type']) : 0;
  17. $uniacid = intval($_GPC['uniacid']);
  18. if ($choose) {
  19. template('wxapp/design-method');
  20. } else {
  21. if (!permission_user_account_creatable($_W['uid'], WXAPP_TYPE_SIGN)) {
  22. $authurl = "javascript:alert('创建小程序已达上限!');";
  23. }
  24. if (empty($authurl) && !empty($_W['setting']['platform']['authstate'])) {
  25. $account_platform = new WxappPlatform();
  26. $authurl = $account_platform->getAuthLoginUrl();
  27. }
  28. template('wxapp/choose-type');
  29. }
  30. }
  31. if ($do == 'post') {
  32. $uniacid = intval($_GPC['uniacid']);
  33. $design_method = intval($_GPC['design_method']);
  34. $create_type = intval($_GPC['create_type']);
  35. if (empty($unicid) && !permission_user_account_creatable($_W['uid'], WXAPP_TYPE_SIGN)) {
  36. itoast('创建的小程序已达上限!', '', '');
  37. }
  38. $version_id = intval($_GPC['version_id']);
  39. $isedit = $version_id > 0 ? 1 : 0;
  40. if ($isedit) {
  41. $wxapp_version = miniapp_version($version_id);
  42. }
  43. if (empty($design_method)) {
  44. itoast('请先选择要添加小程序类型', referer(), 'error');
  45. }
  46. if ($design_method == WXAPP_TEMPLATE) {
  47. itoast('拼命开发中。。。', referer(), 'info');
  48. }
  49. if (checksubmit('submit')) {
  50. if ($design_method == WXAPP_TEMPLATE && empty($_GPC['choose']['modules'])) {
  51. iajax(2, '请选择要打包的模块应用', url('wxapp/post'));
  52. }
  53. if (!preg_match('/^[0-9]{1,2}\.[0-9]{1,2}(\.[0-9]{1,2})?$/', trim($_GPC['version']))) {
  54. iajax('-1', '版本号错误,只能是数字、点,数字最多2位,例如 1.1.1 或1.2');
  55. }
  56. if (empty($uniacid)) {
  57. if (empty($_GPC['name'])) {
  58. iajax(1, '请填写小程序名称', url('wxapp/post'));
  59. }
  60. $account_wxapp_data = array(
  61. 'name' => trim($_GPC['name']),
  62. 'description' => trim($_GPC['description']),
  63. 'original' => trim($_GPC['original']),
  64. 'level' => 1,
  65. 'key' => trim($_GPC['appid']),
  66. 'secret' => trim($_GPC['appsecret']),
  67. 'type' => ACCOUNT_TYPE_APP_NORMAL,
  68. 'headimg' => file_is_image( $_GPC['headimg']) ? $_GPC['headimg'] : '',
  69. 'qrcode' => file_is_image( $_GPC['qrcode']) ? $_GPC['qrcode'] : '',
  70. );
  71. $uniacid = miniapp_create($account_wxapp_data, ACCOUNT_TYPE_APP_NORMAL);
  72. $unisettings['creditnames'] = array('credit1' => array('title' => '积分', 'enabled' => 1), 'credit2' => array('title' => '余额', 'enabled' => 1));
  73. $unisettings['creditnames'] = iserializer($unisettings['creditnames']);
  74. $unisettings['uniacid'] = $uniacid;
  75. $res = uni_setting_save('uni_settings', $unisettings);
  76. if (is_error($uniacid)) {
  77. iajax(3, '添加小程序信息失败', url('wxapp/post'));
  78. }
  79. } else {
  80. $wxapp_info = miniapp_fetch($uniacid);
  81. if (empty($wxapp_info)) {
  82. iajax(4, '小程序不存在或是已经被删除', url('wxapp/post'));
  83. }
  84. }
  85. $wxapp_version = array(
  86. 'uniacid' => $uniacid,
  87. 'multiid' => '0',
  88. 'description' => trim($_GPC['description']),
  89. 'version' => trim($_GPC['version']),
  90. 'modules' => '',
  91. 'design_method' => $design_method,
  92. 'quickmenu' => '',
  93. 'createtime' => TIMESTAMP,
  94. 'template' => $design_method == WXAPP_TEMPLATE ? intval($_GPC['choose']['template']) : 0,
  95. 'type' => 0
  96. );
  97. if (!in_array($create_type, array(WXAPP_CREATE_DEFAULT, WXAPP_CREATE_MODULE, WXAPP_CREATE_MUTI_MODULE))) {
  98. $create_type = WXAPP_CREATE_DEFAULT;
  99. }
  100. $wxapp_version['type'] = $create_type;
  101. if ($design_method == WXAPP_TEMPLATE) {
  102. $multi_data = array(
  103. 'uniacid' => $uniacid,
  104. 'title' => $account_wxapp_data['name'],
  105. 'styleid' => 0,
  106. );
  107. pdo_insert('site_multi', $multi_data);
  108. $wxapp_version['multiid'] = pdo_insertid();
  109. }
  110. if (!empty($_GPC['choose']['modules'])) {
  111. $select_modules = array();
  112. foreach ($_GPC['choose']['modules'] as $post_module) {
  113. $module = module_fetch($post_module['module']);
  114. if (empty($module)) {
  115. continue;
  116. }
  117. $select_modules[$module['name']] = array('name' => $module['name'],
  118. 'newicon' => $post_module['newicon'],
  119. 'version' => $module['version'], 'defaultentry'=>$post_module['defaultentry']);
  120. }
  121. $wxapp_version['modules'] = serialize($select_modules);
  122. }
  123. if (!empty($_GPC['quickmenu'])) {
  124. $quickmenu = array(
  125. 'color' => $_GPC['quickmenu']['bottom']['color'],
  126. 'selected_color' => $_GPC['quickmenu']['bottom']['selectedColor'],
  127. 'boundary' => $_GPC['quickmenu']['bottom']['boundary'],
  128. 'bgcolor' => $_GPC['quickmenu']['bottom']['bgcolor'],
  129. 'show' => $_GPC['quickmenu']['show'] == 'true' ? 1 : 0,
  130. 'menus' => array(),
  131. );
  132. if (!empty($_GPC['quickmenu']['menus'])) {
  133. foreach ($_GPC['quickmenu']['menus'] as $row) {
  134. $quickmenu['menus'][] = array(
  135. 'name' => $row['name'],
  136. 'icon' => $row['defaultImage'],
  137. 'selectedicon' => $row['selectedImage'],
  138. 'url' => $row['module']['url'],
  139. 'defaultentry' => $row['defaultentry']['eid'],
  140. );
  141. }
  142. }
  143. $wxapp_version['quickmenu'] = serialize($quickmenu);
  144. }
  145. if ($isedit) {
  146. $msg = '小程序修改成功';
  147. pdo_update('wxapp_versions', $wxapp_version, array('id'=>$version_id, 'uniacid'=>$uniacid));
  148. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  149. } else {
  150. $msg = '小程序创建成功';
  151. pdo_insert('wxapp_versions', $wxapp_version);
  152. }
  153. iajax(0, $msg, url('account/display/switch', array('uniacid' => $uniacid, 'type' => ACCOUNT_TYPE_APP_NORMAL)));
  154. }
  155. if (!empty($uniacid)) {
  156. $wxapp_info = miniapp_fetch($uniacid);
  157. }
  158. template('wxapp/post');
  159. }
  160. if ($do == 'get_wxapp_modules') {
  161. $wxapp_modules = miniapp_support_wxapp_modules();
  162. foreach ($wxapp_modules as $name => $module) {
  163. if ($module['issystem']) {
  164. $path = '/framework/builtin/'.$module['name'];
  165. } else {
  166. $path = '../addons/'.$module['name'];
  167. }
  168. $icon = $path.'/icon-custom.jpg';
  169. if (!file_exists($cion)) {
  170. $icon = $path.'/icon.jpg';
  171. if (!file_exists($icon)) {
  172. $icon = './resource/images/nopic-small.jpg';
  173. }
  174. }
  175. $module['logo'] = $icon;
  176. }
  177. iajax(0, $wxapp_modules, '');
  178. }
  179. if ($do == 'module_binding') {
  180. $modules = $_GPC['modules'];
  181. if (empty($modules)) {
  182. iajax(1, '参数无效');
  183. return;
  184. }
  185. $modules = explode(',', $modules);
  186. $modules = array_map(function($item) {
  187. return trim($item);
  188. }, $modules);
  189. $modules = table('modules')->with(array('bindings' => function($query){
  190. return $query->where('entry', 'cover');
  191. }))->where('name', $modules)->getall();
  192. $modules = array_filter($modules, function($module){
  193. return count($module['bindings']) > 0;
  194. });
  195. iajax(0, $modules);
  196. }